Class TemplateInterpreter


public class TemplateInterpreter extends Interpreter
The type of interpreter to use during evaluation of templates.

This context exposes its writer as '$jexl' to the scripts.

public for introspection purpose.

  • Field Details

  • Constructor Details

    • TemplateInterpreter

      protected TemplateInterpreter(TemplateInterpreter.Arguments args)
      Creates a template interpreter instance.
      Parameters:
      args - the template interpreter arguments
  • Method Details

    • doPrint

      private void doPrint(JexlInfo info, Object arg)
      Prints to output.

      This will dynamically try to find the best suitable method in the writer through uberspection. Subclassing Writer by adding 'print' methods should be the preferred way to specialize output.

      Parameters:
      info - the source info
      arg - the argument to print out
    • include

      public void include(JxltEngine.Template script, Object... args)
      Includes a call to another template.

      Includes another template using this template initial context and writer.

      Parameters:
      script - the TemplateScript to evaluate
      args - the arguments
    • print

      public void print(int e)
      Prints a unified expression evaluation result.
      Parameters:
      e - the expression number
    • printComposite

      private void printComposite(TemplateEngine.CompositeExpression composite)
      Prints a composite expression.
      Parameters:
      composite - the composite expression
    • resolveNamespace

      protected Object resolveNamespace(String prefix, JexlNode node)
      Description copied from class: InterpreterBase
      Resolves a namespace, eventually allocating an instance using context as constructor argument.

      The lifetime of such instances span the current expression or script evaluation.

      Overrides:
      resolveNamespace in class InterpreterBase
      Parameters:
      prefix - the prefix name (can be null for global namespace)
      node - the AST node
      Returns:
      the namespace instance
    • visit

      protected Object visit(ASTFunctionNode node, Object data)
      Interprets a function node. print() and include() must be decoded by this interpreter since delegating to the Uberspect may be sandboxing the interpreter itself making it unable to call the function.
      Overrides:
      visit in class Interpreter
      Parameters:
      node - the function node
      data - the data
      Returns:
      the function evaluation result.
    • visit

      protected Object visit(ASTIdentifier node, Object data)
      Overrides:
      visit in class Interpreter
    • visit

      protected Object visit(ASTJexlScript script, Object data)
      Overrides:
      visit in class Interpreter