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 classAbstract the source fragments, verbatim or immediate typed text blocks.(package private) static enumThe enum capturing the difference between verbatim and code source fragments.(package private) final classA composite unified expression: "...(package private) final classA constant unified expression.(package private) final classA deferred unified expression: #{jexl}.(package private) static final classA helper class to build expressions.(package private) static enumTypes of expressions.(package private) final classAn immediate unified expression: ${jexl}.(package private) classThe base for JEXL based unified expressions.(package private) final classAn immediate unified expression nested into a deferred unified expression.private static enumThe different parsing states.(package private) classThe 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 JexlCache<String, TemplateEngine.TemplateExpression> The TemplateExpression cache.(package private) final charThe first character for deferred expressions.(package private) final charThe first character for immediate expressions.(package private) final EngineThe JEXL engine instance.(package private) final org.apache.commons.logging.LogThe logger.(package private) final booleanWhether expressions can use JEXL script or only expressions (ie, no for, var, etc). -
Constructor Summary
ConstructorsConstructorDescriptionTemplateEngine(Engine jexl, boolean noScript, int cacheSize, char immediate, char deferred) Creates a new instance ofJxltEnginecreating a local cache. -
Method Summary
Modifier and TypeMethodDescriptionprivate static intappend(StringBuilder strb, CharSequence expr, int position, char c) Helper for expression dealing with embedded strings.voidClears the cache.(package private) static JxltEngine.ExceptioncreateException(JexlInfo info, String action, TemplateEngine.TemplateExpression expr, Exception xany) Creates a JxltEngine.Exception from a JexlException.createExpression(JexlInfo jexlInfo, String expression) Creates aJxltEngine.Expressionfrom an expression string.createTemplate(JexlInfo info, String prefix, Reader source, String... parms) Creates a new template.(package private) charGets the JexlEngine underlying this JxltEngine.(package private) char(package private) TemplateEngine.TemplateExpressionparseExpression(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 intstartsWith(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 ofJxltEnginecreating a local cache.- Parameters:
jexl- 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
-
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
-
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
-
readLines
Read lines from a (buffered / mark-able) reader keeping all new-lines and line-feeds.- Parameters:
reader- the reader- Returns:
- the line iterator
-
clearCache
public void clearCache()Clears the cache.- Specified by:
clearCachein classJxltEngine
-
createExpression
Description copied from class:JxltEngineCreates aJxltEngine.Expressionfrom 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:
createExpressionin classJxltEngine- Parameters:
jexlInfo- theJexlInfosource informationexpression- theJxltEngine.Templatestring expression- Returns:
- the
JxltEngine.Expression, null if silent and an error occurred
-
createTemplate
Description copied from class:JxltEngineCreates a new template.- Specified by:
createTemplatein classJxltEngine- Parameters:
info- the jexl info (file, line, column)prefix- the directive prefixsource- the sourceparms- the parameter names- Returns:
- the template
-
getDeferredChar
char getDeferredChar()- Returns:
- the deferred character
-
getEngine
Gets the JexlEngine underlying this JxltEngine.- Specified by:
getEnginein classJxltEngine- Returns:
- the JexlEngine
-
getImmediateChar
char getImmediateChar()- Returns:
- the immediate character
-
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
-
readTemplate
Reads lines of a template grouping them by typed blocks.- Parameters:
prefix- the directive prefixsource- the source reader- Returns:
- the list of blocks
-
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
-