Source Code Cross Referenced for FreeMarkerConfigurer.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » view » freemarker » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.servlet.view.freemarker 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.servlet.view.freemarker;
018:
019:        import java.io.IOException;
020:        import java.util.List;
021:
022:        import javax.servlet.ServletContext;
023:
024:        import freemarker.cache.ClassTemplateLoader;
025:        import freemarker.ext.jsp.TaglibFactory;
026:        import freemarker.template.Configuration;
027:        import freemarker.template.TemplateException;
028:
029:        import org.springframework.beans.factory.InitializingBean;
030:        import org.springframework.context.ResourceLoaderAware;
031:        import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory;
032:        import org.springframework.web.context.ServletContextAware;
033:
034:        /**
035:         * JavaBean to configure FreeMarker for web usage, via the "configLocation"
036:         * and/or "freemarkerSettings" and/or "templateLoaderPath" properties.
037:         * The simplest way to use this class is to specify just a "templateLoaderPath";
038:         * you do not need any further configuration then.
039:         *
040:         * <pre>
041:         * &lt;bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"&gt;
042:         *   &lt;property name="templateLoaderPath"&gt;&lt;value&gt;/WEB-INF/freemarker/&lt;/value>&lt;/property&gt;
043:         * &lt;/bean&gt;</pre>
044:         *
045:         * This bean must be included in the application context of any application
046:         * using Spring's FreeMarkerView for web MVC. It exists purely to configure FreeMarker.
047:         * It is not meant to be referenced by application components but just internally
048:         * by FreeMarkerView. Implements FreeMarkerConfig to be found by FreeMarkerView without
049:         * depending on the bean name the configurer. Each DispatcherServlet can define its
050:         * own FreeMarkerConfigurer if desired.
051:         *
052:         * <p>Note that you can also refer to a preconfigured FreeMarker Configuration
053:         * instance, for example one set up by FreeMarkerConfigurationFactoryBean, via
054:         * the "configuration" property. This allows to share a FreeMarker Configuration
055:         * for web and email usage, for example.
056:         *
057:         * <p>This configurer registers a template loader for this package, allowing to
058:         * reference the "spring.ftl" macro library (contained in this package and thus
059:         * in spring.jar) like this:
060:         *
061:         * <pre>
062:         * &lt;#import "spring.ftl" as spring/&gt;
063:         * &lt;@spring.bind "person.age"/&gt;
064:         * age is ${spring.status.value}</pre>
065:         *
066:         * Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.
067:         *
068:         * @author Darren Davison
069:         * @author Rob Harrop
070:         * @since 03.03.2004
071:         * @see #setConfigLocation
072:         * @see #setFreemarkerSettings
073:         * @see #setTemplateLoaderPath
074:         * @see #setConfiguration
075:         * @see org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean
076:         * @see FreeMarkerView
077:         */
078:        public class FreeMarkerConfigurer extends
079:                FreeMarkerConfigurationFactory implements  FreeMarkerConfig,
080:                InitializingBean, ResourceLoaderAware, ServletContextAware {
081:
082:            private Configuration configuration;
083:
084:            private TaglibFactory taglibFactory;
085:
086:            /**
087:             * Set a preconfigured Configuration to use for the FreeMarker web config, e.g. a
088:             * shared one for web and email usage, set up via FreeMarkerConfigurationFactoryBean.
089:             * If this is not set, FreeMarkerConfigurationFactory's properties (inherited by
090:             * this class) have to be specified.
091:             * @see org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean
092:             */
093:            public void setConfiguration(Configuration configuration) {
094:                this .configuration = configuration;
095:            }
096:
097:            /**
098:             * Initialize the {@link TaglibFactory} for the given ServletContext.
099:             */
100:            public void setServletContext(ServletContext servletContext) {
101:                this .taglibFactory = new TaglibFactory(servletContext);
102:            }
103:
104:            /**
105:             * Initialize FreeMarkerConfigurationFactory's Configuration
106:             * if not overridden by a preconfigured FreeMarker Configuation.
107:             * <p>Sets up a ClassTemplateLoader to use for loading Spring macros.
108:             * @see #createConfiguration
109:             * @see #setConfiguration
110:             */
111:            public void afterPropertiesSet() throws IOException,
112:                    TemplateException {
113:                if (this .configuration == null) {
114:                    this .configuration = createConfiguration();
115:                }
116:            }
117:
118:            /**
119:             * This implementation registers an additional ClassTemplateLoader
120:             * for the Spring-provided macros, added to the end of the list.
121:             */
122:            protected void postProcessTemplateLoaders(List templateLoaders) {
123:                templateLoaders.add(new ClassTemplateLoader(
124:                        FreeMarkerConfigurer.class, ""));
125:                logger
126:                        .info("ClassTemplateLoader for Spring macros added to FreeMarker configuration");
127:            }
128:
129:            /**
130:             * Return the Configuration object wrapped by this bean.
131:             */
132:            public Configuration getConfiguration() {
133:                return this .configuration;
134:            }
135:
136:            /**
137:             * Return the TaglibFactory object wrapped by this bean.
138:             */
139:            public TaglibFactory getTaglibFactory() {
140:                return this.taglibFactory;
141:            }
142:
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.