Class WebEngineContext.ExchangeAttributeMap

    • Constructor Detail

      • ExchangeAttributeMap

        ExchangeAttributeMap​(IEngineConfiguration configuration,
                             TemplateData templateData,
                             java.util.Map<java.lang.String,​java.lang.Object> templateResolutionAttributes,
                             IWebExchange webExchange,
                             java.util.Locale locale,
                             java.util.Map<java.lang.String,​java.lang.Object> variables)
    • Method Detail

      • containsVariable

        public boolean containsVariable​(java.lang.String name)
        Description copied from interface: IContext

        Checks whether a specific variable is already contained in this context or not.

        Specified by:
        containsVariable in interface IContext
        Parameters:
        name - the name of the variable to be checked.
        Returns:
        true if the variable is already contained, false if not.
      • getVariable

        public java.lang.Object getVariable​(java.lang.String name)
        Description copied from interface: IContext

        Retrieve a specific variable, by name.

        Specified by:
        getVariable in interface IContext
        Parameters:
        name - the name of the variable to be retrieved.
        Returns:
        the variable's value.
      • getVariableNames

        public java.util.Set<java.lang.String> getVariableNames()
        Description copied from interface: IContext

        Get a list with all the names of variables contained at this context.

        Specified by:
        getVariableNames in interface IContext
        Returns:
        the variable names.
      • searchNameInIndex

        private int searchNameInIndex​(java.lang.String name,
                                      int idx)
      • setVariable

        public void setVariable​(java.lang.String name,
                                java.lang.Object value)
        Description copied from interface: IEngineContext

        Sets 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.

        Specified by:
        setVariable in interface IEngineContext
        Parameters:
        name - the name of the variable.
        value - the value of the variable.
      • setVariables

        public void setVariables​(java.util.Map<java.lang.String,​java.lang.Object> variables)
        Description copied from interface: IEngineContext

        Sets 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.

        Specified by:
        setVariables in interface IEngineContext
        Parameters:
        variables - the variables to be set.
      • removeVariable

        public void removeVariable​(java.lang.String name)
        Description copied from interface: IEngineContext

        Removes 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.

        Specified by:
        removeVariable in interface IEngineContext
        Parameters:
        name - the name of the variable to be removed.
      • isVariableLocal

        public boolean isVariableLocal​(java.lang.String name)
        Description copied from interface: IEngineContext

        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.

        Specified by:
        isVariableLocal in interface IEngineContext
        Parameters:
        name - the name of the variable to be checked.
        Returns:
        true if the variable is local (level > 0), false if not (level == 0).
      • hasSelectionTarget

        public boolean hasSelectionTarget()
        Description copied from interface: ITemplateContext

        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.

        Specified by:
        hasSelectionTarget in interface ITemplateContext
        Returns:
        true if there is a selection target, false if not.
      • getSelectionTarget

        public java.lang.Object getSelectionTarget()
        Description copied from interface: ITemplateContext

        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.

        Specified by:
        getSelectionTarget in interface ITemplateContext
        Returns:
        the selection target, or null if there isn't any.
      • setSelectionTarget

        public void setSelectionTarget​(java.lang.Object selectionTarget)
        Description copied from interface: IEngineContext

        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 IEngineContext.setVariable(String, Object)).

        Specified by:
        setSelectionTarget in interface IEngineContext
        Parameters:
        selectionTarget - the selection target to be set.
      • getTemplateData

        public TemplateData getTemplateData()
        Description copied from interface: ITemplateContext

        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.

        Specified by:
        getTemplateData in interface ITemplateContext
        Returns:
        the template data corresponding to the elements or nodes being currently processed.
      • setTemplateData

        public void setTemplateData​(TemplateData templateData)
        Description copied from interface: 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.

        Specified by:
        setTemplateData in interface IEngineContext
        Parameters:
        templateData - the template data.
      • getTemplateStack

        public java.util.List<TemplateData> getTemplateStack()
        Description copied from interface: 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).

        Specified by:
        getTemplateStack in interface ITemplateContext
        Returns:
        the stack of templates (list of TemplateData).
      • getElementStack

        public java.util.List<IProcessableElementTag> getElementStack()
        Description copied from interface: 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.

        Specified by:
        getElementStack in interface ITemplateContext
        Returns:
        the stack of elements (list of IProcessableElementTag).
      • getElementStackAbove

        public java.util.List<IProcessableElementTag> getElementStackAbove​(int contextLevel)
        Description copied from interface: IEngineContext

        Retrieves the element stack just like ITemplateContext.getElementStack(), but only for those elements added to the hierarchy above a specific context level.

        Specified by:
        getElementStackAbove in interface IEngineContext
        Parameters:
        contextLevel - the level above which we want to obtain the element stack.
        Returns:
        the element stack above a specified level.
      • ensureLevelInitialized

        private void ensureLevelInitialized​(boolean initVariables)
      • level

        public int level()
        Description copied from interface: IEngineContext

        Return the current context level.

        This method should only be called internally.

        Specified by:
        level in interface IEngineContext
        Returns:
        the current level
      • getStringRepresentationByLevel

        public java.lang.String getStringRepresentationByLevel()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object