Package com.aspectran.freemarker
Class FreeMarkerConfigurationFactory
- java.lang.Object
-
- com.aspectran.freemarker.FreeMarkerConfigurationFactory
-
- All Implemented Interfaces:
ApplicationAdapterAware
,Aware
- Direct Known Subclasses:
FreeMarkerConfigurationFactoryBean
public class FreeMarkerConfigurationFactory extends java.lang.Object implements ApplicationAdapterAware
Factory that configures a FreeMarker Configuration.Created: 2016. 1. 9.
-
-
Constructor Summary
Constructors Constructor Description FreeMarkerConfigurationFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description freemarker.template.Configuration
createConfiguration()
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(java.lang.String templateLoaderPath)
Determine a FreeMarker TemplateLoader for the given path.protected freemarker.template.Configuration
newConfiguration()
Return a new Configuration object.void
setApplicationAdapter(ApplicationAdapter applicationAdapter)
void
setConfigLocation(java.lang.String configLocation)
Set the location of the Freemarker settings file.void
setDefaultEncoding(java.lang.String defaultEncoding)
Set the default encoding for the FreeMarker configuration.void
setFreemarkerSettings(java.util.Properties settings)
Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker'sConfiguration.setSettings
method.void
setFreemarkerVariables(java.util.Map<java.lang.String,java.lang.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(java.util.List<freemarker.cache.TemplateLoader> templateLoaderList)
Set a List of TemplateLoaders that will be used to search for templates.void
setTemplateLoaderPath(java.lang.String templateLoaderPath)
Set the Freemarker template loader path.void
setTemplateLoaderPath(java.lang.String... templateLoaderPaths)
Set multiple Freemarker template loader paths.void
setTemplateLoaderPath(java.util.List<java.lang.String> templateLoaderPathList)
Set a List of Freemarker template loader paths.void
setTrimDirectives(Parameters parameters)
void
setTrimDirectives(TrimDirective... trimDirectives)
-
-
-
Method Detail
-
setApplicationAdapter
public void setApplicationAdapter(ApplicationAdapter applicationAdapter)
- Specified by:
setApplicationAdapter
in interfaceApplicationAdapterAware
-
setConfigLocation
public void setConfigLocation(java.lang.String configLocation)
Set the location of the Freemarker settings file. Alternatively, you can specify all properties locally.
-
setFreemarkerSettings
public void setFreemarkerSettings(java.util.Properties settings)
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
public void setFreemarkerVariables(java.util.Map<java.lang.String,java.lang.Object> variables)
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
public void setDefaultEncoding(java.lang.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).
- Parameters:
defaultEncoding
- the default encoding- See Also:
freemarker.template.Configuration#setDefaultEncoding
-
setTemplateLoaderPath
public void setTemplateLoaderPath(java.lang.String templateLoaderPath)
Set the Freemarker template loader path.- Parameters:
templateLoaderPath
- the Freemarker template loader path
-
setTemplateLoaderPath
public void setTemplateLoaderPath(java.lang.String... templateLoaderPaths)
Set multiple Freemarker template loader paths.- Parameters:
templateLoaderPaths
- the multiple Freemarker template loader paths
-
setTemplateLoaderPath
public void setTemplateLoaderPath(java.util.List<java.lang.String> templateLoaderPathList)
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
public void setTemplateLoader(java.util.List<freemarker.cache.TemplateLoader> templateLoaderList)
Set a List of TemplateLoaders that will be used to search for templates.- Parameters:
templateLoaderList
- a List of TemplateLoaders
-
setTrimDirectives
public void setTrimDirectives(TrimDirective... trimDirectives)
-
setTrimDirectives
public void setTrimDirectives(Parameters parameters)
-
createConfiguration
public freemarker.template.Configuration createConfiguration() throws java.io.IOException, freemarker.template.TemplateException
Prepare the FreeMarker Configuration and return it.- Returns:
- the FreeMarker Configuration object
- Throws:
java.io.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(java.lang.String templateLoaderPath) throws java.io.IOException
Determine a FreeMarker TemplateLoader for the given path.- Parameters:
templateLoaderPath
- the path to load templates from- Returns:
- an appropriate TemplateLoader
- Throws:
java.io.IOException
- if an I/O error has occurred- See Also:
FileTemplateLoader
-
-