Class UnifiedJEXL.TemplateContext

  • All Implemented Interfaces:
    JexlContext, NamespaceResolver
    Enclosing class:
    UnifiedJEXL

    public final class UnifiedJEXL.TemplateContext
    extends java.lang.Object
    implements JexlContext, NamespaceResolver
    The type of context to use during evaluation of templates.

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

    public for introspection purpose.

    Since:
    2.1
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object get​(java.lang.String name)
      Gets the value of a variable.
      JexlEngine.Frame getFrame()
      Gets this context calling frame.
      boolean has​(java.lang.String name)
      Checks whether a variable is defined in this context.
      void include​(UnifiedJEXL.Template template, java.lang.Object... args)
      Includes a call to another template.
      void print​(int e)
      Prints an expression result.
      protected void printComposite​(org.apache.commons.jexl2.UnifiedJEXL.CompositeExpression composite)
      Prints a composite expression.
      java.lang.Object resolveNamespace​(java.lang.String ns)
      Resolves a namespace by its name.
      void set​(java.lang.String name, java.lang.Object value)
      Sets the value of a variable.
      • Methods inherited from class java.lang.Object

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

      • TemplateContext

        protected TemplateContext​(JexlContext jcontext,
                                  JexlEngine.Frame jframe,
                                  UnifiedJEXL.Expression[] expressions,
                                  java.io.Writer out)
        Creates a template context instance.
        Parameters:
        jcontext - the base context
        jframe - the calling frame
        expressions - the list of expression from the template to evaluate
        out - the output writer
    • Method Detail

      • getFrame

        public JexlEngine.Frame getFrame()
        Gets this context calling frame.
        Returns:
        the engine frame
      • get

        public java.lang.Object get​(java.lang.String name)
        Gets the value of a variable.
        Specified by:
        get in interface JexlContext
        Parameters:
        name - the variable's name
        Returns:
        the value
      • set

        public void set​(java.lang.String name,
                        java.lang.Object value)
        Sets the value of a variable.
        Specified by:
        set in interface JexlContext
        Parameters:
        name - the variable's name
        value - the variable's value
      • has

        public boolean has​(java.lang.String name)
        Checks whether a variable is defined in this context.

        A variable may be defined with a null value; this method checks whether the value is null or if the variable is undefined.

        Specified by:
        has in interface JexlContext
        Parameters:
        name - the variable's name
        Returns:
        true if it exists, false otherwise
      • resolveNamespace

        public java.lang.Object resolveNamespace​(java.lang.String ns)
        Resolves a namespace by its name.
        Specified by:
        resolveNamespace in interface NamespaceResolver
        Parameters:
        ns - the name
        Returns:
        the namespace object
      • include

        public void include​(UnifiedJEXL.Template template,
                            java.lang.Object... args)
        Includes a call to another template.

        Evaluates a template using this template initial context and writer.

        Parameters:
        template - the template to evaluate
        args - the arguments
      • print

        public void print​(int e)
        Prints an expression result.
        Parameters:
        e - the expression number
      • printComposite

        protected void printComposite​(org.apache.commons.jexl2.UnifiedJEXL.CompositeExpression composite)
        Prints a composite expression.
        Parameters:
        composite - the composite expression