Class TemplateScript

    • Constructor Detail

      • TemplateScript

        public TemplateScript​(TemplateEngine engine,
                              JexlInfo jexlInfo,
                              java.lang.String directive,
                              java.io.Reader reader,
                              java.lang.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; can not be "$", "${", "#" or "#{" since this would preclude being able to differentiate directives and jxlt expressions
        reader - the input reader
        parms - the parameter names
        Throws:
        java.lang.NullPointerException - if either the directive prefix or input is null
        java.lang.IllegalArgumentException - if the directive prefix is invalid
      • TemplateScript

        TemplateScript​(TemplateEngine engine,
                       java.lang.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 Detail

      • collectPrintScope

        private static void collectPrintScope​(JexlNode node,
                                              java.util.Map<java.lang.Integer,​JexlNode.Info> minfo)
        Collects the scope surrounding a call to jexl:print(i).

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

        Parameters:
        node - the visited node
        minfo - the map of printed expression number to node info
      • scopeOf

        private static Scope scopeOf​(JexlNode.Info info)
        Gets the scope from an info.
        Parameters:
        info - the node info
        Returns:
        the scope
      • asString

        public java.lang.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,
                             java.io.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,
                             java.io.Writer writer,
                             java.lang.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
      • getParameters

        public java.lang.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 java.util.Map<java.lang.String,​java.lang.Object> getPragmas()
        Description copied from interface: JxltEngine.Template
        Gets this script pragmas.
        Specified by:
        getPragmas in interface JxltEngine.Template
        Returns:
        the (non null, may be empty) pragmas map
      • getVariables

        public java.util.Set<java.util.List<java.lang.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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object