|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
Factory that configures a FreeMarker Configuration. Can be used standalone, but typically you will either use FreeMarkerConfigurationFactoryBean for preparing a Configuration as bean reference, or FreeMarkerConfigurer for web views.
The optional "configLocation" property sets the location of a FreeMarker
properties file, within the current application. FreeMarker properties can be
overridden via "freemarkerSettings". All of these properties will be set by
calling FreeMarker's Configuration.setSettings()
method and are
subject to constraints set by FreeMarker.
The "freemarkerVariables" property can be used to specify a Map of
shared variables that will be applied to the Configuration via the
setAllSharedVariables()
method. Like setSettings()
,
these entries are subject to FreeMarker constraints.
The simplest way to use this class is to specify a "templateLoaderPath"; FreeMarker does not need any further configuration then.
Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.
setConfigLocation(org.springframework.core.io.Resource)
,
setFreemarkerSettings(java.util.Properties)
,
setFreemarkerVariables(java.util.Map)
,
setTemplateLoaderPath(java.lang.String)
,
createConfiguration()
Field Summary | |
protected Log |
logger
|
Constructor Summary | |
FreeMarkerConfigurationFactory()
|
Method Summary | |
Configuration |
createConfiguration()
Prepare the FreeMarker Configuration and return it. |
protected Configuration |
newConfiguration()
Return a new Configuration object. |
protected void |
postProcessConfiguration(Configuration config)
To be implemented by subclasses that want to to perform custom post-processing of the Configuration object after this FactoryBean performed its default initialization. |
void |
setConfigLocation(Resource resource)
Set the location of the FreeMarker config file. |
void |
setFreemarkerSettings(Properties settings)
Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker's Configuration.setSettings method. |
void |
setFreemarkerVariables(Map variables)
Set a Map that contains well-known FreeMarker objects which will be passed to FreeMarker's Configuration.setAllSharedVariables() method. |
void |
setPreferFileSystemAccess(boolean preferFileSystemAccess)
Set whether to prefer file system access for template loading. |
void |
setResourceLoader(ResourceLoader resourceLoader)
Set the Spring ResourceLoader to use for loading FreeMarker template files. |
void |
setTemplateLoaderPath(String templateLoaderPath)
Set the Freemarker template loader path via a Spring resource location. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final Log logger
Constructor Detail |
public FreeMarkerConfigurationFactory()
Method Detail |
public void setConfigLocation(Resource resource)
setFreemarkerSettings(java.util.Properties)
,
setTemplateLoaderPath(java.lang.String)
public void setFreemarkerSettings(Properties settings)
Configuration.setSettings
method.
Configurable.setSettings(java.util.Properties)
public void setFreemarkerVariables(Map variables)
Configuration.setAllSharedVariables()
method.
Configuration.setAllSharedVariables(freemarker.template.TemplateHashModelEx)
public void setTemplateLoaderPath(String templateLoaderPath)
When populated via a String, standard URLs like "file:" and "classpath:" pseudo URLs are supported, as understood by ResourceEditor. Allows for relative paths when running in an ApplicationContext.
Will define a path for the default FreeMarker template loader. If the specified resource cannot be resolved to a java.io.File, a generic SpringTemplateLoader will be used, without modification detection.
To enforce the use of SpringTemplateLoader, i.e. to not resolve a path as file system resource in any case, turn off the "preferFileSystemAccess" flag. See the latter's javadoc for details.
ResourceEditor
,
ResourceLoader.getResource(java.lang.String)
,
Configuration.setDirectoryForTemplateLoading(java.io.File)
,
SpringTemplateLoader
public void setResourceLoader(ResourceLoader resourceLoader)
DefaultResourceLoader
public void setPreferFileSystemAccess(boolean preferFileSystemAccess)
If this is enabled, FreeMarkerConfigurationFactory will try to resolve the specified "templateLoaderPath" as file system resource (which will work for expanded class path resources and ServletContext resources too).
Default is true. Turn this off to always load via SpringTemplateLoader (i.e. as stream, without hot detection of template changes), which might be necessary if some of your templates reside in an expanded classes directory while others reside in jar files.
setTemplateLoaderPath(java.lang.String)
public Configuration createConfiguration() throws IOException, TemplateException
IOException
- if the config file wasn't found
TemplateException
- on FreeMarker initialization failureprotected Configuration newConfiguration() throws IOException, TemplateException
IOException
- if a config file wasn't found
TemplateException
- on FreeMarker initialization failurecreateConfiguration()
protected void postProcessConfiguration(Configuration config) throws IOException, TemplateException
config
- the current Configuration object
IOException
- if a config file wasn't found
TemplateException
- on FreeMarker initialization failurecreateConfiguration()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |