public class StringTemplateResolver extends AbstractTemplateResolver
Implementation of ITemplateResolver
that extends AbstractTemplateResolver
and creates StringTemplateResource
instances for template resources.
This template resolvers will consider the template being resolved as the template itself, this is, its contents. No external file or resource will be therefore accessed.
This template resolver will consider its resolved templates non-cacheable by default, given its nature of being used for resolving arbitrary String objects.
Also, the TemplateMode.HTML
template mode will be used by default.
Note this is the default template resolver that TemplateEngine
instances will use if no other resolvers are configured.
Modifier and Type | Field and Description |
---|---|
static Long |
DEFAULT_CACHE_TTL_MS
Default value for the cache TTL: null.
|
static boolean |
DEFAULT_CACHEABLE
Default value for the cacheable flag: false.
|
static TemplateMode |
DEFAULT_TEMPLATE_MODE
Default template mode:
TemplateMode.HTML |
DEFAULT_EXISTENCE_CHECK, DEFAULT_USE_DECOUPLED_LOGIC
Constructor and Description |
---|
StringTemplateResolver()
Creates a new instance of this template resolver.
|
Modifier and Type | Method and Description |
---|---|
protected TemplateMode |
computeTemplateMode(IEngineConfiguration configuration,
String ownerTemplate,
String template,
Map<String,Object> templateResolutionAttributes)
Computes the template mode that should be applied to a template, according
to existing configuration.
|
protected ITemplateResource |
computeTemplateResource(IEngineConfiguration configuration,
String ownerTemplate,
String template,
Map<String,Object> templateResolutionAttributes)
Computes the resolved template resource.
|
protected ICacheEntryValidity |
computeValidity(IEngineConfiguration configuration,
String ownerTemplate,
String template,
Map<String,Object> templateResolutionAttributes)
Computes the validity to be applied to the template resolution.
|
Long |
getCacheTTLMs()
Returns the TTL (Time To Live) in cache of templates resolved by this
resolver.
|
TemplateMode |
getTemplateMode()
Returns the template mode to be applied to templates resolved by
this template resolver.
|
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 |
setCacheTTLMs(Long cacheTTLMs)
Sets a new value for the cache TTL for resolved templates.
|
void |
setTemplateMode(String templateMode)
Sets the template mode to be applied to templates resolved by this resolver.
|
void |
setTemplateMode(TemplateMode templateMode)
Sets the template mode to be applied to templates resolved by this resolver.
|
void |
setUseDecoupledLogic(boolean useDecoupledLogic)
Sets whether a separate (decoupled) resource containing template logic should be checked for existence
and its instructions included into the resolved template during parsing.
|
computeResolvable, getCheckExistence, getName, getOrder, getResolvablePatterns, getResolvablePatternSpec, getUseDecoupledLogic, resolveTemplate, setCheckExistence, setName, setOrder, setResolvablePatterns
public static final TemplateMode DEFAULT_TEMPLATE_MODE
Default template mode: TemplateMode.HTML
public static final boolean DEFAULT_CACHEABLE
Default value for the cacheable flag: false.
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).
public StringTemplateResolver()
Creates a new instance of this template resolver.
public final TemplateMode getTemplateMode()
Returns the template mode to be applied to templates resolved by this template resolver.
public final void setTemplateMode(TemplateMode templateMode)
Sets the template mode to be applied to templates resolved by this resolver.
templateMode
- the template mode.public final void setTemplateMode(String templateMode)
Sets the template mode to be applied to templates resolved by this resolver.
Allowed templates modes are defined by the TemplateMode
class.
templateMode
- the template mode.public final boolean isCacheable()
Returns whether templates resolved by this resolver have to be considered cacheable or not.
public final void setCacheable(boolean cacheable)
Sets a new value for the cacheable flag.
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.
public final 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 void setUseDecoupledLogic(boolean useDecoupledLogic)
AbstractTemplateResolver
Sets whether a separate (decoupled) resource containing template logic should be checked for existence and its instructions included into the resolved template during parsing.
This mechanism allows the creation of pure HTML or XML markup templates, which acquire their logic
from an external resource. The way this decoupled resources are resolved is defined by a configured
implementation of the IDecoupledTemplateLogicResolver
interface.
Note this flag can only be true for the TemplateMode.HTML
and TemplateMode.XML
template modes. Also, note that setting this flag to true does not mean that a resource with
decoupled logic must exist for the resolved template, only that it can exist and therefore it should be
checked.
Decoupled logic extracted from these additional resources is injected into the resolved templates in real-time as the resolved templates are parsed and processed. This greatly reduces overhead caused by decoupled parsing for non-cacheable templates, and completely removes any overhead for cached templates.
Default value is FALSE.
setUseDecoupledLogic
in class AbstractTemplateResolver
useDecoupledLogic
- true if resource existence should be checked, false if notprotected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate, String template, Map<String,Object> templateResolutionAttributes)
AbstractTemplateResolver
Computes the resolved template resource.
computeTemplateResource
in class AbstractTemplateResolver
configuration
- the engine configuration.ownerTemplate
- the owner template, if the resource being computed is a fragment. Might be null.template
- the template to be resolved (usually its name).templateResolutionAttributes
- the template resolution attributes, if any. Might be null.protected TemplateMode computeTemplateMode(IEngineConfiguration configuration, String ownerTemplate, String template, Map<String,Object> templateResolutionAttributes)
AbstractTemplateResolver
Computes the template mode that should be applied to a template, according to existing configuration.
computeTemplateMode
in class AbstractTemplateResolver
configuration
- the engine configuration.ownerTemplate
- the owner template, if the resource being computed is a fragment. Might be null.template
- the template to be resolved (usually its name).templateResolutionAttributes
- the template resolution attributes, if any. Might be null.protected ICacheEntryValidity computeValidity(IEngineConfiguration configuration, String ownerTemplate, String template, Map<String,Object> templateResolutionAttributes)
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
configuration
- the engine configuration.ownerTemplate
- the owner template, if the resource being computed is a fragment. Might be null.template
- the template to be resolved (usually its name).templateResolutionAttributes
- the template resolution attributes, if any. Might be null.Copyright © 2016 The THYMELEAF team. All rights reserved.