source: josm/trunk/src/org/openstreetmap/josm/tools/template_engine/SearchExpressionCondition.java@ 13568

Last change on this file since 13568 was 13003, checked in by bastiK, 7 years ago

see #14794 - add missing top level javadoc; minor refactoring for Condition

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools.template_engine;
3
4import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
5
6/**
7 * Conditional {@link TemplateEntry} that executes another template in case a search expression applies
8 * to the given data provider.
9 */
10public class SearchExpressionCondition implements TemplateEntry {
11
12 private final Match condition;
13 private final TemplateEntry text;
14
15 /**
16 * Creates a new {@link SearchExpressionCondition}.
17 * @param condition the match condition that is checked before applying the child template
18 * @param text the child template to execute in case the condition is fulfilled
19 */
20 public SearchExpressionCondition(Match condition, TemplateEntry text) {
21 this.condition = condition;
22 this.text = text;
23 }
24
25 @Override
26 public void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider) {
27 text.appendText(result, dataProvider);
28 }
29
30 @Override
31 public boolean isValid(TemplateEngineDataProvider dataProvider) {
32 return dataProvider.evaluateCondition(condition);
33 }
34
35 @Override
36 public String toString() {
37 return condition + " '" + text + '\'';
38 }
39}
Note: See TracBrowser for help on using the repository browser.