站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

FreeMarkerConfigurer (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.web.servlet.view.freemarker
Class FreeMarkerConfigurer

java.lang.Object
  extended by org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
      extended by org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
All Implemented Interfaces:
InitializingBean, ResourceLoaderAware, ServletContextAware, FreeMarkerConfig

public class FreeMarkerConfigurer
extends FreeMarkerConfigurationFactory
implements FreeMarkerConfig, InitializingBean, ResourceLoaderAware, ServletContextAware

JavaBean to configure FreeMarker for web usage, via the "configLocation" and/or "freemarkerSettings" and/or "templateLoaderPath" properties. The simplest way to use this class is to specify just a "templateLoaderPath"; you do not need any further configuration then.

 <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
   <property name="templateLoaderPath"><value>/WEB-INF/freemarker/</value></property>
 </bean>
This bean must be included in the application context of any application using Spring's FreeMarkerView for web MVC. It exists purely to configure FreeMarker. It is not meant to be referenced by application components but just internally by FreeMarkerView. Implements FreeMarkerConfig to be found by FreeMarkerView without depending on the bean name the configurer. Each DispatcherServlet can define its own FreeMarkerConfigurer if desired.

Note that you can also refer to a preconfigured FreeMarker Configuration instance, for example one set up by FreeMarkerConfigurationFactoryBean, via the "configuration" property. This allows to share a FreeMarker Configuration for web and email usage, for example.

This configurer registers a template loader for this package, allowing to reference the "spring.ftl" macro library (contained in this package and thus in spring.jar) like this:

 <#import "spring.ftl" as spring/>
 <@spring.bind "person.age"/>
 age is ${spring.status.value}
Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.

Since:
03.03.2004
Author:
Darren Davison, Rob Harrop
See Also:
FreeMarkerConfigurationFactory.setConfigLocation(org.springframework.core.io.Resource), FreeMarkerConfigurationFactory.setFreemarkerSettings(java.util.Properties), FreeMarkerConfigurationFactory.setTemplateLoaderPath(java.lang.String), setConfiguration(freemarker.template.Configuration), FreeMarkerConfigurationFactoryBean, FreeMarkerView

Field Summary
 
Fields inherited from class org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
logger
 
Constructor Summary
FreeMarkerConfigurer()
           
 
Method Summary
 void afterPropertiesSet()
          Initialize FreeMarkerConfigurationFactory's Configuration if not overridden by a preconfigured FreeMarker Configuation.
 Configuration getConfiguration()
          Return the Configuration object wrapped by this bean.
 TaglibFactory getTaglibFactory()
          Return the TaglibFactory object wrapped by this bean.
protected  void postProcessTemplateLoaders(List templateLoaders)
          This implementation registers an additional ClassTemplateLoader for the Spring-provided macros, added to the end of the list.
 void setConfiguration(Configuration configuration)
          Set a preconfigured Configuration to use for the FreeMarker web config, e.g. a shared one for web and email usage, set up via FreeMarkerConfigurationFactoryBean.
 void setServletContext(ServletContext servletContext)
          Initialize the TaglibFactory for the given ServletContext.
 
Methods inherited from class org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
createConfiguration, getAggregateTemplateLoader, getResourceLoader, getTemplateLoaderForPath, isPreferFileSystemAccess, newConfiguration, postProcessConfiguration, setConfigLocation, setDefaultEncoding, setFreemarkerSettings, setFreemarkerVariables, setPostTemplateLoaders, setPreferFileSystemAccess, setPreTemplateLoaders, setResourceLoader, setTemplateLoaderPath, setTemplateLoaderPaths, setTemplateLoaders
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.context.ResourceLoaderAware
setResourceLoader
 

Constructor Detail

FreeMarkerConfigurer

public FreeMarkerConfigurer()
Method Detail

setConfiguration

public void setConfiguration(Configuration configuration)
Set a preconfigured Configuration to use for the FreeMarker web config, e.g. a shared one for web and email usage, set up via FreeMarkerConfigurationFactoryBean. If this is not set, FreeMarkerConfigurationFactory's properties (inherited by this class) have to be specified.

See Also:
FreeMarkerConfigurationFactoryBean

setServletContext

public void setServletContext(ServletContext servletContext)
Initialize the TaglibFactory for the given ServletContext.

Specified by:
setServletContext in interface ServletContextAware
Parameters:
servletContext - ServletContext object to be used by this object
See Also:
InitializingBean.afterPropertiesSet(), ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)

afterPropertiesSet

public void afterPropertiesSet()
                        throws IOException,
                               TemplateException
Initialize FreeMarkerConfigurationFactory's Configuration if not overridden by a preconfigured FreeMarker Configuation.

Sets up a ClassTemplateLoader to use for loading Spring macros.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
IOException
TemplateException
See Also:
FreeMarkerConfigurationFactory.createConfiguration(), setConfiguration(freemarker.template.Configuration)

postProcessTemplateLoaders

protected void postProcessTemplateLoaders(List templateLoaders)
This implementation registers an additional ClassTemplateLoader for the Spring-provided macros, added to the end of the list.

Overrides:
postProcessTemplateLoaders in class FreeMarkerConfigurationFactory
Parameters:
templateLoaders - the current List of TemplateLoader instances, to be modified by a subclass
See Also:
FreeMarkerConfigurationFactory.createConfiguration(), FreeMarkerConfigurationFactory.setPostTemplateLoaders(freemarker.cache.TemplateLoader[])

getConfiguration

public Configuration getConfiguration()
Return the Configuration object wrapped by this bean.

Specified by:
getConfiguration in interface FreeMarkerConfig
Returns:
the FreeMarker Configuration

getTaglibFactory

public TaglibFactory getTaglibFactory()
Return the TaglibFactory object wrapped by this bean.

Specified by:
getTaglibFactory in interface FreeMarkerConfig

The Spring Framework

Copyright © 2002-2007 The Spring Framework.