public class WebEngineContext extends AbstractEngineContext implements IEngineContext, IWebContext
Basic web implementation of the IEngineContext interface, based on the Servlet API.
This is the context implementation that will be used by default for web processing. Note that this is an internal implementation, and there is no reason for users' code to directly reference or use it instead of its implemented interfaces.
This class is NOT thread-safe. Thread-safety is not a requirement for context implementations.
| Constructor and Description |
|---|
WebEngineContext(IEngineConfiguration configuration,
TemplateData templateData,
Map<String,Object> templateResolutionAttributes,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.ServletContext servletContext,
Locale locale,
Map<String,Object> variables)
Creates a new instance of this
IEngineContext implementation binding engine execution to
the Servlet API. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsVariable(String name)
Checks whether a specific variable is already contained in this context or not.
|
void |
decreaseLevel()
Decrease the context level.
|
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. |
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. |
IInliner |
getInliner()
Returns the inliner (implementation of
IInliner) set to be used at the current point
of execution. |
javax.servlet.http.HttpServletRequest |
getRequest()
Returns the
HttpServletRequest object associated with the template execution. |
javax.servlet.http.HttpServletResponse |
getResponse()
Returns the
HttpServletResponse object associated with the template execution. |
Object |
getSelectionTarget()
Returns the selection target set for the current point of execution (or null if there
isn't any).
|
javax.servlet.ServletContext |
getServletContext()
Returns the
ServletContext object associated with the template execution. |
javax.servlet.http.HttpSession |
getSession()
Returns the
HttpSession object associated with the template execution, or null if
there is no session. |
String |
getStringRepresentationByLevel() |
TemplateData |
getTemplateData()
Returns the template data object containing metadata about the template currently
being processed.
|
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. |
Object |
getVariable(String key)
Retrieve a specific variable, by name.
|
Set<String> |
getVariableNames()
Get a list with all the names of variables contained at this context.
|
boolean |
hasSelectionTarget()
Returns whether the current template has set a selection target for the current point of
execution or not.
|
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 templateData)
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.
|
String |
toString() |
buildLink, getConfiguration, getExpressionObjects, getIdentifierSequences, getLocale, getMessage, getModelFactory, getTemplateMode, getTemplateResolutionAttributesclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbuildLink, getIdentifierSequences, getMessage, getModelFactory, getTemplateMode, getTemplateResolutionAttributesgetConfiguration, getExpressionObjectspublic WebEngineContext(IEngineConfiguration configuration, TemplateData templateData, Map<String,Object> templateResolutionAttributes, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext servletContext, Locale locale, Map<String,Object> variables)
Creates a new instance of this IEngineContext implementation binding engine execution to
the Servlet API.
Note that implementations of IEngineContext are not meant to be used in order to execute
the template engine (use implementations of IContext such as Context or WebContext
instead). This is therefore mostly an internal implementation, and users should have no reason
to ever call this constructor except in very specific integration/extension scenarios.
configuration - the configuration instance being used.templateData - the template data for the template to be processed.templateResolutionAttributes - the template resolution attributes.request - the servlet request object.response - the servlet response object.servletContext - the servlet context object.locale - the locale.variables - the context variables, probably coming from another IContext implementation.public javax.servlet.http.HttpServletRequest getRequest()
IWebContext
Returns the HttpServletRequest object associated with the template execution.
getRequest in interface IWebContextpublic javax.servlet.http.HttpServletResponse getResponse()
IWebContext
Returns the HttpServletResponse object associated with the template execution.
getResponse in interface IWebContextpublic javax.servlet.http.HttpSession getSession()
IWebContext
Returns the HttpSession object associated with the template execution, or null if
there is no session.
getSession in interface IWebContextpublic javax.servlet.ServletContext getServletContext()
IWebContext
Returns the ServletContext object associated with the template execution.
getServletContext in interface IWebContextpublic boolean containsVariable(String name)
IContextChecks whether a specific variable is already contained in this context or not.
containsVariable in interface IContextname - the name of the variable to be checked.public Object getVariable(String key)
IContextRetrieve a specific variable, by name.
getVariable in interface IContextkey - the name of the variable to be retrieved.public Set<String> getVariableNames()
IContextGet a list with all the names of variables contained at this context.
getVariableNames in interface IContextpublic void setVariable(String name, Object value)
IEngineContextSets a new variable into the context.
Depending on the context level, determined by IEngineContext.increaseLevel() and
IEngineContext.decreaseLevel(), 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.
setVariable in interface IEngineContextname - the name of the variable.value - the value of the variable.public void setVariables(Map<String,Object> variables)
IEngineContextSets several variables at a time into the context.
Depending on the context level, determined by IEngineContext.increaseLevel() and
IEngineContext.decreaseLevel(), 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.
setVariables in interface IEngineContextvariables - the variables to be set.public void removeVariable(String name)
IEngineContextRemoves a variable from the context.
Depending on the context level, determined by IEngineContext.increaseLevel() and
IEngineContext.decreaseLevel(), 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.
removeVariable in interface IEngineContextname - the name of the variable to be removed.public boolean isVariableLocal(String name)
IEngineContextChecks 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.
isVariableLocal in interface IEngineContextname - the name of the variable to be checked.public boolean hasSelectionTarget()
ITemplateContextReturns 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.
hasSelectionTarget in interface ITemplateContextpublic Object getSelectionTarget()
ITemplateContextReturns 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.
getSelectionTarget in interface ITemplateContextpublic void setSelectionTarget(Object selectionTarget)
IEngineContextSet 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 IEngineContext.setVariable(String, Object)).
setSelectionTarget in interface IEngineContextselectionTarget - the selection target to be set.public IInliner getInliner()
ITemplateContext
Returns the inliner (implementation of IInliner) set to be used at the current point
of execution.
getInliner in interface ITemplateContextpublic void setInliner(IInliner inliner)
IEngineContextSet 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 IEngineContext.setVariable(String, Object)).
setInliner in interface IEngineContextinliner - the inliner to be set.public TemplateData getTemplateData()
ITemplateContextReturns 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.
getTemplateData in interface ITemplateContextpublic void setTemplateData(TemplateData templateData)
IEngineContext
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 or th:replace.
setTemplateData in interface IEngineContexttemplateData - the template data.public List<TemplateData> getTemplateStack()
ITemplateContext
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).
getTemplateStack in interface ITemplateContextTemplateData).public void setElementTag(IProcessableElementTag elementTag)
IEngineContext
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().
setElementTag in interface IEngineContextelementTag - the element tag.public List<IProcessableElementTag> getElementStack()
ITemplateContext
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.
getElementStack in interface ITemplateContextIProcessableElementTag).public List<IProcessableElementTag> getElementStackAbove(int contextLevel)
IEngineContext
Retrieves the element stack just like ITemplateContext.getElementStack(), but only for those elements added
to the hierarchy above a specific context level.
getElementStackAbove in interface IEngineContextcontextLevel - the level above which we want to obtain the element stack.public int level()
IEngineContextReturn the current context level.
This method should only be called internally.
level in interface IEngineContextpublic void increaseLevel()
IEngineContext
Increase the context level. This is usually a consequence of the
ProcessorTemplateHandler detecting the start of a new element
(i.e. handling an IOpenElementTag event).
This method should only be called internally.
increaseLevel in interface IEngineContextpublic void decreaseLevel()
IEngineContext
Decrease the context level. This is usually a consequence of the
ProcessorTemplateHandler detecting the closing of an element
(i.e. handling an ICloseElementTag event).
This method should only be called internally.
decreaseLevel in interface IEngineContextpublic String getStringRepresentationByLevel()
Copyright © 2016 The THYMELEAF team. All rights reserved.