Class TemplateEngine

java.lang.Object
org.apache.commons.jexl3.JxltEngine
org.apache.commons.jexl3.internal.TemplateEngine

public final class TemplateEngine extends JxltEngine
A JxltEngine implementation.
Since:
3.0
  • Field Details

    • cache

      The TemplateExpression cache.
    • jexl

      final Engine jexl
      The JEXL engine instance.
    • logger

      final org.apache.commons.logging.Log logger
      The logger.
    • immediateChar

      final char immediateChar
      The first character for immediate expressions.
    • deferredChar

      final char deferredChar
      The first character for deferred expressions.
    • noscript

      final boolean noscript
      Whether expressions can use JEXL script or only expressions (ie, no for, var, etc).
  • Constructor Details

    • TemplateEngine

      public TemplateEngine(Engine aJexl, boolean noScript, int cacheSize, char immediate, char deferred)
      Creates a new instance of JxltEngine creating a local cache.
      Parameters:
      aJexl - the JexlEngine to use.
      noScript - whether this engine only allows JEXL expressions or scripts
      cacheSize - the number of expressions in this cache, default is 256
      immediate - the immediate template expression character, default is '$'
      deferred - the deferred template expression character, default is '#'
  • Method Details

    • getImmediateChar

      char getImmediateChar()
      Returns:
      the immediate character
    • getDeferredChar

      char getDeferredChar()
      Returns:
      the deferred character
    • getEngine

      public Engine getEngine()
      Gets the JexlEngine underlying this JxltEngine.
      Specified by:
      getEngine in class JxltEngine
      Returns:
      the JexlEngine
    • clearCache

      public void clearCache()
      Clears the cache.
      Specified by:
      clearCache in class JxltEngine
    • createExpression

      public JxltEngine.Expression createExpression(JexlInfo jexlInfo, String expression)
      Description copied from class: JxltEngine
      Creates a JxltEngine.Expression from an expression string. Uses and fills up the expression cache if any.

      If the underlying JEXL engine is silent, errors will be logged through its logger as warnings.

      Specified by:
      createExpression in class JxltEngine
      Parameters:
      jexlInfo - the JexlInfo source information
      expression - the JxltEngine.Template string expression
      Returns:
      the JxltEngine.Expression, null if silent and an error occurred
    • createException

      static JxltEngine.Exception createException(JexlInfo info, String action, TemplateEngine.TemplateExpression expr, Exception xany)
      Creates a JxltEngine.Exception from a JexlException.
      Parameters:
      info - the source info
      action - createExpression, prepare, evaluate
      expr - the template expression
      xany - the exception
      Returns:
      an exception containing an explicit error message
    • append

      private static int append(StringBuilder strb, CharSequence expr, int position, char c)
      Helper for expression dealing with embedded strings.
      Parameters:
      strb - the expression buffer to copy characters into
      expr - the source
      position - the offset into the source
      c - the separator character
      Returns:
      the new position to read the source from
    • parseExpression

      TemplateEngine.TemplateExpression parseExpression(JexlInfo info, String expr, Scope scope)
      Parses a unified expression.
      Parameters:
      info - the source info
      expr - the string expression
      scope - the template scope
      Returns:
      the unified expression instance
      Throws:
      JexlException - if an error occur during parsing
    • startsWith

      protected int startsWith(CharSequence sequence, CharSequence pattern)
      Whether a sequence starts with a given set of characters (following spaces).

      Space characters at beginning of line before the pattern are discarded.

      Parameters:
      sequence - the sequence
      pattern - the pattern to match at start of sequence
      Returns:
      the first position after end of pattern if it matches, -1 otherwise
    • readLines

      protected static Iterator<CharSequence> readLines(Reader reader)
      Read lines from a (buffered / mark-able) reader keeping all new-lines and line-feeds.
      Parameters:
      reader - the reader
      Returns:
      the line iterator
    • readTemplate

      protected List<TemplateEngine.Block> readTemplate(String prefix, Reader source)
      Reads lines of a template grouping them by typed blocks.
      Parameters:
      prefix - the directive prefix
      source - the source reader
      Returns:
      the list of blocks
    • createTemplate

      public TemplateScript createTemplate(JexlInfo info, String prefix, Reader source, String... parms)
      Description copied from class: JxltEngine
      Creates a new template.
      Specified by:
      createTemplate in class JxltEngine
      Parameters:
      info - the jexl info (file, line, column)
      prefix - the directive prefix
      source - the source
      parms - the parameter names
      Returns:
      the template