Class Template


  • public class Template
    extends java.lang.Object
    Representation of a parsed template
    • Constructor Summary

      Constructors 
      Constructor Description
      Template​(java.lang.String name)  
      Template​(java.lang.String name, Template parent)
      Allocates a new, undefined template associated with the given one and with the same delimiters.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFuncs​(FuncMap funcs)  
      void addParseTree​(java.lang.String name, Tree tree)
      Adds parse tree for template with given name and associates it with template.
      void execute​(java.io.OutputStream os, java.lang.Object data)
      Applies a parsed template to the specified data object, and writes the output to OutputStream.
      void executeTemplate​(java.io.OutputStream os, java.lang.String name, java.lang.Object data)
      Applies the template associated with this template that has the given name to the specified data object and writes the output to OutputStream
      Template getTemplate​(java.lang.String name)  
      Template[] getTemplates()  
      void parse​(java.io.InputStream input)  
      void parse​(java.lang.String text)
      Named template definition ({define ...}) in text define additional templates associated with template and are removed from the definition of template itself.
      static Template parse​(FuncMap funcs, java.io.File... files)
      Create templates from the file list
      static Template parse​(FuncMap funcs, java.util.Map<java.lang.String,​java.lang.String> inputs)
      Create templates from the map, that represent pair (Name, InputStream)
      Template parseTo​(FuncMap funcs, java.io.File... files)
      Create templates from the file list and append to this template
      Template parseTo​(FuncMap funcs, java.util.Map<java.lang.String,​java.lang.String> text)
      Create templates from the map, that represent pair (Name, Text) and append to this template
      void setDelims​(java.lang.String left, java.lang.String right)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Template

        public Template​(java.lang.String name)
      • Template

        public Template​(java.lang.String name,
                        Template parent)
        Allocates a new, undefined template associated with the given one and with the same delimiters. The association allows one template to invoke another with a {template} action
        Parameters:
        name - template name
        parent - parent
    • Method Detail

      • parse

        public static Template parse​(FuncMap funcs,
                                     java.io.File... files)
                              throws ParseException,
                                     java.io.IOException
        Create templates from the file list
        Parameters:
        funcs - functions
        files - template files
        Returns:
        template
        Throws:
        ParseException - in case of a parse error
        java.io.IOException - in case of an I/O error
      • parse

        public static Template parse​(FuncMap funcs,
                                     java.util.Map<java.lang.String,​java.lang.String> inputs)
                              throws ParseException
        Create templates from the map, that represent pair (Name, InputStream)
        Parameters:
        funcs - functions
        inputs - list of InputStream
        Returns:
        template
        Throws:
        ParseException - in case of a parse error
      • parse

        public void parse​(java.lang.String text)
                   throws InternalException,
                          ParseException
        Named template definition ({define ...}) in text define additional templates associated with template and are removed from the definition of template itself. Templates can be redefined in successive calls to parse. A template definition with a body containing only white space and comments is considered empty and will not replace an existing template's body.
        Parameters:
        text - template text
        Throws:
        InternalException - in case of an internal error
        ParseException - in case of a parse error
      • parseTo

        public Template parseTo​(FuncMap funcs,
                                java.io.File... files)
                         throws ParseException,
                                java.io.IOException
        Create templates from the file list and append to this template
        Parameters:
        funcs - functions
        files - template files
        Returns:
        template
        Throws:
        ParseException - in case of a parse error
        java.io.IOException - in case of an I/O error
      • parseTo

        public Template parseTo​(FuncMap funcs,
                                java.util.Map<java.lang.String,​java.lang.String> text)
                         throws ParseException
        Create templates from the map, that represent pair (Name, Text) and append to this template
        Parameters:
        funcs - functions
        text - pair (Name, Text)
        Returns:
        template
        Throws:
        ParseException - in case of a parse error
      • execute

        public void execute​(java.io.OutputStream os,
                            java.lang.Object data)
                     throws ExecException
        Applies a parsed template to the specified data object, and writes the output to OutputStream. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer
        Parameters:
        os - OutputStream object
        data - data
        Throws:
        ExecException - in case of an execute error
      • executeTemplate

        public void executeTemplate​(java.io.OutputStream os,
                                    java.lang.String name,
                                    java.lang.Object data)
                             throws ExecException
        Applies the template associated with this template that has the given name to the specified data object and writes the output to OutputStream
        Parameters:
        os - OutputStream object
        name - template name
        data - data
        Throws:
        ExecException - in case of an execute error
      • addFuncs

        public void addFuncs​(FuncMap funcs)
      • setDelims

        public void setDelims​(java.lang.String left,
                              java.lang.String right)
      • getTemplates

        public Template[] getTemplates()
      • getTemplate

        public Template getTemplate​(java.lang.String name)
      • addParseTree

        public void addParseTree​(java.lang.String name,
                                 Tree tree)
                          throws InternalException,
                                 ParseException
        Adds parse tree for template with given name and associates it with template. If the template does not already exist, it will create a new one. If the template does exist, it will be replaced
        Parameters:
        name - template name
        tree - parse tree
        Throws:
        InternalException - in case of an internal error
        ParseException - in case of an execute error