org.springframework.ui.freemarker
Class FreeMarkerConfigurationFactory

java.lang.Object
  extended byorg.springframework.ui.freemarker.FreeMarkerConfigurationFactory
Direct Known Subclasses:
FreeMarkerConfigurationFactoryBean, FreeMarkerConfigurer

public class FreeMarkerConfigurationFactory
extends java.lang.Object

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.setSetting() 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 setSharedVariable() method. Like setSettings(), these entries are subject to FreeMarker constraints and may throw a FreemarkerInitializationException.

Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.

Since:
3/3/2004
Version:
$Id: FreeMarkerConfigurationFactory.java,v 1.1 2004/03/20 15:41:33 trisberg Exp $
Author:
Darren Davison, Juergen Hoeller
See Also:
setConfigLocation(org.springframework.core.io.Resource), setFreemarkerSettings(java.util.Properties), setFreemarkerVariables(java.util.Map), setTemplateLoaderPath(java.lang.String), createConfiguration()

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
FreeMarkerConfigurationFactory()
           
 
Method Summary
 freemarker.template.Configuration createConfiguration()
          Prepare the FreeMarker Configuration and return it.
protected  freemarker.template.Configuration newConfiguration()
          Return a new Configuration object.
protected  void postProcessConfiguration(freemarker.template.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(java.util.Properties settings)
          Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker's Configuration.setSettings method.
 void setFreemarkerVariables(java.util.Map variables)
          Set a Map that contains well-known FreeMarker objects which will be passed to FreeMarker's Configuration.setAllSharedVariables method.
 void setResourceLoader(ResourceLoader resourceLoader)
          Set the Spring ResourceLoader to use for loading FreeMarker template files.
 void setTemplateLoaderPath(java.lang.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

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

FreeMarkerConfigurationFactory

public FreeMarkerConfigurationFactory()
Method Detail

setConfigLocation

public void setConfigLocation(Resource resource)
Set the location of the FreeMarker config file. Alternatively, you can specify all setting locally.

See Also:
setFreemarkerSettings(java.util.Properties), setTemplateLoaderPath(java.lang.String)

setFreemarkerSettings

public void setFreemarkerSettings(java.util.Properties settings)
Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker's Configuration.setSettings method.

See Also:
Configurable.setSettings(java.util.Properties)

setFreemarkerVariables

public void setFreemarkerVariables(java.util.Map variables)
Set a Map that contains well-known FreeMarker objects which will be passed to FreeMarker's Configuration.setAllSharedVariables method.

See Also:
Configuration.setAllSharedVariables(freemarker.template.TemplateHashModelEx)

setTemplateLoaderPath

public void setTemplateLoaderPath(java.lang.String templateLoaderPath)
Set the Freemarker template loader path via a Spring resource location.

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, the generic SpringTemplateLoader will be used, without modification detection.

See Also:
ResourceEditor, ResourceLoader.getResource(java.lang.String), Configuration.setDirectoryForTemplateLoading(java.io.File), SpringTemplateLoader

setResourceLoader

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.

See Also:
DefaultResourceLoader

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 found
freemarker.template.TemplateException - on FreeMarker initialization failure

newConfiguration

protected freemarker.template.Configuration newConfiguration()
                                                      throws java.io.IOException,
                                                             freemarker.template.TemplateException
Return a new Configuration object. Subclasses can override this for custom initialization, or for using a mock object for testing. Called by createConfiguration.

Returns:
the Configuration object
Throws:
java.io.IOException - if a config file wasn't found
freemarker.template.TemplateException - on FreeMarker initialization failure
See Also:
createConfiguration()

postProcessConfiguration

protected void postProcessConfiguration(freemarker.template.Configuration config)
                                 throws java.io.IOException,
                                        freemarker.template.TemplateException
To be implemented by subclasses that want to to perform custom post-processing of the Configuration object after this FactoryBean performed its default initialization. Called by createConfiguration.

Parameters:
config - the current Configuration object
Throws:
java.io.IOException - if a config file wasn't found
freemarker.template.TemplateException - on FreeMarker initialization failure
See Also:
createConfiguration()


Copyright (C) 2003-2004 The Spring Framework Project.