KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > ui > velocity > VelocityEngineFactoryBean


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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"> &lt;bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"&gt;
39  * &lt;property name="resourceLoaderPath" value="/WEB-INF/velocity/"/&gt;
40  * &lt;/bean&gt;</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
56     public void afterPropertiesSet() throws IOException JavaDoc, VelocityException {
57         this.velocityEngine = createVelocityEngine();
58     }
59
60
61     public Object JavaDoc getObject() {
62         return this.velocityEngine;
63     }
64
65     public Class JavaDoc getObjectType() {
66         return VelocityEngine.class;
67     }
68
69     public boolean isSingleton() {
70         return true;
71     }
72
73 }
74
Popular Tags