Source Code Cross Referenced for PlainTextResult.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » dispatcher » 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.dispatcher 
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.dispatcher;
006:
007:        import java.io.InputStreamReader;
008:        import java.io.PrintWriter;
009:        import java.nio.charset.Charset;
010:
011:        import javax.servlet.ServletContext;
012:        import javax.servlet.http.HttpServletResponse;
013:
014:        import org.apache.commons.logging.Log;
015:        import org.apache.commons.logging.LogFactory;
016:
017:        import com.opensymphony.xwork.ActionInvocation;
018:
019:        /**
020:         * <!-- START SNIPPET: description -->
021:         * 
022:         * A result that send the content out as plain text. Usefull typically when needed
023:         * to display the raw content of a JSP or Html file for example.
024:         * 
025:         * <!-- END SNIPPET: description -->
026:         * 
027:         * 
028:         * <!-- START SNIPPET: params -->
029:         * 
030:         * <ul>
031:         * 	<li>location (default) = location of the file (jsp/html) to be displayed as plain text.</li>
032:         *  <li>charSet (optional) = character set to be used. This character set will be used to set the
033:         *  response type (eg. Content-Type=text/plain; charset=UTF-8) and when reading 
034:         *  using a Reader. Some example of charSet would be UTF-8, ISO-8859-1 etc. 
035:         * </ul>
036:         * 
037:         * <!-- END SNIPPET: params -->
038:         * 
039:         * 
040:         * <pre>
041:         * <!-- START SNIPPET: example -->
042:         * 
043:         * &lt;action name="displayJspRawContent" &gt;
044:         *   &lt;result type="plaintext"&gt;/myJspFile.jsp&lt;/result&gt;
045:         * &lt;/action&gt;
046:         * 
047:         * 
048:         * &lt;action name="displayJspRawContent" &gt;
049:         *   &lt;result type="plaintext"&gt;
050:         *      &lt;param name="location"&gt;/myJspFile.jsp&lt;/param&gt;
051:         *      &lt;param name="charSet"&gt;UTF-8&lt;/param&gt;
052:         *   &lt;/result&gt;
053:         * &lt;/action&gt;
054:         * 
055:         * <!-- END SNIPPET: example -->
056:         * </pre>
057:         * 
058:         * @author tm_jee
059:         * @version $Date: 2006-03-12 06:41:05 +0100 (Sun, 12 Mar 2006) $ $Id: PlainTextResult.java 2381 2006-03-12 05:41:05Z tmjee $
060:         */
061:        public class PlainTextResult extends WebWorkResultSupport {
062:
063:            private static final Log _log = LogFactory
064:                    .getLog(PlainTextResult.class);
065:
066:            private static final long serialVersionUID = 3633371605905583950L;
067:
068:            public static final int BUFFER_SIZE = 1024;
069:
070:            private String charSet;
071:
072:            public String getCharSet() {
073:                return charSet;
074:            }
075:
076:            public void setCharSet(String charSet) {
077:                this .charSet = charSet;
078:            }
079:
080:            protected void doExecute(String finalLocation,
081:                    ActionInvocation invocation) throws Exception {
082:
083:                // verify charset 
084:                Charset charset = null;
085:                if (charSet != null) {
086:                    if (Charset.isSupported(charSet)) {
087:                        charset = Charset.forName(charSet);
088:                    } else {
089:                        _log.warn("charset [" + charSet
090:                                + "] is not recognized ");
091:                        charset = null;
092:                    }
093:                }
094:
095:                HttpServletResponse response = (HttpServletResponse) invocation
096:                        .getInvocationContext().get(HTTP_RESPONSE);
097:                ServletContext servletContext = (ServletContext) invocation
098:                        .getInvocationContext().get(SERVLET_CONTEXT);
099:
100:                if (charset != null) {
101:                    response.setContentType("text/plain; charset=" + charSet);
102:                } else {
103:                    response.setContentType("text/plain");
104:                }
105:                response.setHeader("Content-Disposition", "inline");
106:
107:                PrintWriter writer = response.getWriter();
108:                InputStreamReader reader = null;
109:                try {
110:                    if (charset != null) {
111:                        reader = new InputStreamReader(servletContext
112:                                .getResourceAsStream(location), charset);
113:                    } else {
114:                        reader = new InputStreamReader(servletContext
115:                                .getResourceAsStream(location));
116:                    }
117:                    if (reader == null) {
118:                        _log
119:                                .warn("resource at location ["
120:                                        + location
121:                                        + "] cannot be obtained (return null) from ServletContext !!! ");
122:                    } else {
123:                        char[] buffer = new char[BUFFER_SIZE];
124:                        int charRead = 0;
125:                        while ((charRead = reader.read(buffer)) != -1) {
126:                            writer.write(buffer, 0, charRead);
127:                        }
128:                    }
129:                } finally {
130:                    if (reader != null)
131:                        reader.close();
132:                    if (writer != null) {
133:                        writer.flush();
134:                        writer.close();
135:                    }
136:                }
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.