org.thymeleaf.templateresolver
Class AbstractTemplateResolver

Object
  extended by org.thymeleaf.templateresolver.AbstractTemplateResolver
All Implemented Interfaces:
ITemplateResolver
Direct Known Subclasses:
TemplateResolver

public abstract class AbstractTemplateResolver
extends Object
implements ITemplateResolver

Convenience base class for all Template Resolvers.

This class allows configuration of:

Since:
1.0
Author:
Daniel Fernández

Constructor Summary
AbstractTemplateResolver()
           
 
Method Summary
protected  void checkInitialized()
           Check the template resolver is initialized, and throw an exception if it is not.
protected  void checkNotInitialized()
           Check the template resolver is not initialized, and throw an exception if it is.
protected abstract  String computeCharacterEncoding(TemplateProcessingParameters templateProcessingParameters)
           Computes the character encoding that should be applied when reading template resource, according to existing configuration.
protected  boolean computeResolvable(TemplateProcessingParameters templateProcessingParameters)
           Computes whether a template can be resolved by this resolver or not, applying the corresponding patterns.
protected abstract  String computeResourceName(TemplateProcessingParameters templateProcessingParameters)
           Computes the resource name from the template name, applying aliases, prefix/suffix, or any other artifacts the Template Resolver might need to apply.
protected abstract  IResourceResolver computeResourceResolver(TemplateProcessingParameters templateProcessingParameters)
           Computes the resource resolver that should be applied to a template, according to existing configuration.
protected abstract  String computeTemplateMode(TemplateProcessingParameters templateProcessingParameters)
           Computes the template mode that should be applied to a template, according to existing configuration.
protected abstract  ITemplateResolutionValidity computeValidity(TemplateProcessingParameters templateProcessingParameters)
           Computes the validity to be applied to the template resolution.
 String getName()
           Returns the name of the template resolver
 Integer getOrder()
           Returns the order in which this template resolver will be asked to resolve templates as a part of the chain of resolvers configured into the template engine.
 java.util.Set<String> getResolvablePatterns()
           Returns the patterns (as String) specified for establishing which templates can be resolved by this template resolver.
 PatternSpec getResolvablePatternSpec()
           Returns the pattern spec specified for establishing which templates can be resolved by this template resolver.
 void initialize()
           Initialize this template resolver.
protected  void initializeSpecific()
           Initialize specific aspects of a subclass.
protected  boolean isInitialized()
           
 TemplateResolution resolveTemplate(TemplateProcessingParameters templateProcessingParameters)
           Tries to resolve a template.
 void setName(String name)
           Sets a new name for the Template Resolver.
 void setOrder(Integer order)
           Sets a new order for the template engine in the chain.
 void setResolvablePatterns(java.util.Set<String> resolvablePatterns)
           Sets the new patterns to be applied for establishing which templates can be resolved by this template resolver.
protected  String unsafeGetName()
           Uninitialized method meant only for use by subclasses.
protected  Integer unsafeGetOrder()
           Unsynchronized method meant only for use by subclasses.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTemplateResolver

public AbstractTemplateResolver()
Method Detail

isInitialized

protected final boolean isInitialized()

initialize

public final void initialize()

Initialize this template resolver.

Once initialized the configuration parameters of this template resolvers cannot be changed.

Initialization is automatically triggered by the Template Engine before processing the first template.

Specified by:
initialize in interface ITemplateResolver

initializeSpecific

protected void initializeSpecific()

Initialize specific aspects of a subclass. This method is called during initialization of TemplateResolver (initialize()) and is meant for being overridden by subclasses.


checkNotInitialized

protected final void checkNotInitialized()

Check the template resolver is not initialized, and throw an exception if it is.

Calling this method allows to protect calls to methods that change the configuration, ensuring the template resolver has not been initialized yet.


checkInitialized

protected final void checkInitialized()

Check the template resolver is initialized, and throw an exception if it is not.

Calling this method allows to protect calls to methods that need the template resolver to be already initialized.


getName

public String getName()

Returns the name of the template resolver

Specified by:
getName in interface ITemplateResolver
Returns:
the name of the template resolver

unsafeGetName

protected String unsafeGetName()

Uninitialized method meant only for use by subclasses.

Returns:
the name

setName

public void setName(String name)

Sets a new name for the Template Resolver.

Parameters:
name - the new name

getOrder

public Integer getOrder()

Returns the order in which this template resolver will be asked to resolve templates as a part of the chain of resolvers configured into the template engine.

Order should start with 1.

Specified by:
getOrder in interface ITemplateResolver
Returns:
the order in which this template resolver will be called in the chain.

unsafeGetOrder

protected Integer unsafeGetOrder()

Unsynchronized method meant only for use by subclasses.

Returns:
the order

setOrder

public void setOrder(Integer order)

Sets a new order for the template engine in the chain. Order should start with 1.

Parameters:
order - the new order.

getResolvablePatternSpec

public PatternSpec getResolvablePatternSpec()

Returns the pattern spec specified for establishing which templates can be resolved by this template resolver. For those templates which names do not match this patterns, the Template Resolver will return null.

This allows for a fast discard of those templates that the developer might know for sure that will not be resolvable by the Resource Resolver used by this Template Resolver, so that an execution of the resource resolver is not needed.

Returns:
the pattern spec

getResolvablePatterns

public java.util.Set<String> getResolvablePatterns()

Returns the patterns (as String) specified for establishing which templates can be resolved by this template resolver. For those templates which names do not match this patterns, the Template Resolver will return null.

This allows for a fast discard of those templates that the developer might know for sure that will not be resolvable by the Resource Resolver used by this Template Resolver, so that an execution of the resource resolver is not needed.

This is a convenience method equivalent to getResolvablePatternSpec().getPatterns()

Returns:
the pattern spec

setResolvablePatterns

public void setResolvablePatterns(java.util.Set<String> resolvablePatterns)

Sets the new patterns to be applied for establishing which templates can be resolved by this template resolver. For those templates which names do not match this patterns, the Template Resolver will return null.

This allows for a fast discard of those templates that the developer might know for sure that will not be resolvable by the Resource Resolver used by this Template Resolver, so that an execution of the resource resolver is not needed.

This is a convenience method equivalent to getResolvablePatternSpec().setPatterns(Set)

Parameters:
resolvablePatterns - the new patterns

resolveTemplate

public TemplateResolution resolveTemplate(TemplateProcessingParameters templateProcessingParameters)
Description copied from interface: ITemplateResolver

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.

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

computeResolvable

protected boolean computeResolvable(TemplateProcessingParameters templateProcessingParameters)

Computes whether a template can be resolved by this resolver or not, applying the corresponding patterns. Meant only for use by subclasses.

Parameters:
templateProcessingParameters - the template processing parameters
Returns:
whether the template is resolvable or not

computeResourceName

protected abstract String computeResourceName(TemplateProcessingParameters templateProcessingParameters)

Computes the resource name from the template name, applying aliases, prefix/suffix, or any other artifacts the Template Resolver might need to apply.

Parameters:
templateProcessingParameters - the template processing parameters
Returns:
the resource name

computeResourceResolver

protected abstract IResourceResolver computeResourceResolver(TemplateProcessingParameters templateProcessingParameters)

Computes the resource resolver that should be applied to a template, according to existing configuration.

Parameters:
templateProcessingParameters - the template processing parameters
Returns:
the resource resolver to be applied

computeCharacterEncoding

protected abstract String computeCharacterEncoding(TemplateProcessingParameters templateProcessingParameters)

Computes the character encoding that should be applied when reading template resource, according to existing configuration.

Parameters:
templateProcessingParameters - the template processing parameters
Returns:
the resource resolver to be applied

computeTemplateMode

protected abstract String computeTemplateMode(TemplateProcessingParameters templateProcessingParameters)

Computes the template mode that should be applied to a template, according to existing configuration.

Parameters:
templateProcessingParameters - the template processing parameters
Returns:
the template mode to be applied

computeValidity

protected abstract ITemplateResolutionValidity computeValidity(TemplateProcessingParameters templateProcessingParameters)

Computes the validity to be applied to the template resolution. This includes determining whether the template can be cached or not, and also in what circumstances (for instance, for how much time) can its cache entry be considered valid.

Parameters:
templateProcessingParameters - the template processing parameters
Returns:
the validity


Copyright © 2012 The THYMELEAF team. All Rights Reserved.