1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package 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 | */
|
---|
11 | public 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 | }
|
---|