public interface ITemplateResolver
Interface for all Template Resolvers.
Template resolvers are in charge of resolving template names into
TemplateResolution
objects that contain additional information related to
the template like:
IResourceResolver
)
to be used for trying to read this template.
The Template Resolver will usually get all this information from a set of configurations
like applicability patterns, template mode patterns, etc. Each ITemplateResolver
implementation will provide its own set of methods for specifying such configurations.
Note that it is allowed for a Template Resolver to return a result even if a template will not be resolvable by its Resource Resolver in the end. Many times it is not possible to know whether a template can be effectively resolved by a template resolver until the template resource is actually read into an InputStream so, in order to avoid two read operations for each template, many times Template Resolvers will return a result but Resource Resolvers will return none once executed.
A Template Engine can be configured several template resolvers, and these will
be asked in order (according to the value returned by getOrder()
) to return
a TemplateResolution
object for each template name. If a template resolver
returns null or its resource resolver does, the next one in the chain is asked.
Modifier and Type | Method and Description |
---|---|
String |
getName()
Returns the name of this template resolver.
|
Integer |
getOrder()
Return the order in which this template resolver will be executed in the
chain when several template resolvers are set for the same Template Engine.
|
void |
initialize()
Initialize the Template Resolver.
|
TemplateResolution |
resolveTemplate(TemplateProcessingParameters templateProcessingParameters)
Tries to resolve a template.
|
String getName()
Returns the name of this template resolver. Used in logs and configuration details.
Integer getOrder()
Return the order in which this template resolver will be executed in the chain when several template resolvers are set for the same Template Engine.
Higher values are interpreted as lower priority. A null value is interpreted as lowest priority, and thus the template resolver will appear last in the chain.
TemplateResolution resolveTemplate(TemplateProcessingParameters templateProcessingParameters)
Tries to resolve a template.
The templateProcessingParameters parameter contains all the info needed for trying to
resolve the template (esp. the template name). The Template Resolver
will apply its configuration (prefixes/suffixes, template mode patterns,
cache configurations, etc) and return a TemplateResolution
object.
This method can return null if the template resolver is completely certain
that a template cannot be resolved by it. But returning a result does not
mean the contrary, because it could be that the IResourceResolver
object returned in the result is not effectively able to resolve the
resource corresponding to this template. As sometimes this cannot be known in
advance (the template resource would have to be read two times
for that), it will not be until the Template Engine executes the Resource
Resolver that it will know whether the template was correctly resolved by
a Template Resolver or not.
templateProcessingParameters
- the information required to resolve a templatevoid initialize()
Initialize the Template Resolver. Once initialized, none of its configuration parameters should be allowed to change.
This method is called by TemplateEngine. Do not use directly in your code.
Copyright © 2016 The THYMELEAF team. All rights reserved.