Class Template

java.lang.Object
ru.proninyaroslav.template.Template

public class Template extends Object
Representation of a parsed template
  • Constructor Details

    • Template

      public Template(String name)
    • Template

      public Template(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 Details

    • parse

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

      public static Template parse(FuncMap funcs, Map<String,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(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
    • parse

      public void parse(InputStream input) throws InternalException, ParseException, IOException
      Throws:
      InternalException
      ParseException
      IOException
    • parseTo

      public Template parseTo(FuncMap funcs, File... files) throws ParseException, 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
      IOException - in case of an I/O error
    • parseTo

      public Template parseTo(FuncMap funcs, Map<String,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(OutputStream os, 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(OutputStream os, String name, 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(String left, String right)
    • getTemplates

      public Template[] getTemplates()
    • getTemplate

      public Template getTemplate(String name)
    • addParseTree

      public void addParseTree(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