Source Code Cross Referenced for VelocityConfigurer.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » view » velocity » 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.velocity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2005 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.velocity;
018:
019:        import java.io.IOException;
020:
021:        import org.apache.velocity.app.VelocityEngine;
022:        import org.apache.velocity.exception.VelocityException;
023:        import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
024:
025:        import org.springframework.beans.factory.InitializingBean;
026:        import org.springframework.context.ResourceLoaderAware;
027:        import org.springframework.ui.velocity.VelocityEngineFactory;
028:
029:        /**
030:         * JavaBean to configure Velocity for web usage, via the "configLocation"
031:         * and/or "velocityProperties" and/or "resourceLoaderPath" bean properties.
032:         * The simplest way to use this class is to specify just a "resourceLoaderPath";
033:         * you do not need any further configuration then.
034:         *
035:         * <pre>
036:         * &lt;bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"&gt;
037:         *   &lt;property name="resourceLoaderPath">&lt;value&gt;/WEB-INF/velocity/&lt;/value>&lt;/property&gt;
038:         * &lt;/bean&gt;</pre>
039:         *
040:         * This bean must be included in the application context of any application
041:         * using Spring's VelocityView for web MVC. It exists purely to configure Velocity;
042:         * it is not meant to be referenced by application components but just internally
043:         * by VelocityView. Implements VelocityConfig to be found by VelocityView without
044:         * depending on the bean name of the configurer. Each DispatcherServlet can define
045:         * its own VelocityConfigurer if desired.
046:         *
047:         * <p>Note that you can also refer to a preconfigured VelocityEngine instance, for
048:         * example one set up by VelocityEngineFactoryBean, via the "velocityEngine" property.
049:         * This allows to share a VelocityEngine for web and email usage, for example.
050:         *
051:         * <p>This configurer registers the "spring.vm" Velocimacro library for web views
052:         * (contained in this package and thus in spring.jar), which makes all macros
053:         * defined in it implicitly available:
054:         *
055:         * <pre>
056:         * #springBind("person.age")
057:         * age is ${status.value}</pre>
058:         *
059:         * @author Rod Johnson
060:         * @author Juergen Hoeller
061:         * @author Darren Davison
062:         * @see #setConfigLocation
063:         * @see #setVelocityProperties
064:         * @see #setResourceLoaderPath
065:         * @see #setVelocityEngine
066:         * @see org.springframework.ui.velocity.VelocityEngineFactoryBean
067:         * @see VelocityView
068:         */
069:        public class VelocityConfigurer extends VelocityEngineFactory implements 
070:                VelocityConfig, InitializingBean, ResourceLoaderAware {
071:
072:            /** the name of the resource loader for Spring's bind macros */
073:            private static final String SPRING_MACRO_RESOURCE_LOADER_NAME = "springMacro";
074:
075:            /** the key for the class of Spring's bind macro resource loader */
076:            private static final String SPRING_MACRO_RESOURCE_LOADER_CLASS = "springMacro.resource.loader.class";
077:
078:            /** the name of Spring's default bind macro library */
079:            private static final String SPRING_MACRO_LIBRARY = "org/springframework/web/servlet/view/velocity/spring.vm";
080:
081:            private VelocityEngine velocityEngine;
082:
083:            /**
084:             * Set a preconfigured VelocityEngine to use for the Velocity web config, e.g.
085:             * a shared one for web and email usage, set up via VelocityEngineFactoryBean.
086:             * If this is not set, VelocityEngineFactory's properties (inherited by this
087:             * class) have to be specified.
088:             * @see org.springframework.ui.velocity.VelocityEngineFactoryBean
089:             */
090:            public void setVelocityEngine(VelocityEngine velocityEngine) {
091:                this .velocityEngine = velocityEngine;
092:            }
093:
094:            /**
095:             * Initialize VelocityEngineFactory's VelocityEngine
096:             * if not overridden by a preconfigured VelocityEngine.
097:             * @see #createVelocityEngine
098:             * @see #setVelocityEngine
099:             */
100:            public void afterPropertiesSet() throws IOException,
101:                    VelocityException {
102:                if (this .velocityEngine == null) {
103:                    this .velocityEngine = createVelocityEngine();
104:                }
105:            }
106:
107:            /**
108:             * Provides a ClasspathResourceLoader in addition to any default or user-defined
109:             * loader in order to load the spring Velocity macros from the class path.
110:             * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
111:             */
112:            protected void postProcessVelocityEngine(
113:                    VelocityEngine velocityEngine) {
114:                velocityEngine.setProperty(SPRING_MACRO_RESOURCE_LOADER_CLASS,
115:                        ClasspathResourceLoader.class.getName());
116:                velocityEngine.addProperty(VelocityEngine.RESOURCE_LOADER,
117:                        SPRING_MACRO_RESOURCE_LOADER_NAME);
118:                velocityEngine.addProperty(VelocityEngine.VM_LIBRARY,
119:                        SPRING_MACRO_LIBRARY);
120:                if (logger.isInfoEnabled()) {
121:                    logger.info("ClasspathResourceLoader with name '"
122:                            + SPRING_MACRO_RESOURCE_LOADER_NAME
123:                            + "' added to configured VelocityEngine");
124:                }
125:            }
126:
127:            public VelocityEngine getVelocityEngine() {
128:                return this.velocityEngine;
129:            }
130:
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.