public interface ITemplateContext extends IExpressionContext
Interface implemented by all classes containing the context required for template processing.
This interface extends IExpressionContext
and IContext
by adding the required
information needed to process templates.
Note that, in order for the template engine to use a custom-made implementation of this interface
for template processing instead of cloning its data, such implementation should also implement
the IEngineContext
interface.
Also note these implementations do not have to be thread-safe, and in fact should not be shared by different threads or template executions. They are meant to be local to a specific template engine execution.
Modifier and Type | Method and Description |
---|---|
String |
buildLink(String base,
Map<String,Object> parameters)
Computes link to be used on a template.
|
List<IProcessableElementTag> |
getElementStack()
Returns the list of all the
IProcessableElementTag objects corresponding to the hierarchy
of elements (open or standalone elements) that had to be processed in order to reach the current
point in execution. |
IdentifierSequences |
getIdentifierSequences()
Returns the
IdentifierSequences object set to be used at the current point of execution. |
IInliner |
getInliner()
Returns the inliner (implementation of
IInliner ) set to be used at the current point
of execution. |
String |
getMessage(Class<?> origin,
String key,
Object[] messageParameters,
boolean useAbsentMessageRepresentation)
Computes an externalized (internationalized, i18n) message to be used on a template.
|
IModelFactory |
getModelFactory()
Returns the model factory that can be used for creating or modifying events.
|
Object |
getSelectionTarget()
Returns the selection target set for the current point of execution (or null if there
isn't any).
|
TemplateData |
getTemplateData()
Returns the template data object containing metadata about the template currently
being processed.
|
TemplateMode |
getTemplateMode()
Returns the template mode of the template currently being processed.
|
Map<String,Object> |
getTemplateResolutionAttributes()
Returns the map of configuration items that have been specified at the process(...) methods of
ITemplateEngine , aimed at further configuring the template being used and its
resolution by means of the ITemplateResolver s. |
List<TemplateData> |
getTemplateStack()
Returns the list of all the
TemplateData objects corresponding to all the templates that have
been nested in order to reach the current execution point. |
boolean |
hasSelectionTarget()
Returns whether the current template has set a selection target for the current point of
execution or not.
|
getConfiguration, getExpressionObjects
containsVariable, getLocale, getVariable, getVariableNames
TemplateData getTemplateData()
Returns the template data object containing metadata about the template currently being processed.
Note that the TemplateData
returned here corresponds with the origin of the elements or
nodes being currently processed. This is, if a processor is being executed for an element inserted
from an external template (via a th:insert, for example), then this method will return
the template data for the template in which the inserted fragment lives, not the one it was inserted
into.
TemplateMode getTemplateMode()
Returns the template mode of the template currently being processed.
Note that the TemplateMode
returned here corresponds with origin of the elements or nodes being
currently processed. This is, if a processor is being executed for an element inserted from an external
template (via a th:insert, for example), then this method will return the template mode
for the template in which the inserted fragment lives, not the one it was inserted into.
List<TemplateData> getTemplateStack()
Returns the list of all the TemplateData
objects corresponding to all the templates that have
been nested in order to reach the current execution point.
This is a way in which processors can know the complete execution route that lead to the execution of a specific event (e.g. Template A inserted fragment B, which inserted fragment C).
The first element in this list will always be the top-level template (the one called at the
ITemplateEngine
process(...) methods).
TemplateData
).List<IProcessableElementTag> getElementStack()
Returns the list of all the IProcessableElementTag
objects corresponding to the hierarchy
of elements (open or standalone elements) that had to be processed in order to reach the current
point in execution.
If the element being processed is a tag (open/standalone), it will appear at the end of the list.
Note this hierarchy does not correspond with the tag hierarchy at the original template, but with the hierarchy of processing (many tags could appear during processing itself and not be present at the original template).
Also note that, because of this being the processing-time hierarchy, this information is set at the processor level, so it should not be considered to be available and/or valid at the pre-processor layer.
IProcessableElementTag
).Map<String,Object> getTemplateResolutionAttributes()
Returns the map of configuration items that have been specified at the process(...) methods of
ITemplateEngine
, aimed at further configuring the template being used and its
resolution by means of the ITemplateResolver
s.
IModelFactory getModelFactory()
Returns the model factory that can be used for creating or modifying events.
This is actually a convenience method completely equivalent to calling
IExpressionContext.getConfiguration()
and then IEngineConfiguration.getModelFactory(TemplateMode)
using as template mode the result of getTemplateMode()
.
boolean hasSelectionTarget()
Returns whether the current template has set a selection target for the current point of execution or not.
Selection targets are objects on which all *{...} expression will be executed (instead of on the root context). They are normally set by means of th:objects.
Object getSelectionTarget()
Returns the selection target set for the current point of execution (or null if there isn't any).
Selection targets are objects on which all *{...} expression will be executed (instead of on the root context). They are normally set by means of th:objects.
IInliner getInliner()
Returns the inliner (implementation of IInliner
) set to be used at the current point
of execution.
String getMessage(Class<?> origin, String key, Object[] messageParameters, boolean useAbsentMessageRepresentation)
Computes an externalized (internationalized, i18n) message to be used on a template.
This method is meant to be called mainly by processors that need to output externalized messages.
origin
- the origin class to be used for message resolution. When calling from a processor, this
is normally the processor class itself. See IMessageResolver
.key
- the key of the message to be retrieved.messageParameters
- the parameters to be applied to the requested message.useAbsentMessageRepresentation
- whether an absent message representation should be returned in
the case that the message does not exist
(see IMessageResolver
).String buildLink(String base, Map<String,Object> parameters)
Computes link to be used on a template.
This method is meant to be called mainly by processors or expressions that need to output links.
base
- the base of the link URL to be built, i.e. its path. Can be null.parameters
- the (optional) URL parameters.IdentifierSequences getIdentifierSequences()
Returns the IdentifierSequences
object set to be used at the current point of execution.
Copyright © 2017 The THYMELEAF team. All rights reserved.