| Modifier and Type | Class and Description |
|---|---|
| public static interface | Template.ResourceOpener
Used to resolve references to resources in the template, through |
| Modifier and Type | Field and Description |
|---|---|
| private final ImmutableMap | macros
Macros that are defined in this template (this exact VTL file). |
| private final MethodFinder | methodFinder
Caches |
| private final Node |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the string result of evaluating the template.a map where the keys are variable names and the values are the corresponding
variable values. For example, if vars)"x" maps to 23, then $x in the template
will expand to 23.Evaluate the given template with the given initial set of variables. |
| pack-priv ImmutableMap | |
| public static Template | Returns: an object representing the parsed template.a Reader that will supply the text of the template. It will be closed on return
from this method. The Reader will be buffered internally by this method (via reader)BufferedReader), so the passed-in Reader doesn't need to perform
its own buffering.Parses a VTL template from the given |
| public static Template | Returns: an object representing the parsed template.name of the resource. May be null. resourceName, Template.used to open the initial resource and resources referenced by
resourceOpener#parse directives in the template.Parses a VTL template of the given name using the given |
| pack-priv static Template | |
| pack-priv void |
| macros | back to summary |
|---|---|
| private final ImmutableMap<String, Macro> macros Macros that are defined in this template (this exact VTL file). If the template includes
| |
| methodFinder | back to summary |
|---|---|
| private final MethodFinder methodFinder Caches | |
| root | back to summary |
|---|---|
| private final Node root | |
| Template | back to summary |
|---|---|
| pack-priv Template(Node root, ImmutableMap<String, Macro> macros) | |
| evaluate | back to summary |
|---|---|
| public String evaluate(Map<String, ?> vars) Evaluate the given template with the given initial set of variables.
| |
| getMacros | back to summary |
|---|---|
| pack-priv ImmutableMap | |
| parseFrom | back to summary |
|---|---|
| public static Template parseFrom(Reader reader) throws IOException Parses a VTL template from the given
| |
| parseFrom | back to summary |
|---|---|
| public static Template parseFrom(String resourceName, Template. Parses a VTL template of the given name using the given
| |
| parseFrom | back to summary |
|---|---|
| pack-priv static Template parseFrom(String resourceName, Template. | |
| render | back to summary |
|---|---|
| pack-priv void render(EvaluationContext context, StringBuilder output) | |
#parse directives.
Here is an example that opens nested templates as resources relative to the calling class:
ResourceOpener resourceOpener = resourceName -> {
InputStream inputStream = getClass().getResource(resourceName);
if (inputStream == null) {
throw new IOException("Unknown resource: " + resourceName);
}
return new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
};
Template template = Template.parseFrom("foo.vm", resourceOpener);
| Modifier and Type | Method and Description |
|---|---|
| public Reader | Returns: aReader for the resource.the name of the resource to be read. This can be null if resourceName)Template.parseFrom is called with a null resourceName.Returns a |
| openResource | back to summary |
|---|---|
| public Reader openResource(String resourceName) throws IOException Returns a
| |