View Javadoc

1   /***
2    * @(#)VelocityServiceImpl.java
3    * 
4    * JFoxSOAF, Service-Oriented Application Framework
5    * 
6    * Copyright(c) JFoxSOAF Team
7    * 
8    * Licensed under the GNU LGPL, Version 2.1 (the "License"); 
9    * you may not use this file except in compliance with the License. 
10   * You may obtain a copy of the License at  
11   * 
12   * http://www.gnu.org/copyleft/lesser.html
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, 
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17   * See the License for the specific language governing permissions and 
18   * limitations under the License. 
19   * 
20   * For more information, please visit:
21   * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22   * http://www.huihoo.org/jfox/jfoxsoaf
23   */
24  
25  package org.huihoo.jfox.soaf.services.useraccess.velocity;
26  
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.apache.velocity.Template;
30  import org.apache.velocity.app.Velocity;
31  import org.picocontainer.Startable;
32  
33  /***
34   * <p>
35   * Velocity Service implementation.
36   * </p>
37   * 
38   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
39   * @version $Revision: 1.1 $ $Date: 2006/02/31 15:23:45 $
40   * @version Revision: 1.0
41   */
42  
43  public class VelocityServiceImpl implements Startable {
44  	
45  	private static String VELOCITY_CONFIG = "velocity.properties";
46  	
47  	private final Log log = LogFactory.getLog(getClass());
48  	
49  	/***
50  	 * Obtain velocity template
51  	 * 
52  	 * @param templateFile
53  	 * @return Template
54  	 * @throws Exception
55  	 */
56  	public Template getTemplate(String templateFile) throws Exception {		
57  		return Velocity.getTemplate(templateFile);
58      }
59  	
60  	/***
61  	 * Obtain velocity template with encoding.
62  	 * 
63  	 * @param templateFile
64  	 * @param encoding
65  	 * @return Template
66  	 * @throws Exception
67  	 */
68  	public Template getTemplate(String templateFile, String encoding) throws Exception {		
69  		return Velocity.getTemplate(templateFile);
70      }
71  	
72  	/***
73  	 * Init velocity template engine
74  	 * 
75  	 * @see org.picocontainer.Startable#start()
76  	 */
77  	public void start() {
78  		try {
79  			Velocity.init(VELOCITY_CONFIG);
80  		} catch (Exception e) {
81  			log.error("Init velocity failed, please check velocity.properties ");
82  		}
83  	}
84  	
85  	/***
86  	 * @see org.picocontainer.Startable#stop()
87  	 */
88  	public void stop() {
89      }
90  }