Module net.shibboleth.ext.spring
Class VelocityConfigurer
- java.lang.Object
-
- net.shibboleth.ext.spring.velocity.VelocityEngineFactory
-
- net.shibboleth.ext.spring.velocity.VelocityConfigurer
-
- All Implemented Interfaces:
VelocityConfig,Aware,InitializingBean,ResourceLoaderAware,ServletContextAware
public class VelocityConfigurer extends VelocityEngineFactory implements VelocityConfig, InitializingBean, ResourceLoaderAware, ServletContextAware
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'sVelocityViewfor web MVC. It exists purely to configure Velocity; it is not meant to be referenced by application components (just internally by VelocityView). This class implementsVelocityConfigin order to be found by VelocityView without depending on the bean name of this configurer. Each DispatcherServlet may define its own VelocityConfigurer if desired, potentially with different template loader paths.Note that you can also refer to a pre-configured VelocityEngine instance via the "velocityEngine" property, e.g. set up by
VelocityEngineFactoryBean, This allows to share a VelocityEngine for web and email usage, for example.This configurer registers the "spring.vm" Velocimacro library for web views (contained in this package and thus in
spring.jar), which makes all of Spring's default Velocity macros available to the views. This allows for using the Spring-provided macros such as follows:#springBind("person.age") age is ${status.value}- Since:
- 6.0.0
-
-
Field Summary
Fields Modifier and Type Field Description private javax.servlet.ServletContextservletContextServlet context.private static StringSPRING_MACRO_LIBRARYName of Spring's default bind macro library.private static StringSPRING_MACRO_RESOURCE_LOADER_CLASSKey for the class of Spring's bind macro resource loader.private static StringSPRING_MACRO_RESOURCE_LOADER_NAMEName of the resource loader for Spring's bind macros.private org.apache.velocity.app.VelocityEnginevelocityEngineVelocity engine.
-
Constructor Summary
Constructors Constructor Description VelocityConfigurer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Initialize VelocityEngineFactory's VelocityEngine if not overridden by a pre-configured VelocityEngine.org.apache.velocity.app.VelocityEnginegetVelocityEngine()Return the VelocityEngine for the current web application context.protected voidpostProcessVelocityEngine(org.apache.velocity.app.VelocityEngine engine)Provides a ClasspathResourceLoader in addition to any default or user-defined loader in order to load the spring Velocity macros from the class path.voidsetServletContext(javax.servlet.ServletContext context)-
Methods inherited from class net.shibboleth.ext.spring.velocity.VelocityEngineFactory
createVelocityEngine, initSpringResourceLoader, initVelocityResourceLoader, newVelocityEngine, setConfigLocation, setPreferFileSystemAccess, setResourceLoader, setResourceLoaderPath, setVelocityProperties, setVelocityPropertiesMap
-
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
-
Methods inherited from interface org.springframework.web.context.ServletContextAware
setServletContext
-
-
-
-
Field Detail
-
SPRING_MACRO_RESOURCE_LOADER_NAME
private static final String SPRING_MACRO_RESOURCE_LOADER_NAME
Name of the resource loader for Spring's bind macros.- See Also:
- Constant Field Values
-
SPRING_MACRO_RESOURCE_LOADER_CLASS
private static final String SPRING_MACRO_RESOURCE_LOADER_CLASS
Key for the class of Spring's bind macro resource loader.- See Also:
- Constant Field Values
-
SPRING_MACRO_LIBRARY
private static final String SPRING_MACRO_LIBRARY
Name of Spring's default bind macro library.- See Also:
- Constant Field Values
-
servletContext
@Nullable private javax.servlet.ServletContext servletContext
Servlet context.
-
velocityEngine
@Nullable private org.apache.velocity.app.VelocityEngine velocityEngine
Velocity engine.
-
-
Method Detail
-
setServletContext
public void setServletContext(javax.servlet.ServletContext context)
-
afterPropertiesSet
public void afterPropertiesSet() throws IOException, org.apache.velocity.exception.VelocityExceptionInitialize VelocityEngineFactory's VelocityEngine if not overridden by a pre-configured VelocityEngine.- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
IOExceptionorg.apache.velocity.exception.VelocityException- See Also:
VelocityEngineFactory.createVelocityEngine()
-
postProcessVelocityEngine
protected void postProcessVelocityEngine(@Nonnull org.apache.velocity.app.VelocityEngine engine)Provides a ClasspathResourceLoader in addition to any default or user-defined loader in order to load the spring Velocity macros from the class path.- Overrides:
postProcessVelocityEnginein classVelocityEngineFactory- Parameters:
engine- the current VelocityEngine- See Also:
ClasspathResourceLoader
-
getVelocityEngine
public org.apache.velocity.app.VelocityEngine getVelocityEngine()
Return the VelocityEngine for the current web application context.May be unique to one servlet, or shared in the root context.
- Specified by:
getVelocityEnginein interfaceVelocityConfig- Returns:
- the VelocityEngine
-
-