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, setFreemarkerSettings, setFreemarkerVariables, setTemplateLoaderPath, createConfiguration, FreeMarkerConfigurationFactoryBean, org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer , freemarker.template.Configuration
| Modifier and Type | Field and Description |
|---|---|
| private Resource | |
| private String | |
| private Properties | |
| private Map | |
| protected final Log | |
| private List | |
| private boolean | |
| private List | |
| private ResourceLoader | |
| private String[] | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public freemarker. | Returns: the FreeMarker Configuration objectPrepare the FreeMarker Configuration and return it. |
| protected freemarker. | Returns: the aggregate TemplateLoaderthe final List of TemplateLoader instances templateLoadersReturn a TemplateLoader based on the given TemplateLoader list. |
| protected ResourceLoader | |
| protected freemarker. | Returns: an appropriate TemplateLoaderthe path to load templates from templateLoaderPath)Determine a FreeMarker TemplateLoader for the given path. |
| protected boolean | |
| protected freemarker. | |
| protected void | postProcessConfiguration(freemarker.
the current Configuration object configTo be overridden by subclasses that want to perform custom post-processing of the Configuration object after this factory performed its default initialization. |
| protected void | postProcessTemplateLoaders(List<freemarker.
the current List of TemplateLoader instances,
to be modified by a subclass templateLoadersTo be overridden by subclasses that want to register custom TemplateLoader instances after this factory created its default template loaders. |
| public void | |
| public void | setDefaultEncoding(String defaultEncoding)
Set the default encoding for the FreeMarker configuration. |
| public void | setFreemarkerSettings(Properties settings)
Set properties that contain well-known FreeMarker keys which will be
passed to FreeMarker's |
| public void | setFreemarkerVariables(Map<String, Object> variables)
Set a Map that contains well-known FreeMarker objects which will be passed
to FreeMarker's |
| public void | setPostTemplateLoaders(freemarker.
Set a List of |
| public void | setPreferFileSystemAccess(boolean preferFileSystemAccess)
Set whether to prefer file system access for template loading. |
| public void | setPreTemplateLoaders(freemarker.
Set a List of |
| public void | setResourceLoader(ResourceLoader resourceLoader)
Set the Spring ResourceLoader to use for loading FreeMarker template files. |
| public void | setTemplateLoaderPath(String templateLoaderPath)
Set the Freemarker template loader path via a Spring resource location. |
| public void | setTemplateLoaderPaths(String... templateLoaderPaths)
Set multiple Freemarker template loader paths via Spring resource locations. |
| configLocation | back to summary |
|---|---|
| private Resource configLocation
| |
| defaultEncoding | back to summary |
|---|---|
| private String defaultEncoding
| |
| freemarkerSettings | back to summary |
|---|---|
| private Properties freemarkerSettings
| |
| freemarkerVariables | back to summary |
|---|---|
| private Map<String, Object> freemarkerVariables
| |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| postTemplateLoaders | back to summary |
|---|---|
| private List<freemarker. | |
| preferFileSystemAccess | back to summary |
|---|---|
| private boolean preferFileSystemAccess | |
| preTemplateLoaders | back to summary |
|---|---|
| private List<freemarker. | |
| resourceLoader | back to summary |
|---|---|
| private ResourceLoader resourceLoader | |
| templateLoaderPaths | back to summary |
|---|---|
| private String[] templateLoaderPaths
| |
| templateLoaders | back to summary |
|---|---|
| private final List<freemarker. | |
| FreeMarkerConfigurationFactory | back to summary |
|---|---|
| public FreeMarkerConfigurationFactory() | |
| createConfiguration | back to summary |
|---|---|
| public freemarker. Prepare the FreeMarker Configuration and return it.
| |
| getAggregateTemplateLoader | back to summary |
|---|---|
| protected freemarker. Return a TemplateLoader based on the given TemplateLoader list. If more than one TemplateLoader has been registered, a FreeMarker MultiTemplateLoader needs to be created. | |
| getResourceLoader | back to summary |
|---|---|
| protected ResourceLoader getResourceLoader() Return the Spring ResourceLoader to use for loading FreeMarker template files. | |
| getTemplateLoaderForPath | back to summary |
|---|---|
| protected freemarker. Determine a FreeMarker TemplateLoader for the given path. Default implementation creates either a FileTemplateLoader or a SpringTemplateLoader.
| |
| isPreferFileSystemAccess | back to summary |
|---|---|
| protected boolean isPreferFileSystemAccess() Return whether to prefer file system access for template loading. | |
| newConfiguration | back to summary |
|---|---|
| protected freemarker. Return a new Configuration object. Subclasses can override this for custom initialization (e.g. specifying a FreeMarker compatibility level which is a new feature in FreeMarker 2.3.21), or for using a mock object for testing. Called by
| |
| postProcessConfiguration | back to summary |
|---|---|
| protected void postProcessConfiguration(freemarker. To be overridden by subclasses that want to perform custom post-processing of the Configuration object after this factory performed its default initialization. Called by
| |
| postProcessTemplateLoaders | back to summary |
|---|---|
| protected void postProcessTemplateLoaders(List<freemarker. To be overridden by subclasses that want to register custom TemplateLoader instances after this factory created its default template loaders. Called by
| |
| setConfigLocation | back to summary |
|---|---|
| public void setConfigLocation(Resource resource) Set the location of the FreeMarker config file. Alternatively, you can specify all setting locally.
| |
| setDefaultEncoding | back to summary |
|---|---|
| public void setDefaultEncoding(String defaultEncoding) Set the default encoding for the FreeMarker configuration. If not specified, FreeMarker will use the platform file encoding. Used for template rendering unless there is an explicit encoding specified for the rendering process (for example, on Spring's FreeMarkerView). | |
| setFreemarkerSettings | back to summary |
|---|---|
| public void setFreemarkerSettings(Properties settings) Set properties that contain well-known FreeMarker keys which will be
passed to FreeMarker's | |
| setFreemarkerVariables | back to summary |
|---|---|
| public void setFreemarkerVariables(Map<String, Object> variables) Set a Map that contains well-known FreeMarker objects which will be passed
to FreeMarker's | |
| setPostTemplateLoaders | back to summary |
|---|---|
| public void setPostTemplateLoaders(freemarker. Set a List of The | |
| setPreferFileSystemAccess | back to summary |
|---|---|
| public void setPreferFileSystemAccess(boolean preferFileSystemAccess) Set whether to prefer file system access for template loading. File system access enables hot detection of template changes. 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.
| |
| setPreTemplateLoaders | back to summary |
|---|---|
| public void setPreTemplateLoaders(freemarker. Set a List of The | |
| setResourceLoader | back to summary |
|---|---|
| public void setResourceLoader(ResourceLoader resourceLoader) Set the Spring ResourceLoader to use for loading FreeMarker template files. The default is DefaultResourceLoader. Will get overridden by the ApplicationContext if running in a context. | |
| setTemplateLoaderPath | back to summary |
|---|---|
| public void setTemplateLoaderPath(String templateLoaderPath) Set the Freemarker template loader path via a Spring resource location. See the "templateLoaderPaths" property for details on path handling.
| |
| setTemplateLoaderPaths | back to summary |
|---|---|
| public void setTemplateLoaderPaths(String... templateLoaderPaths) Set multiple Freemarker template loader paths via Spring resource locations. 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 a specified resource cannot be resolved to a 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. If you wish to specify your own list of TemplateLoaders, do not set this
property and instead use | |