public final class TemplateSpec extends Object implements Serializable
Specification class containing everything needed by the template engine related to the
template to be processed. Objects of this class are normally used as an argument to the
different process(...) methods at ITemplateEngine
.
The only required value in a template specification is the template, which normally
represents the template name, but can be the entire template contents if the template
is meant to be specified as a String and resolved by a
StringTemplateResolver
.
This is not to be mistaken for the template processing context, containing
the data to be used during the processing of the template (variables, locale, etc.) and
modelled by the IContext
interface.
The data contained in a Template Specification relates to and identifies the template itself, independently of any data (variables, etc.) used for processing it.
Objects of this class are thread-safe.
Constructor and Description |
---|
TemplateSpec(String template,
Map<String,Object> templateResolutionAttributes)
Build a new object of this class, specifying template and also template mode.
|
TemplateSpec(String template,
Set<String> templateSelectors,
TemplateMode templateMode,
Map<String,Object> templateResolutionAttributes)
Build a new object of this class, specifying all its attributes.
|
TemplateSpec(String template,
TemplateMode templateMode)
Build a new object of this class, specifying template and also template mode.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
String |
getTemplate()
Returns the template (usually the template name).
|
TemplateMode |
getTemplateMode()
Returns the template mode, if it has been specified.
|
Map<String,Object> |
getTemplateResolutionAttributes()
Returns the template resolution attributes, if any have been specified.
|
Set<String> |
getTemplateSelectors()
Returns the template selectors, if there are any.
|
int |
hashCode() |
boolean |
hasTemplateMode()
Returns whether this spec has template mode specified or not.
|
boolean |
hasTemplateResolutionAttributes()
Returns whether this spec includes template resolution attributes or not.
|
boolean |
hasTemplateSelectors()
Returns whether this spec has template selectors specified or not.
|
String |
toString() |
public TemplateSpec(String template, TemplateMode templateMode)
Build a new object of this class, specifying template and also template mode.
The template normally represents the template name, but can be the entire template
contents if the template is meant to be specified as a String and resolved by a
StringTemplateResolver
.
The template mode only needs to be specified in cases when we want to force a template mode to be used for a template, independently of the mode that is selected for it by the configured template resolvers.
This constructor will set no template selectors or template resolution attributes.
template
- the template (usually the template name), required.templateMode
- the template mode to be forced, can be null.public TemplateSpec(String template, Map<String,Object> templateResolutionAttributes)
Build a new object of this class, specifying template and also template mode.
The template normally represents the template name, but can be the entire template
contents if the template is meant to be specified as a String and resolved by a
StringTemplateResolver
.
The template resolution attributes are meant to be passed to the template resolvers (see
ITemplateResolver
during template resolution, as a way
of configuring their execution for the template being processed.
Note that template resolution attributes are considered a part of the identifier of a template,
so they will be used as a part of the keys for cached templates. It is therefore
required that template attribute maps contain values with valid equals(Object)
and hashCode()
implementations. Therefore, using simple (and fast)
Map<String,String> maps is the recommended option.
This constructor will set no template selectors or forced template mode.
template
- the template (usually the template name), required.templateResolutionAttributes
- the template resolution attributes, can be null.public TemplateSpec(String template, Set<String> templateSelectors, TemplateMode templateMode, Map<String,Object> templateResolutionAttributes)
Build a new object of this class, specifying all its attributes.
The template usually represents the template name, but can be the entire template
contents if the template is meant to be specified as a String and resolved by a
StringTemplateResolver
.
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.
The template mode only needs to be specified in cases when we want to force a template mode to be used for a template, independently of the mode that is selected for it by the configured template resolvers.
The template resolution attributes are meant to be passed to the template resolvers (see
ITemplateResolver
during template resolution, as a way
of configuring their execution for the template being processed.
Note that template resolution attributes are considered a part of the identifier of a template,
so they will be used as a part of the keys for cached templates. It is therefore
required that template attribute maps contain values with valid equals(Object)
and hashCode()
implementations. Therefore, using simple (and fast)
Map<String,String> maps is the recommended option.
template
- the template (usually the template name), required.templateSelectors
- the template selectors to be applied on the template.templateMode
- the template mode to be forced, can be null.templateResolutionAttributes
- the template resolution attributes, can be null.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 is meant to be specified as a String and resolved by a
StringTemplateResolver
.
public boolean hasTemplateSelectors()
Returns whether this spec has template selectors specified or not.
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.
public boolean hasTemplateMode()
Returns whether this spec has template mode specified or not.
public TemplateMode getTemplateMode()
Returns the template mode, if it has been specified.
The template mode only needs to be specified in cases when we want to force a template mode to be used for a template, independently of the mode that is selected for it by the configured template resolvers.
public boolean hasTemplateResolutionAttributes()
Returns whether this spec includes template resolution attributes or not.
public Map<String,Object> getTemplateResolutionAttributes()
Returns the template resolution attributes, if any have been specified.
The template resolution attributes are meant to be passed to the template resolvers (see
ITemplateResolver
during template resolution, as a way
of configuring their execution for the template being processed.
Note that template resolution attributes are considered a part of the identifier of a template,
so they will be used as a part of the keys for cached templates. It is therefore
required that template attribute maps contain values with valid equals(Object)
and hashCode()
implementations. Therefore, using simple (and fast)
Map<String,String> maps is the recommended option.
Copyright © 2016 The THYMELEAF team. All rights reserved.