org.springframework.web.servlet.view.velocity
Class VelocityConfigurer

java.lang.Object
  extended byorg.springframework.ui.velocity.VelocityEngineFactory
      extended byorg.springframework.web.servlet.view.velocity.VelocityConfigurer
All Implemented Interfaces:
InitializingBean, ResourceLoaderAware, VelocityConfig

public class VelocityConfigurer
extends VelocityEngineFactory
implements VelocityConfig, InitializingBean, ResourceLoaderAware

JavaBean to configure Velocity for web usage, via the "configLocation" and/or "velocityProperties" and/or "resourceLoaderPath" bean properties. The simplest way to use this class is to specify just a "resourceLoaderPath": You do not need any further configuration then.

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  <property name="resourceLoaderPath"><value>/WEB-INF/velocity/</value></property>
</bean>

This bean must be included in the application context of any application using Spring's VelocityView for web MVC. It exists purely to configure Velocity. It is not meant to be referenced by application components but just internally by VelocityView. Implements VelocityConfig to be found by VelocityView without depending on the bean name the configurer. Each DispatcherServlet can define its own VelocityConfigurer if desired.

Note that you can also refer to a preconfigured VelocityEngine instance, for example one set up by VelocityEngineFactoryBean, via the "velocityEngine" property. This allows to shared a VelocityEngine for web and email usage, for example.

Version:
$Id: VelocityConfigurer.java,v 1.13 2004/03/18 02:46:15 trisberg Exp $
Author:
Rod Johnson, Juergen Hoeller
See Also:
VelocityEngineFactory.setConfigLocation(org.springframework.core.io.Resource), VelocityEngineFactory.setVelocityProperties(java.util.Properties), VelocityEngineFactory.setResourceLoaderPath(java.lang.String), setVelocityEngine(org.apache.velocity.app.VelocityEngine), VelocityEngineFactoryBean, VelocityView

Field Summary
 
Fields inherited from class org.springframework.ui.velocity.VelocityEngineFactory
logger
 
Constructor Summary
VelocityConfigurer()
           
 
Method Summary
 void afterPropertiesSet()
          Initialize VelocityEngineFactory's VelocityEngine if not overridden by a preconfigured VelocityEngine.
 org.apache.velocity.app.VelocityEngine getVelocityEngine()
          Return the VelocityEngine for the current web application context.
 void setVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine)
          Set a preconfigured VelocityEngine to use for the Velocity web config, e.g.
 
Methods inherited from class org.springframework.ui.velocity.VelocityEngineFactory
createVelocityEngine, newVelocityEngine, postProcessVelocityEngine, setConfigLocation, setOverrideLogging, setResourceLoader, setResourceLoaderPath, setVelocityProperties
 
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

VelocityConfigurer

public VelocityConfigurer()
Method Detail

setVelocityEngine

public void setVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine)
Set a preconfigured VelocityEngine to use for the Velocity web config, e.g. a shared one for web and email usage, set up via VelocityEngineFactoryBean. If this is not set, VelocityEngineFactory's properties (inherited by this class) have to be specified.

See Also:
VelocityEngineFactoryBean

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.io.IOException,
                               org.apache.velocity.exception.VelocityException
Initialize VelocityEngineFactory's VelocityEngine if not overridden by a preconfigured VelocityEngine.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
java.io.IOException
org.apache.velocity.exception.VelocityException
See Also:
VelocityEngineFactory.createVelocityEngine(), setVelocityEngine(org.apache.velocity.app.VelocityEngine)

getVelocityEngine

public org.apache.velocity.app.VelocityEngine getVelocityEngine()
Description copied from interface: VelocityConfig
Return the VelocityEngine for the current web application context. May be unique to one servlet, or shared in the root context.

Specified by:
getVelocityEngine in interface VelocityConfig
Returns:
the VelocityEngine


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