Package com.aspectran.freemarker
Class FreeMarkerConfigurationFactory
java.lang.Object
com.aspectran.freemarker.FreeMarkerConfigurationFactory
- All Implemented Interfaces:
ActivityContextAware
,Aware
- Direct Known Subclasses:
FreeMarkerConfigurationFactoryBean
Factory that configures a FreeMarker Configuration.
Created: 2016. 1. 9.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfreemarker.template.Configuration
Prepare the FreeMarker Configuration and return it.protected freemarker.cache.TemplateLoader
getAggregateTemplateLoader
(freemarker.cache.TemplateLoader[] templateLoaders) Return a TemplateLoader based on the given TemplateLoader list.protected freemarker.cache.TemplateLoader
getTemplateLoaderForPath
(String templateLoaderPath) Determine a FreeMarker TemplateLoader for the given path.protected freemarker.template.Configuration
Return a new Configuration object.void
setActivityContext
(ActivityContext context) void
setConfigLocation
(String configLocation) Set the location of the Freemarker settings file.void
setDefaultEncoding
(String defaultEncoding) Set the default encoding for the FreeMarker configuration.void
setFreemarkerSettings
(Properties settings) Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker'sConfiguration.setSettings
method.void
setFreemarkerVariables
(Map<String, Object> variables) Set a Map that contains well-known FreeMarker objects which will be passed to FreeMarker'sConfiguration.setAllSharedVariables()
method.void
setTemplateLoader
(freemarker.cache.TemplateLoader templateLoader) Set a TemplateLoader that will be used to search for templates.void
setTemplateLoader
(freemarker.cache.TemplateLoader... templateLoaders) Set multiple TemplateLoaders that will be used to search for templates.void
setTemplateLoader
(List<freemarker.cache.TemplateLoader> templateLoaderList) Set a List of TemplateLoaders that will be used to search for templates.void
setTemplateLoaderPath
(String templateLoaderPath) Set the Freemarker template loader path.void
setTemplateLoaderPath
(String... templateLoaderPaths) Set multiple Freemarker template loader paths.void
setTemplateLoaderPath
(List<String> templateLoaderPathList) Set a List of Freemarker template loader paths.void
setTrimDirectives
(TrimDirective... trimDirectives) void
setTrimDirectives
(Parameters parameters)
-
Constructor Details
-
FreeMarkerConfigurationFactory
public FreeMarkerConfigurationFactory()
-
-
Method Details
-
setActivityContext
- Specified by:
setActivityContext
in interfaceActivityContextAware
-
setConfigLocation
Set the location of the Freemarker settings file. Alternatively, you can specify all properties locally. -
setFreemarkerSettings
Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker'sConfiguration.setSettings
method.- Parameters:
settings
- the settings- See Also:
-
freemarker.template.Configuration#setSettings
-
setFreemarkerVariables
Set a Map that contains well-known FreeMarker objects which will be passed to FreeMarker'sConfiguration.setAllSharedVariables()
method.- Parameters:
variables
- the variables- See Also:
-
freemarker.template.Configuration#setAllSharedVariables
-
setDefaultEncoding
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).
- Parameters:
defaultEncoding
- the default encoding- See Also:
-
freemarker.template.Configuration#setDefaultEncoding
-
setTemplateLoaderPath
Set the Freemarker template loader path.- Parameters:
templateLoaderPath
- the Freemarker template loader path
-
setTemplateLoaderPath
Set multiple Freemarker template loader paths.- Parameters:
templateLoaderPaths
- the multiple Freemarker template loader paths
-
setTemplateLoaderPath
Set a List of Freemarker template loader paths.- Parameters:
templateLoaderPathList
- a List of Freemarker template loader paths
-
setTemplateLoader
public void setTemplateLoader(freemarker.cache.TemplateLoader templateLoader) Set a TemplateLoader that will be used to search for templates.- Parameters:
templateLoader
- the template loader
-
setTemplateLoader
public void setTemplateLoader(freemarker.cache.TemplateLoader... templateLoaders) Set multiple TemplateLoaders that will be used to search for templates.- Parameters:
templateLoaders
- the multiple TemplateLoaders
-
setTemplateLoader
Set a List of TemplateLoaders that will be used to search for templates.- Parameters:
templateLoaderList
- a List of TemplateLoaders
-
setTrimDirectives
-
setTrimDirectives
-
createConfiguration
public freemarker.template.Configuration createConfiguration() throws IOException, freemarker.template.TemplateExceptionPrepare the FreeMarker Configuration and return it.- Returns:
- the FreeMarker Configuration object
- Throws:
IOException
- if the config file wasn't foundfreemarker.template.TemplateException
- on FreeMarker initialization failure
-
newConfiguration
protected freemarker.template.Configuration newConfiguration()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
createConfiguration()
.- Returns:
- the Configuration object
-
getAggregateTemplateLoader
protected freemarker.cache.TemplateLoader getAggregateTemplateLoader(freemarker.cache.TemplateLoader[] templateLoaders) Return a TemplateLoader based on the given TemplateLoader list. If more than one TemplateLoader has been registered, a FreeMarker MultiTemplateLoader needs to be created.- Parameters:
templateLoaders
- the final List of TemplateLoader instances- Returns:
- the aggregate TemplateLoader
-
getTemplateLoaderForPath
protected freemarker.cache.TemplateLoader getTemplateLoaderForPath(@NonNull String templateLoaderPath) throws IOException Determine a FreeMarker TemplateLoader for the given path.- Parameters:
templateLoaderPath
- the path to load templates from- Returns:
- an appropriate TemplateLoader
- Throws:
IOException
- if an I/O error has occurred- See Also:
-
FileTemplateLoader
-