Class TemplateScript

java.lang.Object
org.apache.commons.jexl3.internal.TemplateScript
All Implemented Interfaces:
JxltEngine.Template

public final class TemplateScript extends Object implements JxltEngine.Template
A Template instance.
  • Field Details

  • Constructor Details

    • TemplateScript

      public TemplateScript(TemplateEngine engine, JexlInfo jexlInfo, String directive, Reader reader, String... parms)
      Creates a new template from an character input.
      Parameters:
      engine - The template engine
      jexlInfo - The source info
      directive - The prefix for lines of code; cannot be "$", "${", "#" or "#{" since this would preclude being able to differentiate directives and jxlt expressions
      reader - The input reader
      parms - The parameter names
      Throws:
      NullPointerException - if either the directive prefix or input is null
      IllegalArgumentException - if the directive prefix is invalid
    • TemplateScript

      TemplateScript(TemplateEngine engine, String thePrefix, TemplateEngine.Block[] theSource, ASTJexlScript theScript, TemplateEngine.TemplateExpression[] theExprs)
      Private ctor used to expand deferred expressions during prepare.
      Parameters:
      engine - The template engine
      thePrefix - The directive prefix
      theSource - The source
      theScript - The script
      theExprs - The expressions
  • Method Details

    • collectPrintScope

      private static void collectPrintScope(JexlNode node, JexlNode.Info[] callSites)
      Collects the call-site surrounding a call to jexl:print(i).

      This allows parsing the blocks with the known symbols in the frame visible to the parser.

      Parameters:
      node - The visited node
      callSites - The map of printed expression number to node info
    • scopeOf

      private static Scope scopeOf(JexlNode.Info info, Scope scope)
      Gets the scope from a node info.
      Parameters:
      info - The node info
      scope - The outer scope
      Returns:
      The scope
    • calleeScripts

      private TemplateEngine.TemplateExpression[] calleeScripts(Scope scope, TemplateEngine.Block[] blocks, JexlNode.Info[] callSites)
      Creates the expression array from the list of blocks.
      Parameters:
      scope - The outer scope
      blocks - The list of blocks
      Returns:
      The array of expressions
    • callerScript

      private static String callerScript(TemplateEngine.Block[] blocks)
      Creates the script calling the list of blocks.

      This is used to create a script from a list of blocks that were parsed from a template.

      Parameters:
      blocks - The list of blocks
      Returns:
      The script source
    • asString

      public String asString()
      Description copied from interface: JxltEngine.Template
      Recreate the template source from its inner components.
      Specified by:
      asString in interface JxltEngine.Template
      Returns:
      The template source rewritten
    • evaluate

      public void evaluate(JexlContext context, Writer writer)
      Description copied from interface: JxltEngine.Template
      Evaluates this template.
      Specified by:
      evaluate in interface JxltEngine.Template
      Parameters:
      context - The context to use during evaluation
      writer - The writer to use for output
    • evaluate

      public void evaluate(JexlContext context, Writer writer, Object... args)
      Description copied from interface: JxltEngine.Template
      Evaluates this template.
      Specified by:
      evaluate in interface JxltEngine.Template
      Parameters:
      context - The context to use during evaluation
      writer - The writer to use for output
      args - The arguments
    • getExpressions

      Returns:
      exprs
    • getParameters

      public String[] getParameters()
      Description copied from interface: JxltEngine.Template
      Gets the list of parameters expected by this template.
      Specified by:
      getParameters in interface JxltEngine.Template
      Returns:
      The parameter names array
    • getPragmas

      public Map<String,Object> getPragmas()
      Description copied from interface: JxltEngine.Template
      Gets this script pragmas.
      Specified by:
      getPragmas in interface JxltEngine.Template
      Returns:
      The (non-null, possibly empty) pragmas map
    • getScript

      ASTJexlScript getScript()
      Returns:
      script
    • getVariables

      public Set<List<String>> getVariables()
      Description copied from interface: JxltEngine.Template
      Gets the list of variables accessed by this template.

      This method will visit all nodes of the sub-expressions and extract all variables whether they are written in 'dot' or 'bracketed' notation. (a.b is equivalent to a['b']).

      Specified by:
      getVariables in interface JxltEngine.Template
      Returns:
      The set of variables, each as a list of strings (ant-ish variables use more than 1 string) or the empty set if no variables are used
    • prepare

      public TemplateScript prepare(JexlContext context)
      Description copied from interface: JxltEngine.Template
      Prepares this template by expanding any contained deferred TemplateExpression.
      Specified by:
      prepare in interface JxltEngine.Template
      Parameters:
      context - The context to prepare against
      Returns:
      The prepared version of the template
    • prepare

      public TemplateScript prepare(JexlContext context, Object... args)
      Description copied from interface: JxltEngine.Template
      Prepares this template by expanding any contained deferred TemplateExpression with optional arguments.

      This binds arguments to template parameters for immediate expressions when the template also uses deferred/nested expressions.

      Specified by:
      prepare in interface JxltEngine.Template
      Parameters:
      context - The context to prepare against
      args - The arguments to bind (optional)
      Returns:
      The prepared version of the template
    • toString

      public String toString()
      Overrides:
      toString in class Object