Source Code Cross Referenced for WebWorkVelocityServlet.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » views » 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 » webwork 2.2.6 » com.opensymphony.webwork.views.velocity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.views.velocity;
006:
007:        import com.opensymphony.webwork.RequestUtils;
008:        import com.opensymphony.webwork.ServletActionContext;
009:        import com.opensymphony.webwork.WebWorkConstants;
010:        import com.opensymphony.webwork.config.Configuration;
011:        import com.opensymphony.webwork.views.util.ContextUtil;
012:        import com.opensymphony.xwork.ActionContext;
013:        import org.apache.velocity.Template;
014:        import org.apache.velocity.context.Context;
015:        import org.apache.velocity.exception.MethodInvocationException;
016:        import org.apache.velocity.exception.ParseErrorException;
017:        import org.apache.velocity.exception.ResourceNotFoundException;
018:        import org.apache.velocity.runtime.RuntimeSingleton;
019:        import org.apache.velocity.servlet.VelocityServlet;
020:
021:        import javax.servlet.ServletConfig;
022:        import javax.servlet.ServletException;
023:        import javax.servlet.http.HttpServletRequest;
024:        import javax.servlet.http.HttpServletResponse;
025:        import javax.servlet.jsp.JspFactory;
026:        import javax.servlet.jsp.PageContext;
027:        import java.io.FileNotFoundException;
028:        import java.io.IOException;
029:        import java.io.UnsupportedEncodingException;
030:        import java.io.Writer;
031:        import java.util.Properties;
032:
033:        /**
034:         * @author $Author: the_mindstorm $
035:         * @version $Revision: 2052 $
036:         * @deprecated please use {@link com.opensymphony.webwork.dispatcher.VelocityResult} instead of direct access
037:         */
038:        public class WebWorkVelocityServlet extends VelocityServlet {
039:            private VelocityManager velocityManager;
040:
041:            public WebWorkVelocityServlet() {
042:                velocityManager = VelocityManager.getInstance();
043:            }
044:
045:            public void init(ServletConfig servletConfig)
046:                    throws ServletException {
047:                super .init(servletConfig);
048:
049:                // initialize our VelocityManager
050:                velocityManager.init(servletConfig.getServletContext());
051:            }
052:
053:            protected Context createContext(HttpServletRequest request,
054:                    HttpServletResponse response) {
055:                return velocityManager.createContext(ActionContext.getContext()
056:                        .getValueStack(), request, response);
057:            }
058:
059:            protected Template handleRequest(
060:                    HttpServletRequest httpServletRequest,
061:                    HttpServletResponse httpServletResponse, Context context)
062:                    throws Exception {
063:                String servletPath = (String) httpServletRequest
064:                        .getAttribute("javax.servlet.include.servlet_path");
065:
066:                if (servletPath == null) {
067:                    servletPath = RequestUtils
068:                            .getServletPath(httpServletRequest);
069:                }
070:
071:                return getTemplate(servletPath, getEncoding());
072:            }
073:
074:            /**
075:             * This method extends the VelocityServlet's loadConfiguration method by performing the following actions:
076:             * <ul>
077:             * <li>invokes VelocityServlet.loadConfiguration to create a properties object</li>
078:             * <li>alters the RESOURCE_LOADER to include a class loader</li>
079:             * <li>configures the class loader using the WebWorkResourceLoader</li>
080:             * </ul>
081:             *
082:             * @param servletConfig
083:             * @throws IOException
084:             * @throws FileNotFoundException
085:             * @see org.apache.velocity.servlet.VelocityServlet#loadConfiguration
086:             */
087:            protected Properties loadConfiguration(ServletConfig servletConfig)
088:                    throws IOException, FileNotFoundException {
089:                return velocityManager.loadConfiguration(servletConfig
090:                        .getServletContext());
091:            }
092:
093:            /**
094:             * create a PageContext and render the template to PageContext.getOut()
095:             *
096:             * @see VelocityServlet#mergeTemplate(Template, Context, HttpServletResponse) for additional documentation
097:             */
098:            protected void mergeTemplate(Template template, Context context,
099:                    HttpServletResponse response)
100:                    throws ResourceNotFoundException, ParseErrorException,
101:                    MethodInvocationException, IOException,
102:                    UnsupportedEncodingException, Exception {
103:                // save the old PageContext
104:                PageContext oldPageContext = ServletActionContext
105:                        .getPageContext();
106:
107:                // create a new PageContext
108:                JspFactory jspFactory = JspFactory.getDefaultFactory();
109:                HttpServletRequest request = (HttpServletRequest) context
110:                        .get(ContextUtil.REQUEST);
111:                PageContext pageContext = jspFactory.getPageContext(this ,
112:                        request, response, null, true, 8192, true);
113:
114:                // put the new PageContext into ActionContext
115:                ActionContext actionContext = ActionContext.getContext();
116:                actionContext.put(ServletActionContext.PAGE_CONTEXT,
117:                        pageContext);
118:
119:                try {
120:                    Writer writer = pageContext.getOut();
121:                    template.merge(context, writer);
122:                    writer.flush();
123:                } finally {
124:                    // perform cleanup
125:                    jspFactory.releasePageContext(pageContext);
126:                    actionContext.put(ServletActionContext.PAGE_CONTEXT,
127:                            oldPageContext);
128:                }
129:            }
130:
131:            private String getEncoding() {
132:                // todo look into converting this to using XWork/WebWork2 encoding rules
133:                try {
134:                    return Configuration
135:                            .getString(WebWorkConstants.WEBWORK_I18N_ENCODING);
136:                } catch (IllegalArgumentException e) {
137:                    return RuntimeSingleton.getString(
138:                            RuntimeSingleton.OUTPUT_ENCODING,
139:                            DEFAULT_OUTPUT_ENCODING);
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.