Class TemplateScript
java.lang.Object
org.apache.commons.jexl3.internal.TemplateScript
- All Implemented Interfaces:
JxltEngine.Template
A Template instance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TemplateEngine.TemplateExpression[]The TemplateEngine expressions called by the script.private final TemplateEngineThe engine.private final StringThe prefix marker.private final ASTJexlScriptThe resulting script.private final TemplateEngine.Block[]The array of source blocks. -
Constructor Summary
ConstructorsConstructorDescriptionTemplateScript(TemplateEngine engine, String thePrefix, TemplateEngine.Block[] theSource, ASTJexlScript theScript, TemplateEngine.TemplateExpression[] theExprs) Private ctor used to expand deferred expressions during prepare.TemplateScript(TemplateEngine engine, JexlInfo jexlInfo, String directive, Reader reader, String... parms) Creates a new template from an character input. -
Method Summary
Modifier and TypeMethodDescriptionasString()Recreate the template source from its inner components.private static voidcollectPrintScope(JexlNode node, Map<Integer, JexlNode.Info> minfo) Collects the scope surrounding a call to jexl:print(i).voidevaluate(JexlContext context, Writer writer) Evaluates this template.voidevaluate(JexlContext context, Writer writer, Object... args) Evaluates this template.(package private) TemplateEngine.TemplateExpression[]String[]Gets the list of parameters expected by this template.Gets this script pragmas.(package private) ASTJexlScriptGets the list of variables accessed by this template.prepare(JexlContext context) Prepares this template by expanding any contained deferred TemplateExpression.private static ScopescopeOf(JexlNode.Info info) Gets the scope from an info.toString()
-
Field Details
-
prefix
The prefix marker. -
source
The array of source blocks. -
script
The resulting script. -
exprs
The TemplateEngine expressions called by the script. -
jxlt
The engine.
-
-
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 enginejexlInfo- the source infodirective- the prefix for lines of code; can not be "$", "${", "#" or "#{" since this would preclude being able to differentiate directives and jxlt expressionsreader- the input readerparms- the parameter names- Throws:
NullPointerException- if either the directive prefix or input is nullIllegalArgumentException- 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 enginethePrefix- the directive prefixtheSource- the sourcetheScript- the scripttheExprs- the expressions
-
-
Method Details
-
collectPrintScope
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 nodeminfo- the map of printed expression number to node info
-
scopeOf
Gets the scope from an info.- Parameters:
info- the node info- Returns:
- the scope
-
asString
Description copied from interface:JxltEngine.TemplateRecreate the template source from its inner components.- Specified by:
asStringin interfaceJxltEngine.Template- Returns:
- the template source rewritten
-
evaluate
Description copied from interface:JxltEngine.TemplateEvaluates this template.- Specified by:
evaluatein interfaceJxltEngine.Template- Parameters:
context- the context to use during evaluationwriter- the writer to use for output
-
evaluate
Description copied from interface:JxltEngine.TemplateEvaluates this template.- Specified by:
evaluatein interfaceJxltEngine.Template- Parameters:
context- the context to use during evaluationwriter- the writer to use for outputargs- the arguments
-
getExpressions
TemplateEngine.TemplateExpression[] getExpressions()- Returns:
- exprs
-
getParameters
Description copied from interface:JxltEngine.TemplateGets the list of parameters expected by this template.- Specified by:
getParametersin interfaceJxltEngine.Template- Returns:
- the parameter names array
-
getPragmas
Description copied from interface:JxltEngine.TemplateGets this script pragmas.- Specified by:
getPragmasin interfaceJxltEngine.Template- Returns:
- the (non null, may be empty) pragmas map
-
getScript
ASTJexlScript getScript()- Returns:
- script
-
getVariables
Description copied from interface:JxltEngine.TemplateGets 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:
getVariablesin interfaceJxltEngine.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
Description copied from interface:JxltEngine.TemplatePrepares this template by expanding any contained deferred TemplateExpression.- Specified by:
preparein interfaceJxltEngine.Template- Parameters:
context- the context to prepare against- Returns:
- the prepared version of the template
-
toString
-