Class Template

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class Template
    extends Resource
    implements java.lang.Cloneable
    This class is used for controlling all template operations. This class uses a parser created by JavaCC to create an AST that is subsequently traversed by a Visitor.
     // set up and initialize Velocity before this code block
    
     Template template = Velocity.getTemplate("test.wm");
     Context context = new VelocityContext();
    
     context.put("foo", "bar");
     context.put("customer", new Customer());
    
     template.merge(context, writer);
     
    Version:
    $Id$
    Author:
    Jason van Zyl, Geir Magnusson Jr.
    • Constructor Detail

      • Template

        public Template()
        Default constructor
    • Method Detail

      • getMacros

        public java.util.Map<java.lang.String,​java.lang.Object> getMacros()
        get the map of all macros defined by this template
        Returns:
        macros map
      • initDocument

        public void initDocument()
                          throws TemplateInitException
        initializes the document. init() is not longer dependant upon context, but we need to let the init() carry the template name down through for VM namespace features
        Throws:
        TemplateInitException - When a problem occurs during the document initialization.
      • merge

        public void merge​(Context context,
                          java.io.Writer writer,
                          java.util.List<java.lang.String> macroLibraries)
                   throws ResourceNotFoundException,
                          ParseErrorException,
                          MethodInvocationException
        The AST node structure is merged with the context to produce the final output.
        Parameters:
        context - Context with data elements accessed by template
        writer - output writer for rendered template
        macroLibraries - a list of template files containing macros to be used when merging
        Throws:
        ResourceNotFoundException - if template not found from any available source.
        ParseErrorException - if template cannot be parsed due to syntax (or other) error.
        MethodInvocationException - When a method on a referenced object in the context could not invoked.
        Since:
        1.6
      • deepCloneData

        protected void deepCloneData()
                              throws java.lang.CloneNotSupportedException
        Description copied from class: Resource
        Deep cloning of resource data
        Overrides:
        deepCloneData in class Resource
        Throws:
        java.lang.CloneNotSupportedException