Class Template


  • public class Template
    extends Object
    A template expressed in EscapeVelocity, a subset of the Velocity Template Language (VTL) from Apache. The intent of this implementation is that if a template is accepted and successfully produces output, that output will be identical to what Velocity would have produced for the same template and input variables.
    Author:
    emcmanus@google.com (Éamonn McManus)
    • Method Detail

      • parseFrom

        public static Template parseFrom​(Reader reader)
                                  throws IOException
        Parses a VTL template from the given Reader. The given Reader will be closed on return from this method.
        Throws:
        IOException
      • parseFrom

        public static Template parseFrom​(String resourceName,
                                         Template.ResourceOpener resourceOpener)
                                  throws IOException
        Parse a VTL template of the given name using the given ResourceOpener.
        Parameters:
        resourceName - name of the resource. May be null.
        resourceOpener - used to open included files for #parse directives in the template.
        Throws:
        IOException
      • evaluate

        public String evaluate​(Map<String,​?> vars)
        Evaluate the given template with the given initial set of variables.
        Parameters:
        vars - a map where the keys are variable names and the values are the corresponding variable values. For example, if "x" maps to 23, then $x in the template will expand to 23.
        Returns:
        the string result of evaluating the template.