org.thymeleaf.templateresolver
Interface ITemplateResolver

All Known Implementing Classes:
AbstractTemplateResolver, ClassLoaderTemplateResolver, FileTemplateResolver, ServletContextTemplateResolver, TemplateResolver, UrlTemplateResolver

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:

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.

Since:
1.0
Author:
Daniel Fernández

Method Summary
 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.
 

Method Detail

getName

String getName()

Returns the name of this template resolver. Used in logs and configuration details.

Returns:
the template resolver name.

getOrder

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.

Returns:
the order of this resolver in the chain.

resolveTemplate

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.

Parameters:
templateProcessingParameters - the information required to resolve a template
Returns:
a TemplateResolution object containing (maybe valid) resource resolution info for the template, or null.

initialize

void 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 © 2012 The THYMELEAF team. All Rights Reserved.