Class TemplateData


  • public final class TemplateData
    extends Object

    Class containing all the data related to a template that is currently being processed.

    Objects of this class are meant to be a part of the ITemplateContext instances offered by the engine to processing artifacts such as processors, pre-/post-processors, etc.

    These objects contain some metadata about the template being processed, and also the template resource itself, coming from the TemplateResolution produced by template resolvers (ITemplateResolver).

    The template contained usually represents the template name, but can be the entire template contents if the template has been resolved by a StringTemplateResolver or an analogous implementation of ITemplateResolver.

    Objects of this class should not be considered thread-safe.

    Since:
    3.0.0
    Author:
    Daniel Fernández
    See Also:
    TemplateSpec, TemplateResolution
    • Method Detail

      • getTemplate

        public String getTemplate()

        Returns the template (usually the template name).

        This template normally represents the template name, but can be the entire template contents if the template was specified as a String and resolved by a StringTemplateResolver or equivalent.

        Returns:
        the template. Cannot be null.
      • hasTemplateSelectors

        public boolean hasTemplateSelectors()

        Returns whether this spec has template selectors specified or not.

        Returns:
        true of there are template selectors, false if not.
      • getTemplateSelectors

        public Set<String> getTemplateSelectors()

        Returns the template selectors, if there are any.

        Template selectors allow the possibility to process only a part of the specified template, expressing this selection in a syntax similar to jQuery, CSS or XPath selectors. Note this is only available for markup template modes (HTML, XML). For more info on template selectors syntax, have a look at AttoParser's markup selectors documentation.

        Returns:
        the template selectors, or null if there are none.
      • getTemplateResource

        public ITemplateResource getTemplateResource()

        Returns the template resource.

        Template resource instances are usually created by implementations of ITemplateResolver.

        Note that, even if this resource object will never be null, the existence of the resource object does not necessarily imply the existence of the resource itself unless the template resolver was configured for calling ITemplateResource.exists() upon template resolution.

        Returns:
        the template resource. Cannot be null.
      • getTemplateMode

        public TemplateMode getTemplateMode()

        Returns the template mode the template is being processed with.

        Most times this template mode is the one suggested by the ITemplateResolver that resolved the template, but in those times that a template mode was forced by specifying it at a TemplateSpec object or at a call to the TemplateManager, these will override the template mode suggested by the template resolver.

        Returns:
        the template mode for the template. Cannot be null.
      • getValidity

        public ICacheEntryValidity getValidity()

        Returns the template resolution validity.

        This validity establishes whether the template can be included in the template cache, and also for how long its resolution will be considered valid.

        When a cached template is not considered valid, its cache entry is discarded and it is resolved again.

        Returns:
        the validity object