source: josm/trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateEntry.java

Last change on this file was 17610, checked in by simon04, 3 years ago

see #18949 - Tagging presets: value_template="..." for <text>

Use value_template to generate the value automatically based on other <text> values of this preset. For instance, "Bus {ref}: {from} → {to}" can be used to generate the name of a bus route relation.

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools.template_engine;
3
4/**
5 * Interface for one node in the abstract syntax tree that is the result of parsing a template
6 * string with {@link TemplateParser}.
7 *
8 * The node can either be branching (condition, context switch) or a leaf node (variable, static text).
9 * The root node, representing the entire template is also a {@code TemplateEntry}.
10 */
11public interface TemplateEntry {
12
13 /**
14 * Execute this template by generating text for a given data provider.
15 * @param dataProvider the data provider from which information should be compiled to a string
16 * @return the generated text
17 */
18 default String getText(TemplateEngineDataProvider dataProvider) {
19 StringBuilder sb = new StringBuilder();
20 appendText(sb, dataProvider);
21 return sb.toString();
22 }
23
24 /**
25 * Execute this template by generating text for a given data provider.
26 * @param result the {@link StringBuilder} to append the text to
27 * @param dataProvider the data provider from which information should be compiled to a string
28 */
29 void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider);
30
31 /**
32 * Check if this template is applicable to the given data provider.
33 *
34 * @param dataProvider the data provider to check
35 * @return true if all conditions are fulfilled to apply the template (for instance all
36 * required key=value mappings are present), false otherwise
37 */
38 boolean isValid(TemplateEngineDataProvider dataProvider);
39}
Note: See TracBrowser for help on using the repository browser.