|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object org.thymeleaf.templateresolver.AbstractTemplateResolver org.thymeleaf.templateresolver.TemplateResolver
public class TemplateResolver
Basic implementation of ITemplateResolver
.
This class can be used both directly and as a parent class for other Template Resolver implementations.
Unless overriden, this class will always apply the following validity to template resolutions:
NonCacheableTemplateResolutionValidity
.AlwaysValidTemplateResolutionValidity
.TTLTemplateResolutionValidity
.
Field Summary | |
---|---|
static Long |
DEFAULT_CACHE_TTL_MS
Default value for the cache TTL: null. |
static boolean |
DEFAULT_CACHEABLE
Default value for the cacheable flag: true. |
static String |
DEFAULT_TEMPLATE_MODE
Default template mode: XHTML |
Constructor Summary | |
---|---|
TemplateResolver()
|
Method Summary | |
---|---|
void |
addTemplateAlias(String alias,
String templateName)
Adds a new template alias to the currently configured ones. |
void |
clearTemplateAliases()
Removes all currently configured template aliases. |
protected String |
computeCharacterEncoding(TemplateProcessingParameters templateProcessingParameters)
Computes the character encoding that should be applied when reading template resource, according to existing configuration. |
protected 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 IResourceResolver |
computeResourceResolver(TemplateProcessingParameters templateProcessingParameters)
Computes the resource resolver that should be applied to a template, according to existing configuration. |
protected String |
computeTemplateMode(TemplateProcessingParameters templateProcessingParameters)
Computes the template mode that should be applied to a template, according to existing configuration. |
protected ITemplateResolutionValidity |
computeValidity(TemplateProcessingParameters templateProcessingParameters)
Computes the validity to be applied to the template resolution. |
java.util.Set<String> |
getCacheablePatterns()
Returns the patterns (as String) specified for establishing which templates have to be considered cacheable. |
PatternSpec |
getCacheablePatternSpec()
Returns the pattern spec specified for establishing which templates have to be considered cacheable. |
Long |
getCacheTTLMs()
Returns the TTL (Time To Live) in cache of templates resolved by this resolver. |
String |
getCharacterEncoding()
Returns the character encoding to be used for reading template resources resolved by this template resolver. |
java.util.Set<String> |
getHtml5TemplateModePatterns()
Returns the patterns specified for establishing the HTML5 (correct, XML-formed HTML5) template mode to resolved templates. |
PatternSpec |
getHtml5TemplateModePatternSpec()
Returns the pattern spec specified for establishing the HTML5 (correct, XML-formed HTML5) template mode to resolved templates. |
java.util.Set<String> |
getLegacyHtml5TemplateModePatterns()
Returns the patterns specified for establishing the LEGACYHTML5 (non-XML-formed HTML5 that needs HTML-to-XML conversion) template mode to resolved templates. |
PatternSpec |
getLegacyHtml5TemplateModePatternSpec()
Returns the pattern spec specified for establishing the LEGACYHTML5 (non-XML-formed HTML5 that needs HTML-to-XML conversion) template mode to resolved templates. |
java.util.Set<String> |
getNonCacheablePatterns()
Returns the patterns (as String) specified for establishing which templates have to be considered non cacheable. |
PatternSpec |
getNonCacheablePatternSpec()
Returns the pattern spec specified for establishing which templates have to be considered non cacheable. |
String |
getPrefix()
Returns the (optional) prefix to be added to all template names in order to convert template names into resource names. |
IResourceResolver |
getResourceResolver()
Returns the Resource Resolver (implementation of IResourceResolver ) that will
be used to resolve the resource names that are assigned to templates resolved
by this template resolver. |
String |
getSuffix()
Returns the (optional) suffix to be added to all template names in order to convert template names into resource names. |
java.util.Map<String,String> |
getTemplateAliases()
Returns the currently configured template aliases. |
String |
getTemplateMode()
Returns the template mode to be applied to templates resolved by this template resolver. |
java.util.Set<String> |
getValidXhtmlTemplateModePatterns()
Returns the patterns specified for establishing the VALIDXHTML (validated XHTML) template mode to resolved templates. |
PatternSpec |
getValidXhtmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the VALIDXHTML (validated XHTML) template mode to resolved templates. |
java.util.Set<String> |
getValidXmlTemplateModePatterns()
Returns the patterns specified for establishing the VALIDXML (validated XML) template mode to resolved templates. |
PatternSpec |
getValidXmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the VALIDXML (validated XML) template mode to resolved templates. |
java.util.Set<String> |
getXhtmlTemplateModePatterns()
Returns the patterns specified for establishing the XHTML template mode to resolved templates. |
PatternSpec |
getXhtmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the XHTML template mode to resolved templates. |
java.util.Set<String> |
getXmlTemplateModePatterns()
Returns the patterns specified for establishing the XML template mode to resolved templates. |
PatternSpec |
getXmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the XML template mode to resolved templates. |
protected void |
initializeSpecific()
Initialize this template resolver. |
protected void |
initializeSpecificAdditional()
Initialize specific aspects of a subclass. |
boolean |
isCacheable()
Returns whether templates resolved by this resolver have to be considered cacheable or not. |
void |
setCacheable(boolean cacheable)
Sets a new value for the cacheable flag. |
void |
setCacheablePatterns(java.util.Set<String> cacheablePatterns)
Sets the new patterns to be applied for establishing which templates have to be considered cacheable These patterns have higher precedence than the cacheable flag (see setCacheable(boolean) ). |
void |
setCacheTTLMs(Long cacheTTLMs)
Sets a new value for the cache TTL for resolved templates. |
void |
setCharacterEncoding(String characterEncoding)
Sets a new character encoding for reading template resources. |
void |
setHtml5TemplateModePatterns(java.util.Set<String> newHtml5TemplatesModePatterns)
Sets the new patterns to be applied for establishing the HTML5 (correct, XML-formed HTML5) template mode as Strings. |
void |
setLegacyHtml5TemplateModePatterns(java.util.Set<String> newLegacyHtml5TemplatesModePatterns)
Sets the new patterns to be applied for establishing the LEGACYHTML5 (non-XML-formed HTML5 that needs HTML-to-XML conversion) template mode as Strings. |
void |
setNonCacheablePatterns(java.util.Set<String> nonCacheablePatterns)
Sets the new patterns to be applied for establishing which templates have to be considered non cacheable These patterns have higher precedence than the cacheable flag (see setCacheable(boolean) ). |
void |
setPrefix(String prefix)
Sets a new (optional) prefix to be added to all template names in order to convert template names into resource names. |
void |
setResourceResolver(IResourceResolver resourceResolver)
Sets the resource resolver to be included into TemplateResolution results. |
void |
setSuffix(String suffix)
Sets a new (optional) suffix to be added to all template names in order to convert template names into resource names. |
void |
setTemplateAliases(java.util.Map<String,String> templateAliases)
Sets all the new template aliases to be used. |
void |
setTemplateMode(String templateMode)
Sets the template mode to be applied to templates resolved by this resolver. |
void |
setTemplateMode(TemplateMode templateMode)
Deprecated. This method has been deprecated as of 2.0.0. Use setTemplateMode(String)
instead. |
void |
setValidXhtmlTemplateModePatterns(java.util.Set<String> newValidXhtmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the VALIDXHTML (validated XHTML) template mode as Strings. |
void |
setValidXmlTemplateModePatterns(java.util.Set<String> newValidXmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the VALIDXML (validated XML) template mode as Strings. |
void |
setXhtmlTemplateModePatterns(java.util.Set<String> newXhtmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the XHTML template mode as Strings. |
void |
setXmlTemplateModePatterns(java.util.Set<String> newXmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the XML template mode as Strings. |
protected Long |
unsafeGetCacheTTLMs()
Uninitialized method meant only for use by subclasses. |
protected String |
unsafeGetCharacterEncoding()
Uninitialized method meant only for use by subclasses. |
protected String |
unsafeGetPrefix()
Uninitialized method meant only for use by subclasses. |
protected IResourceResolver |
unsafeGetResourceResolver()
Uninitialized method meant only for use by subclasses. |
protected String |
unsafeGetSuffix()
Uninitialized method meant only for use by subclasses. |
protected String |
unsafeGetTemplateMode()
Uninitialized method meant only for use by subclasses. |
protected boolean |
unsafeIsCacheable()
Uninitialized method meant only for use by subclasses. |
Methods inherited from class org.thymeleaf.templateresolver.AbstractTemplateResolver |
---|
checkInitialized, checkNotInitialized, computeResolvable, getName, getOrder, getResolvablePatterns, getResolvablePatternSpec, initialize, isInitialized, resolveTemplate, setName, setOrder, setResolvablePatterns, unsafeGetName, unsafeGetOrder |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_TEMPLATE_MODE
Default template mode: XHTML
public static final boolean DEFAULT_CACHEABLE
Default value for the cacheable flag: true.
public static final Long DEFAULT_CACHE_TTL_MS
Default value for the cache TTL: null. This means the parsed template will live in cache until removed by LRU (because of being the oldest entry).
Constructor Detail |
---|
public TemplateResolver()
Method Detail |
---|
protected final void initializeSpecific()
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.
initializeSpecific
in class AbstractTemplateResolver
protected void initializeSpecificAdditional()
Initialize specific aspects of a subclass. This method is called during initialization
of TemplateResolver (AbstractTemplateResolver.initialize()
) and is meant for being overridden by subclasses.
public final String getPrefix()
Returns the (optional) prefix to be added to all template names in order to convert template names into resource names.
protected final String unsafeGetPrefix()
Uninitialized method meant only for use by subclasses.
public void setPrefix(String prefix)
Sets a new (optional) prefix to be added to all template names in order to convert template names into resource names.
prefix
- the prefix to be set.public final String getSuffix()
Returns the (optional) suffix to be added to all template names in order to convert template names into resource names.
protected final String unsafeGetSuffix()
Uninitialized method meant only for use by subclasses.
public void setSuffix(String suffix)
Sets a new (optional) suffix to be added to all template names in order to convert template names into resource names.
suffix
- the suffix to be set.public final String getCharacterEncoding()
Returns the character encoding to be used for reading template resources resolved by this template resolver.
protected final String unsafeGetCharacterEncoding()
Uninitialized method meant only for use by subclasses.
public void setCharacterEncoding(String characterEncoding)
Sets a new character encoding for reading template resources.
characterEncoding
- the character encoding to be used.public final String getTemplateMode()
Returns the template mode to be applied to templates resolved by this template resolver.
If template mode patterns (see setXhtmlTemplateModePatterns(Set)
,
setHtml5TemplateModePatterns(Set)
, etc.) are also set, they have higher
priority than the template mode set here (this would act as a default).
protected final String unsafeGetTemplateMode()
Uninitialized method meant only for use by subclasses.
public void setTemplateMode(String templateMode)
Sets the template mode to be applied to templates resolved by this resolver.
The set of available template modes is variable, as these can be established
by the user by means of adding TemplateModeHandler
objects to the engine. Nevertheless, there is a standard set of
template modes defined by the StandardTemplateModeHandlers
class.
If template mode patterns (see setXhtmlTemplateModePatterns(Set)
,
setHtml5TemplateModePatterns(Set)
, etc.) are also set, they have higher
priority than the template mode set here (this would act as a default).
templateMode
- the template mode.@Deprecated public void setTemplateMode(TemplateMode templateMode)
setTemplateMode(String)
instead.
Sets the template mode to be applied to templates resolved by this resolver.
If template mode patterns (see setXhtmlTemplateModePatterns(Set)
,
setHtml5TemplateModePatterns(Set)
, etc.) are also set, they have higher
priority than the template mode set here (this would act as a default).
templateMode
- public final boolean isCacheable()
Returns whether templates resolved by this resolver have to be considered cacheable or not.
If cacheable patterns (see setCacheablePatterns(Set)
)
are also set, they have higher priority than the value set here (this
would act as a default).
protected final boolean unsafeIsCacheable()
Uninitialized method meant only for use by subclasses.
public void setCacheable(boolean cacheable)
Sets a new value for the cacheable flag.
If cacheable patterns (see setCacheablePatterns(Set)
)
are also set, they have higher priority than the value set here (this
would act as a default).
cacheable
- whether resolved patterns should be considered cacheable or not.public final Long getCacheTTLMs()
Returns the TTL (Time To Live) in cache of templates resolved by this resolver.
If a template is resolved as cacheable but cache TTL is null, this means the template will live in cache until evicted by LRU (Least Recently Used) algorithm for being the oldest entry in cache.
protected final Long unsafeGetCacheTTLMs()
Uninitialized method meant only for use by subclasses.
public void setCacheTTLMs(Long cacheTTLMs)
Sets a new value for the cache TTL for resolved templates.
If a template is resolved as cacheable but cache TTL is null, this means the template will live in cache until evicted by LRU (Least Recently Used) algorithm for being the oldest entry in cache.
cacheTTLMs
- the new cache TTL, or null for using natural LRU eviction.public final java.util.Map<String,String> getTemplateAliases()
Returns the currently configured template aliases.
Template aliases allow the use of several (and probably shorter) names for templates.
Aliases are applied to template names before prefix/suffix.
public void setTemplateAliases(java.util.Map<String,String> templateAliases)
Sets all the new template aliases to be used.
Template aliases allow the use of several (and probably shorter) names for templates.
Aliases are applied to template names before prefix/suffix.
templateAliases
- the new template aliases.public void addTemplateAlias(String alias, String templateName)
Adds a new template alias to the currently configured ones.
alias
- the new alias nametemplateName
- the name of the template the alias will be applied topublic void clearTemplateAliases()
Removes all currently configured template aliases.
public final PatternSpec getXmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the XML template mode to resolved templates.
public final java.util.Set<String> getXmlTemplateModePatterns()
Returns the patterns specified for establishing the XML template mode to resolved templates.
This is a convenience method equivalent to getXmlTemplateModePatternSpec()
.getPatterns()
public final void setXmlTemplateModePatterns(java.util.Set<String> newXmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the XML template mode as Strings.
This is a convenience method equivalent to getXmlTemplateModePatternSpec()
.setPatterns(Set
newXmlTemplatesModePatterns
- the new patternspublic final PatternSpec getValidXmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the VALIDXML (validated XML) template mode to resolved templates.
public final java.util.Set<String> getValidXmlTemplateModePatterns()
Returns the patterns specified for establishing the VALIDXML (validated XML) template mode to resolved templates.
This is a convenience method equivalent to getValidXmlTemplateModePatternSpec()
.getPatterns()
public final void setValidXmlTemplateModePatterns(java.util.Set<String> newValidXmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the VALIDXML (validated XML) template mode as Strings.
This is a convenience method equivalent to getValidXmlTemplateModePatternSpec()
.setPatterns(Set
newValidXmlTemplatesModePatterns
- the new patternspublic final PatternSpec getXhtmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the XHTML template mode to resolved templates.
public final java.util.Set<String> getXhtmlTemplateModePatterns()
Returns the patterns specified for establishing the XHTML template mode to resolved templates.
This is a convenience method equivalent to getXhtmlTemplateModePatternSpec()
.getPatterns()
public final void setXhtmlTemplateModePatterns(java.util.Set<String> newXhtmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the XHTML template mode as Strings.
This is a convenience method equivalent to getXhtmlTemplateModePatternSpec()
.setPatterns(Set
newXhtmlTemplatesModePatterns
- the new patternspublic final PatternSpec getValidXhtmlTemplateModePatternSpec()
Returns the pattern spec specified for establishing the VALIDXHTML (validated XHTML) template mode to resolved templates.
public final java.util.Set<String> getValidXhtmlTemplateModePatterns()
Returns the patterns specified for establishing the VALIDXHTML (validated XHTML) template mode to resolved templates.
This is a convenience method equivalent to getValidXhtmlTemplateModePatternSpec()
.getPatterns()
public final void setValidXhtmlTemplateModePatterns(java.util.Set<String> newValidXhtmlTemplatesModePatterns)
Sets the new patterns to be applied for establishing the VALIDXHTML (validated XHTML) template mode as Strings.
This is a convenience method equivalent to getValidXhtmlTemplateModePatternSpec()
.setPatterns(Set
newValidXhtmlTemplatesModePatterns
- the new patternspublic final PatternSpec getLegacyHtml5TemplateModePatternSpec()
Returns the pattern spec specified for establishing the LEGACYHTML5 (non-XML-formed HTML5 that needs HTML-to-XML conversion) template mode to resolved templates.
public final java.util.Set<String> getLegacyHtml5TemplateModePatterns()
Returns the patterns specified for establishing the LEGACYHTML5 (non-XML-formed HTML5 that needs HTML-to-XML conversion) template mode to resolved templates.
This is a convenience method equivalent to getLegacyHtml5TemplateModePatternSpec()
.getPatterns()
public final void setLegacyHtml5TemplateModePatterns(java.util.Set<String> newLegacyHtml5TemplatesModePatterns)
Sets the new patterns to be applied for establishing the LEGACYHTML5 (non-XML-formed HTML5 that needs HTML-to-XML conversion) template mode as Strings.
This is a convenience method equivalent to getLegacyHtml5TemplateModePatternSpec()
.setPatterns(Set
newLegacyHtml5TemplatesModePatterns
- the new patternspublic final PatternSpec getHtml5TemplateModePatternSpec()
Returns the pattern spec specified for establishing the HTML5 (correct, XML-formed HTML5) template mode to resolved templates.
public final java.util.Set<String> getHtml5TemplateModePatterns()
Returns the patterns specified for establishing the HTML5 (correct, XML-formed HTML5) template mode to resolved templates.
This is a convenience method equivalent to getHtml5TemplateModePatternSpec()
.getPatterns()
public final void setHtml5TemplateModePatterns(java.util.Set<String> newHtml5TemplatesModePatterns)
Sets the new patterns to be applied for establishing the HTML5 (correct, XML-formed HTML5) template mode as Strings.
This is a convenience method equivalent to getHtml5TemplateModePatternSpec()
.setPatterns(Set
newHtml5TemplatesModePatterns
- the new patternspublic final PatternSpec getCacheablePatternSpec()
Returns the pattern spec specified for establishing which templates have to be considered cacheable.
These patterns have higher precedence than the cacheable
flag (see setCacheable(boolean)
). Such flag can be considered
a default value after cacheable patterns and
non-cacheable patterns have been applied.
public final java.util.Set<String> getCacheablePatterns()
Returns the patterns (as String) specified for establishing which templates have to be considered cacheable.
These patterns have higher precedence than the cacheable
flag (see setCacheable(boolean)
). Such flag can be considered
a default value after cacheable patterns and
non-cacheable patterns have been applied.
This is a convenience method equivalent to getCacheablePatternSpec()
.getPatterns()
public final void setCacheablePatterns(java.util.Set<String> cacheablePatterns)
Sets the new patterns to be applied for establishing which templates have to be considered cacheable
These patterns have higher precedence than the cacheable
flag (see setCacheable(boolean)
). Such flag can be considered
a default value after cacheable patterns and
non-cacheable patterns have been applied.
This is a convenience method equivalent to getCacheablePatternSpec()
.setPatterns(Set
cacheablePatterns
- the new patternspublic final PatternSpec getNonCacheablePatternSpec()
Returns the pattern spec specified for establishing which templates have to be considered non cacheable.
These patterns have higher precedence than the cacheable
flag (see setCacheable(boolean)
). Such flag can be considered
a default value after cacheable patterns and
non-cacheable patterns have been applied.
public final java.util.Set<String> getNonCacheablePatterns()
Returns the patterns (as String) specified for establishing which templates have to be considered non cacheable.
These patterns have higher precedence than the cacheable
flag (see setCacheable(boolean)
). Such flag can be considered
a default value after cacheable patterns and
non-cacheable patterns have been applied.
This is a convenience method equivalent to getNonCacheablePatternSpec()
.getPatterns()
public final void setNonCacheablePatterns(java.util.Set<String> nonCacheablePatterns)
Sets the new patterns to be applied for establishing which templates have to be considered non cacheable
These patterns have higher precedence than the cacheable
flag (see setCacheable(boolean)
). Such flag can be considered
a default value after cacheable patterns and
non-cacheable patterns have been applied.
This is a convenience method equivalent to getNonCacheablePatternSpec()
.setPatterns(Set
nonCacheablePatterns
- the new patternspublic IResourceResolver getResourceResolver()
Returns the Resource Resolver (implementation of IResourceResolver
) that will
be used to resolve the resource names that are assigned to templates resolved
by this template resolver.
protected IResourceResolver unsafeGetResourceResolver()
Uninitialized method meant only for use by subclasses.
public void setResourceResolver(IResourceResolver resourceResolver)
Sets the resource resolver to be included into TemplateResolution
results.
resourceResolver
- the new resource resolver.protected String computeResourceName(TemplateProcessingParameters templateProcessingParameters)
AbstractTemplateResolver
Computes the resource name from the template name, applying aliases, prefix/suffix, or any other artifacts the Template Resolver might need to apply.
computeResourceName
in class AbstractTemplateResolver
templateProcessingParameters
- the template processing parameters
protected String computeTemplateMode(TemplateProcessingParameters templateProcessingParameters)
AbstractTemplateResolver
Computes the template mode that should be applied to a template, according to existing configuration.
computeTemplateMode
in class AbstractTemplateResolver
templateProcessingParameters
- the template processing parameters
protected ITemplateResolutionValidity computeValidity(TemplateProcessingParameters templateProcessingParameters)
AbstractTemplateResolver
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.
computeValidity
in class AbstractTemplateResolver
templateProcessingParameters
- the template processing parameters
protected IResourceResolver computeResourceResolver(TemplateProcessingParameters templateProcessingParameters)
AbstractTemplateResolver
Computes the resource resolver that should be applied to a template, according to existing configuration.
computeResourceResolver
in class AbstractTemplateResolver
templateProcessingParameters
- the template processing parameters
protected String computeCharacterEncoding(TemplateProcessingParameters templateProcessingParameters)
AbstractTemplateResolver
Computes the character encoding that should be applied when reading template resource, according to existing configuration.
computeCharacterEncoding
in class AbstractTemplateResolver
templateProcessingParameters
- the template processing parameters
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |