Interface IEngineContext
-
- All Superinterfaces:
IContext
,IExpressionContext
,ITemplateContext
- All Known Implementing Classes:
AbstractEngineContext
,EngineContext
,WebEngineContext
public interface IEngineContext extends ITemplateContext
Mostly-internal interface implemented by all classes containing the context required for template processing inside the engine itself.
This interface extends
ITemplateContext
by adding a series of methods required internally by the template engine for processing, which should not be used from users' code. Calling these methods directly from custom processors or other extensions could have undesirable effects on template processing.Contexts used during template processing by the engine are always implementations of this interface. If the Template Engine is called with an implementation of this
IEngineContext
ascontext
, the same object will be used (so that users can actually provide their own implementations). On the other side, if thecontext
specified to the Template Engine is not an implementation of this interface, an implementation ofIEngineContext
will be internally created by the engine, the original context's variables and other info will be cloned, and used instead.Again note that, besides providing custom-made implementations of this interface (which is a very complex operation, not recommended in most scenarios) there should be no reason why this interface should ever be used in users' code.
- Since:
- 3.0.0
- Author:
- Daniel Fernández
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
decreaseLevel()
Decrease the context level.List<IProcessableElementTag>
getElementStackAbove(int contextLevel)
Retrieves the element stack just likeITemplateContext.getElementStack()
, but only for those elements added to the hierarchy above a specific context level.void
increaseLevel()
Increase the context level.boolean
isVariableLocal(String name)
Checks whether a specific variable is local or not.int
level()
Return the current context level.void
removeVariable(String name)
Removes a variable from the context.void
setElementTag(IProcessableElementTag elementTag)
Sets a new element tag (IProcessableElementTag
) into the hierarchy (stack) of element tags.void
setInliner(IInliner inliner)
Set an inliner.void
setSelectionTarget(Object selectionTarget)
Set a selection target.void
setTemplateData(TemplateData template)
Sets a new template metadata object (TemplateData
) for the current execution point, specifying that the elements and nodes that are to be processed from now on (until the context level is decreased below the current level) originally belonged to a different template.void
setVariable(String name, Object value)
Sets a new variable into the context.void
setVariables(Map<String,Object> variables)
Sets several variables at a time into the context.-
Methods inherited from interface org.thymeleaf.context.IContext
containsVariable, getLocale, getVariable, getVariableNames
-
Methods inherited from interface org.thymeleaf.context.IExpressionContext
getConfiguration, getExpressionObjects
-
Methods inherited from interface org.thymeleaf.context.ITemplateContext
buildLink, getElementStack, getIdentifierSequences, getInliner, getMessage, getModelFactory, getSelectionTarget, getTemplateData, getTemplateMode, getTemplateResolutionAttributes, getTemplateStack, hasSelectionTarget
-
-
-
-
Method Detail
-
setVariable
void setVariable(String name, Object value)
Sets a new variable into the context.
Depending on the context level, determined by
increaseLevel()
anddecreaseLevel()
, the variable being set might be considered a local variable and thus disappear from context once the context level is decreased below the level the variable was created at.- Parameters:
name
- the name of the variable.value
- the value of the variable.
-
setVariables
void setVariables(Map<String,Object> variables)
Sets several variables at a time into the context.
Depending on the context level, determined by
increaseLevel()
anddecreaseLevel()
, the variables being set might be considered a local variables and thus disappear from context once the context level is decreased below the level the variable was created at.- Parameters:
variables
- the variables to be set.
-
removeVariable
void removeVariable(String name)
Removes a variable from the context.
Depending on the context level, determined by
increaseLevel()
anddecreaseLevel()
, this removal might be considered local variable-related and thus cease to happen (i.e. the variable would be recovered) once the context level is decreased below the level the variable was created at.- Parameters:
name
- the name of the variable to be removed.
-
setSelectionTarget
void setSelectionTarget(Object selectionTarget)
Set a selection target. Usually the consequence of executing a
th:object
processor.Once set, all selection expressions (
*{...}
) will be executed on this target.This selection target will have the consideration of a local variable and thus depend on the context level (see
setVariable(String, Object)
).- Parameters:
selectionTarget
- the selection target to be set.
-
setInliner
void setInliner(IInliner inliner)
Set an inliner. Usually the consequence of executing a
th:inline
processor.This inliner will have the consideration of a local variable and thus depend on the context level (see
setVariable(String, Object)
).- Parameters:
inliner
- the inliner to be set.
-
setTemplateData
void setTemplateData(TemplateData template)
Sets a new template metadata object (
TemplateData
) for the current execution point, specifying that the elements and nodes that are to be processed from now on (until the context level is decreased below the current level) originally belonged to a different template.A call on this method is usually the consequence of
th:insert
orth:replace
.- Parameters:
template
- the template data.
-
setElementTag
void setElementTag(IProcessableElementTag elementTag)
Sets a new element tag (
IProcessableElementTag
) into the hierarchy (stack) of element tags.This hierarchy of element tags (added this way) can be obtained with
ITemplateContext.getElementStack()
.- Parameters:
elementTag
- the element tag.
-
getElementStackAbove
List<IProcessableElementTag> getElementStackAbove(int contextLevel)
Retrieves the element stack just like
ITemplateContext.getElementStack()
, but only for those elements added to the hierarchy above a specific context level.- Parameters:
contextLevel
- the level above which we want to obtain the element stack.- Returns:
- the element stack above a specified level.
-
isVariableLocal
boolean isVariableLocal(String name)
Checks whether a specific variable is local or not.
This means checking if the context level at which the variable was defined was 0 or not.
- Parameters:
name
- the name of the variable to be checked.- Returns:
true
if the variable is local (level > 0),false
if not (level == 0).
-
increaseLevel
void increaseLevel()
Increase the context level. This is usually a consequence of the
ProcessorTemplateHandler
detecting the start of a new element (i.e. handling anIOpenElementTag
event).This method should only be called internally.
-
decreaseLevel
void decreaseLevel()
Decrease the context level. This is usually a consequence of the
ProcessorTemplateHandler
detecting the closing of an element (i.e. handling anICloseElementTag
event).This method should only be called internally.
-
level
int level()
Return the current context level.
This method should only be called internally.
- Returns:
- the current level
-
-