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,
String outputContentType,
Map<String,Object> templateResolutionAttributes)
Build a new object of this class, specifying an output content type (MIME type).
|
TemplateSpec(String template,
Set<String> templateSelectors,
TemplateMode templateMode,
Map<String,Object> templateResolutionAttributes)
Build a new object of this class, specifying a template mode that should be forced for template
execution, ignoring the mode resolved by template resolvers.
|
TemplateSpec(String template,
String outputContentType)
Build a new object of this class, specifying template and also output content type
(MIME type).
|
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 |
getOutputContentType()
Returns the output content type (MIME type).
|
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.
|
boolean |
isOutputSSE()
Returns whether output should be Server-Sent Events (SSE) 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, String outputContentType)
Build a new object of this class, specifying template and also output content type (MIME type). Most of the times this will force a template mode for template execution (e.g. text/html, application/javascript), but not always (e.g. text/event-stream).
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
.
Supported relations between template mode and output content type are:
The text/event-stream content type will also be supported, but will have no effect in forcing a template mode. Instead, it will put the engine into Server-Sent Event (SSE) output mode.
Note content type parameters will be ignored (only the mime type itself will be used).
This constructor will set no template selectors or template resolution attributes.
template
- the template (usually the template name), required.outputContentType
- the expected output content type, 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 a template mode that should be forced for template execution, ignoring the mode resolved by template resolvers.
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 TemplateSpec(String template, Set<String> templateSelectors, String outputContentType, Map<String,Object> templateResolutionAttributes)
Build a new object of this class, specifying an output content type (MIME type). Most of the times this will force a template mode for template execution (e.g. text/html, application/javascript), but not always (e.g. text/event-stream).
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 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.
Supported relations between template mode and output content type are:
The text/event-stream content type will also be supported, but will have no effect in forcing a template mode. Instead, it will put the engine into Server-Sent Event (SSE) output mode.
Note content type parameters will be ignored (only the mime type itself will be used).
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.outputContentType
- the expected output content type, 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.
public String getOutputContentType()
Returns the output content type (MIME type). Most of the times this will force a template mode for template execution (e.g. text/html, application/javascript), but not always (e.g. text/event-stream).
Supported relations between template mode and output content type are:
The text/event-stream content type will also be supported, but will have no effect in forcing a template mode. Instead, it will put the engine into Server-Sent Event (SSE) output mode.
Note content type parameters will be ignored (only the mime type itself will be used).
public boolean isOutputSSE()
Returns whether output should be Server-Sent Events (SSE) or not.
Server-Sent Events mode is enabled by setting the text/event-stream mime type as *output content type* constructor argument.
Copyright © 2017 The THYMELEAF team. All rights reserved.