| java.lang.Object freemarker.cache.TemplateCache
TemplateCache | public class TemplateCache (Code) | | A class that performs caching and on-demand loading of the templates.
The actual loading is delegated to a
TemplateLoader . Also,
various constructors provide you with convenient caches with predefined
behavior. Typically you don't use this class directly - in normal
circumstances it is hidden behind a
Configuration .
author: Attila Szegedi, szegedia at freemail dot hu version: $Id: TemplateCache.java,v 1.62.2.2 2007/04/03 18:06:07 szegedia Exp $ |
Constructor Summary | |
public | TemplateCache() Returns a template cache that will first try to load a template from
the file system relative to the current user directory (i.e. | public | TemplateCache(TemplateLoader loader) Creates a new template cache with a custom template loader that is used
to load the templates. | public | TemplateCache(TemplateLoader loader, CacheStorage storage) Creates a new template cache with a custom template loader that is used
to load the templates. |
Method Summary | |
public void | clear() Removes all entries from the cache, forcing reloading of templates
on subsequent
TemplateCache.getTemplate(String,Locale,String,boolean) calls. | public CacheStorage | getCacheStorage() | public synchronized long | getDelay() Gets the delay in milliseconds between checking for newer versions of a
template source. | public static String | getFullTemplatePath(Environment env, String parentTemplateDir, String templateNameString) | public synchronized boolean | getLocalizedLookup() Returns if localized template lookup is enabled or not. | public Template | getTemplate(String name, Locale locale, String encoding, boolean parse) Loads a template with the given name, in the specified locale and
using the specified character encoding.
Parameters: name - the name of the template. | public TemplateLoader | getTemplateLoader() | public void | setConfiguration(Configuration config) Sets the configuration object to which this cache belongs. | public synchronized void | setDelay(long delay) Sets the delay in milliseconds between checking for newer versions of a
template sources. | public synchronized void | setLocalizedLookup(boolean localizedLookup) Setis if localized template lookup is enabled or not. |
TemplateCache | public TemplateCache()(Code) | | Returns a template cache that will first try to load a template from
the file system relative to the current user directory (i.e. the value
of the system property user.dir ), then from the classpath.
This default template cache suits many applications.
|
TemplateCache | public TemplateCache(TemplateLoader loader)(Code) | | Creates a new template cache with a custom template loader that is used
to load the templates.
Parameters: loader - the template loader to use. |
TemplateCache | public TemplateCache(TemplateLoader loader, CacheStorage storage)(Code) | | Creates a new template cache with a custom template loader that is used
to load the templates.
Parameters: loader - the template loader to use. |
getDelay | public synchronized long getDelay()(Code) | | Gets the delay in milliseconds between checking for newer versions of a
template source.
the current value of the delay |
getLocalizedLookup | public synchronized boolean getLocalizedLookup()(Code) | | Returns if localized template lookup is enabled or not.
|
getTemplate | public Template getTemplate(String name, Locale locale, String encoding, boolean parse) throws IOException(Code) | | Loads a template with the given name, in the specified locale and
using the specified character encoding.
Parameters: name - the name of the template. Can't be null. The exact syntax of the nameis interpreted by the underlying TemplateLoader, but thecache makes some assumptions. First, the name is expected to bea hierarchical path, with path components separated by a slashcharacter (not with backslash!). The path (the name) must not begin with slash;the path is always relative to the "template root directory".Then, the .. and . path metaelements will be resolved.For example, if the name is a/../b/./c.ftl, then it will besimplified to b/c.ftl. The rules regarding this are same as with conventionalUN*X paths. The path must not reach outside the template root directory, that is,it can't be something like "../templates/my.ftl" (not even if the pervious pathhappens to be equivalent with "/my.ftl").Further, the path is allowed to contain at mostone path element whose name is * (asterisk). This path metaelement triggers theacquisition mechanism. If the template is not found inthe location described by the concatenation of the path left to theasterisk (called base path) and the part to the right of the asterisk(called resource path), the cache will attempt to remove the rightmostpath component from the base path ("go up one directory") and concatenatethat with the resource path. The process is repeated until either atemplate is found, or the base path is completely exhausted. Parameters: locale - the requested locale of the template. Can't be null.Assuming you have specified en_US as the locale andmyTemplate.html as the name of the template, the cache willfirst try to retrieve myTemplate_en_US.html , thenmyTemplate.html_en.html , and finallymyTemplate.html . Parameters: encoding - the character encoding used to interpret the templatesource bytes. Can't be null. Parameters: parse - if true, the loaded template is parsed and interpretedas a regular FreeMarker template. If false, the loaded template istreated as an unparsed block of text. the loaded template, or null if the template is not found. |
setConfiguration | public void setConfiguration(Configuration config)(Code) | | Sets the configuration object to which this cache belongs. This
method is called by the configuration itself to establish the
relation, and should not be called by users.
|
setDelay | public synchronized void setDelay(long delay)(Code) | | Sets the delay in milliseconds between checking for newer versions of a
template sources.
Parameters: delay - the new value of the delay |
setLocalizedLookup | public synchronized void setLocalizedLookup(boolean localizedLookup)(Code) | | Setis if localized template lookup is enabled or not.
|
|
|