Class TemplateEngine
java.lang.Object
org.apache.commons.jexl3.JxltEngine
org.apache.commons.jexl3.internal.TemplateEngine
A JxltEngine implementation.
- Since:
- 3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
Abstract the source fragments, verbatim or immediate typed text blocks.(package private) static enum
The enum capturing the difference between verbatim and code source fragments.(package private) class
A composite unified expression: "...(package private) class
A constant unified expression.(package private) class
A deferred unified expression: #{jexl}.(package private) static final class
A helper class to build expressions.(package private) static enum
Types of expressions.(package private) class
An immediate unified expression: ${jexl}.(package private) class
The base for JEXL based unified expressions.(package private) class
An immediate unified expression nested into a deferred unified expression.private static enum
The different parsing states.(package private) class
The abstract base class for all unified expressions, immediate '${...}' and deferred '#{...}'.Nested classes/interfaces inherited from class org.apache.commons.jexl3.JxltEngine
JxltEngine.Exception, JxltEngine.Expression, JxltEngine.Template
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final SoftCache<String,
TemplateEngine.TemplateExpression> The TemplateExpression cache.(package private) final char
The first character for deferred expressions.(package private) final char
The first character for immediate expressions.(package private) final Engine
The JEXL engine instance.(package private) final org.apache.commons.logging.Log
The logger.(package private) final boolean
Whether expressions can use JEXL script or only expressions (ie, no for, var, etc). -
Constructor Summary
ConstructorsConstructorDescriptionTemplateEngine
(Engine aJexl, boolean noScript, int cacheSize, char immediate, char deferred) Creates a new instance ofJxltEngine
creating a local cache. -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
append
(StringBuilder strb, CharSequence expr, int position, char c) Helper for expression dealing with embedded strings.void
Clears the cache.(package private) static JxltEngine.Exception
createException
(JexlInfo info, String action, TemplateEngine.TemplateExpression expr, Exception xany) Creates a JxltEngine.Exception from a JexlException.createExpression
(JexlInfo jexlInfo, String expression) Creates aJxltEngine.Expression
from an expression string.createTemplate
(JexlInfo info, String prefix, Reader source, String... parms) Creates a new template.(package private) char
Gets the JexlEngine underlying this JxltEngine.(package private) char
(package private) TemplateEngine.TemplateExpression
parseExpression
(JexlInfo info, String expr, Scope scope) Parses a unified expression.protected static Iterator<CharSequence>
Read lines from a (buffered / mark-able) reader keeping all new-lines and line-feeds.protected List<TemplateEngine.Block>
readTemplate
(String prefix, Reader source) Reads lines of a template grouping them by typed blocks.protected int
startsWith
(CharSequence sequence, CharSequence pattern) Whether a sequence starts with a given set of characters (following spaces).Methods inherited from class org.apache.commons.jexl3.JxltEngine
createExpression, createTemplate, createTemplate, createTemplate, createTemplate, createTemplate
-
Field Details
-
cache
The TemplateExpression cache. -
jexl
The JEXL engine instance. -
logger
final org.apache.commons.logging.Log loggerThe logger. -
immediateChar
final char immediateCharThe first character for immediate expressions. -
deferredChar
final char deferredCharThe first character for deferred expressions. -
noscript
final boolean noscriptWhether expressions can use JEXL script or only expressions (ie, no for, var, etc).
-
-
Constructor Details
-
TemplateEngine
Creates a new instance ofJxltEngine
creating a local cache.- Parameters:
aJexl
- the JexlEngine to use.noScript
- whether this engine only allows JEXL expressions or scriptscacheSize
- the number of expressions in this cache, default is 256immediate
- 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
Gets the JexlEngine underlying this JxltEngine.- Specified by:
getEngine
in classJxltEngine
- Returns:
- the JexlEngine
-
clearCache
public void clearCache()Clears the cache.- Specified by:
clearCache
in classJxltEngine
-
createExpression
Description copied from class:JxltEngine
Creates aJxltEngine.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 classJxltEngine
- Parameters:
jexlInfo
- theJexlInfo
source informationexpression
- theJxltEngine.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 infoaction
- createExpression, prepare, evaluateexpr
- the template expressionxany
- the exception- Returns:
- an exception containing an explicit error message
-
append
Helper for expression dealing with embedded strings.- Parameters:
strb
- the expression buffer to copy characters intoexpr
- the sourceposition
- the offset into the sourcec
- the separator character- Returns:
- the new position to read the source from
-
parseExpression
Parses a unified expression.- Parameters:
info
- the source infoexpr
- the string expressionscope
- the template scope- Returns:
- the unified expression instance
- Throws:
JexlException
- if an error occur during parsing
-
startsWith
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 sequencepattern
- the pattern to match at start of sequence- Returns:
- the first position after end of pattern if it matches, -1 otherwise
-
readLines
Read lines from a (buffered / mark-able) reader keeping all new-lines and line-feeds.- Parameters:
reader
- the reader- Returns:
- the line iterator
-
readTemplate
Reads lines of a template grouping them by typed blocks.- Parameters:
prefix
- the directive prefixsource
- the source reader- Returns:
- the list of blocks
-
createTemplate
Description copied from class:JxltEngine
Creates a new template.- Specified by:
createTemplate
in classJxltEngine
- Parameters:
info
- the jexl info (file, line, column)prefix
- the directive prefixsource
- the sourceparms
- the parameter names- Returns:
- the template
-