01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.ui.velocity;
18:
19: import java.io.IOException;
20:
21: import org.apache.velocity.app.VelocityEngine;
22: import org.apache.velocity.exception.VelocityException;
23:
24: import org.springframework.beans.factory.FactoryBean;
25: import org.springframework.beans.factory.InitializingBean;
26: import org.springframework.context.ResourceLoaderAware;
27:
28: /**
29: * Factory bean that configures a VelocityEngine and provides it as bean
30: * reference. This bean is intended for any kind of usage of Velocity in
31: * application code, e.g. for generating email content. For web views,
32: * VelocityConfigurer is used to set up a VelocityEngine for views.
33: *
34: * <p>The simplest way to use this class is to specify a "resourceLoaderPath";
35: * you do not need any further configuration then. For example, in a web
36: * application context:
37: *
38: * <pre class="code"> <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
39: * <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
40: * </bean></pre>
41: *
42: * See the base class VelocityEngineFactory for configuration details.
43: *
44: * @author Juergen Hoeller
45: * @see #setConfigLocation
46: * @see #setVelocityProperties
47: * @see #setResourceLoaderPath
48: * @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
49: */
50: public class VelocityEngineFactoryBean extends VelocityEngineFactory
51: implements FactoryBean, InitializingBean, ResourceLoaderAware {
52:
53: private VelocityEngine velocityEngine;
54:
55: public void afterPropertiesSet() throws IOException,
56: VelocityException {
57: this .velocityEngine = createVelocityEngine();
58: }
59:
60: public Object getObject() {
61: return this .velocityEngine;
62: }
63:
64: public Class getObjectType() {
65: return VelocityEngine.class;
66: }
67:
68: public boolean isSingleton() {
69: return true;
70: }
71:
72: }
|