Class TemplateEngine
- java.lang.Object
-
- org.apache.commons.jexl3.JxltEngine
-
- org.apache.commons.jexl3.internal.TemplateEngine
-
public final class TemplateEngine extends JxltEngine
A JxltEngine implementation.- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
TemplateEngine.Block
Abstract the source fragments, verbatim or immediate typed text blocks.(package private) static class
TemplateEngine.BlockType
The enum capturing the difference between verbatim and code source fragments.(package private) class
TemplateEngine.CompositeExpression
A composite unified expression: "...(package private) class
TemplateEngine.ConstantExpression
A constant unified expression.(package private) class
TemplateEngine.DeferredExpression
A deferred unified expression: #{jexl}.(package private) static class
TemplateEngine.ExpressionBuilder
A helper class to build expressions.(package private) static class
TemplateEngine.ExpressionType
Types of expressions.(package private) class
TemplateEngine.ImmediateExpression
An immediate unified expression: ${jexl}.(package private) class
TemplateEngine.JexlBasedExpression
The base for JEXL based unified expressions.(package private) class
TemplateEngine.NestedExpression
An immediate unified expression nested into a deferred unified expression.private static class
TemplateEngine.ParseState
The different parsing states.(package private) class
TemplateEngine.TemplateExpression
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
Fields Modifier and Type Field Description (package private) JexlCache<java.lang.String,TemplateEngine.TemplateExpression>
cache
The TemplateExpression cache.(package private) char
deferredChar
The first character for deferred expressions.(package private) char
immediateChar
The first character for immediate expressions.(package private) Engine
jexl
The JEXL engine instance.(package private) org.apache.commons.logging.Log
logger
The logger.(package private) boolean
noscript
Whether expressions can use JEXL script or only expressions (ie, no for, var, etc).
-
Constructor Summary
Constructors Constructor Description TemplateEngine(Engine jexl, boolean noScript, int cacheSize, char immediate, char deferred)
Creates a new instance ofJxltEngine
creating a local cache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
append(java.lang.StringBuilder strb, java.lang.CharSequence expr, int position, char c)
Helper for expression dealing with embedded strings.void
clearCache()
Clears the cache.(package private) static JxltEngine.Exception
createException(JexlInfo info, java.lang.String action, TemplateEngine.TemplateExpression expr, java.lang.Exception xany)
Creates a JxltEngine.Exception from a JexlException.JxltEngine.Expression
createExpression(JexlInfo jexlInfo, java.lang.String expression)
Creates aJxltEngine.Expression
from an expression string.TemplateScript
createTemplate(JexlInfo info, java.lang.String prefix, java.io.Reader source, java.lang.String... parms)
Creates a new template.(package private) char
getDeferredChar()
Engine
getEngine()
Gets the JexlEngine underlying this JxltEngine.(package private) char
getImmediateChar()
(package private) TemplateEngine.TemplateExpression
parseExpression(JexlInfo info, java.lang.String expr, Scope scope)
Parses a unified expression.protected static java.util.Iterator<java.lang.CharSequence>
readLines(java.io.Reader reader)
Read lines from a (buffered / mark-able) reader keeping all new-lines and line-feeds.protected java.util.List<TemplateEngine.Block>
readTemplate(java.lang.String prefix, java.io.Reader source)
Reads lines of a template grouping them by typed blocks.protected int
startsWith(java.lang.CharSequence sequence, java.lang.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 Detail
-
cache
final JexlCache<java.lang.String,TemplateEngine.TemplateExpression> cache
The TemplateExpression cache.
-
jexl
final Engine jexl
The JEXL engine instance.
-
logger
final org.apache.commons.logging.Log logger
The logger.
-
immediateChar
final char immediateChar
The first character for immediate expressions.
-
deferredChar
final char deferredChar
The first character for deferred expressions.
-
noscript
final boolean noscript
Whether expressions can use JEXL script or only expressions (ie, no for, var, etc).
-
-
Constructor Detail
-
TemplateEngine
public TemplateEngine(Engine jexl, boolean noScript, int cacheSize, char immediate, char deferred)
Creates a new instance ofJxltEngine
creating 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 Detail
-
append
private static int append(java.lang.StringBuilder strb, java.lang.CharSequence expr, int position, char c)
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, java.lang.String action, TemplateEngine.TemplateExpression expr, java.lang.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
protected static java.util.Iterator<java.lang.CharSequence> readLines(java.io.Reader reader)
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:
clearCache
in classJxltEngine
-
createExpression
public JxltEngine.Expression createExpression(JexlInfo jexlInfo, java.lang.String expression)
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
-
createTemplate
public TemplateScript createTemplate(JexlInfo info, java.lang.String prefix, java.io.Reader source, java.lang.String... parms)
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
-
getDeferredChar
char getDeferredChar()
- Returns:
- the deferred character
-
getEngine
public Engine getEngine()
Gets the JexlEngine underlying this JxltEngine.- Specified by:
getEngine
in classJxltEngine
- Returns:
- the JexlEngine
-
getImmediateChar
char getImmediateChar()
- Returns:
- the immediate character
-
parseExpression
TemplateEngine.TemplateExpression parseExpression(JexlInfo info, java.lang.String expr, Scope scope)
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
protected java.util.List<TemplateEngine.Block> readTemplate(java.lang.String prefix, java.io.Reader source)
Reads lines of a template grouping them by typed blocks.- Parameters:
prefix
- the directive prefixsource
- the source reader- Returns:
- the list of blocks
-
startsWith
protected int startsWith(java.lang.CharSequence sequence, java.lang.CharSequence pattern)
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
-
-