KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > ui > freemarker > FreeMarkerConfigurationFactoryBean


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.freemarker;
18
19 import java.io.IOException JavaDoc;
20
21 import freemarker.template.Configuration;
22 import freemarker.template.TemplateException;
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 creates a FreeMarker Configuration and provides it as
30  * bean reference. This bean is intended for any kind of usage of FreeMarker
31  * in application code, e.g. for generating email content. For web views,
32  * FreeMarkerConfigurer is used to set up a FreeMarkerConfigurationFactory.
33  *
34  * The simplest way to use this class is to specify just a "templateLoaderPath";
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="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean"&gt;
39  * &lt;property name="templateLoaderPath" value="/WEB-INF/freemarker/"/&gt;
40  * &lt;/bean&gt;</pre>
41
42  * See the base class FreeMarkerConfigurationFactory for configuration details.
43  *
44  * <p>Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.
45  *
46  * @author Darren Davison
47  * @since 03.03.2004
48  * @see #setConfigLocation
49  * @see #setFreemarkerSettings
50  * @see #setTemplateLoaderPath
51  * @see org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
52  */

53 public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationFactory
54         implements FactoryBean, InitializingBean, ResourceLoaderAware {
55
56     private Configuration configuration;
57
58
59     public void afterPropertiesSet() throws IOException JavaDoc, TemplateException {
60         this.configuration = createConfiguration();
61     }
62
63
64     public Object JavaDoc getObject() {
65         return this.configuration;
66     }
67
68     public Class JavaDoc getObjectType() {
69         return Configuration.class;
70     }
71
72     public boolean isSingleton() {
73         return true;
74     }
75
76 }
77
Popular Tags