Source Code Cross Referenced for HttpHeaderResult.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » 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 » Web Framework » struts 2.0.11 » org.apache.struts2.dispatcher 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: HttpHeaderResult.java 471756 2006-11-06 15:01:43Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts2.dispatcher;
022:
023:        import java.util.HashMap;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:
027:        import javax.servlet.http.HttpServletResponse;
028:
029:        import org.apache.struts2.ServletActionContext;
030:
031:        import com.opensymphony.xwork2.ActionContext;
032:        import com.opensymphony.xwork2.ActionInvocation;
033:        import com.opensymphony.xwork2.Result;
034:        import com.opensymphony.xwork2.util.TextParseUtil;
035:        import com.opensymphony.xwork2.util.ValueStack;
036:
037:        /**
038:         * <!-- START SNIPPET: description -->
039:         *
040:         * A custom Result type for setting HTTP headers and status by optionally evaluating against the ValueStack.
041:         *
042:         * <!-- END SNIPPET: description -->
043:         * <p/>
044:         * <b>This result type takes the following parameters:</b>
045:         *
046:         * <!-- START SNIPPET: params -->
047:         *
048:         * <ul>
049:         *
050:         * <li><b>status</b> - the http servlet response status code that should be set on a response.</li>
051:         *
052:         * <li><b>parse</b> - true by default. If set to false, the headers param will not be parsed for Ognl expressions.</li>
053:         *
054:         * <li><b>headers</b> - header values.</li>
055:         *
056:         * </ul>
057:         *
058:         * <!-- END SNIPPET: params -->
059:         *
060:         * <b>Example:</b>
061:         *
062:         * <pre><!-- START SNIPPET: example -->
063:         * &lt;result name="success" type="httpheader"&gt;
064:         *   &lt;param name="status"&gt;204&lt;/param&gt;
065:         *   &lt;param name="headers.a"&gt;a custom header value&lt;/param&gt;
066:         *   &lt;param name="headers.b"&gt;another custom header value&lt;/param&gt;
067:         * &lt;/result&gt;
068:         * <!-- END SNIPPET: example --></pre>
069:         *
070:         */
071:        public class HttpHeaderResult implements  Result {
072:
073:            private static final long serialVersionUID = 195648957144219214L;
074:
075:            /** The default parameter */
076:            public static final String DEFAULT_PARAM = "status";
077:
078:            private boolean parse = true;
079:            private Map<String, String> headers;
080:            private int status = -1;
081:
082:            public HttpHeaderResult() {
083:                super ();
084:                headers = new HashMap<String, String>();
085:            }
086:
087:            public HttpHeaderResult(int status) {
088:                this ();
089:                this .status = status;
090:                this .parse = false;
091:            }
092:
093:            /**
094:             * Returns a Map of all HTTP headers.
095:             *
096:             * @return a Map of all HTTP headers.
097:             */
098:            public Map getHeaders() {
099:                return headers;
100:            }
101:
102:            /**
103:             * Sets whether or not the HTTP header values should be evaluated against the ValueStack (by default they are).
104:             *
105:             * @param parse <tt>true</tt> if HTTP header values should be evaluated agains the ValueStack, <tt>false</tt>
106:             *              otherwise.
107:             */
108:            public void setParse(boolean parse) {
109:                this .parse = parse;
110:            }
111:
112:            /**
113:             * Sets the http servlet response status code that should be set on a response.
114:             *
115:             * @param status the Http status code
116:             * @see javax.servlet.http.HttpServletResponse#setStatus(int)
117:             */
118:            public void setStatus(int status) {
119:                this .status = status;
120:            }
121:
122:            /**
123:             * Adds an HTTP header to the response
124:             * @param name
125:             * @param value
126:             */
127:            public void addHeader(String name, String value) {
128:                headers.put(name, value);
129:            }
130:
131:            /**
132:             * Sets the optional HTTP response status code and also re-sets HTTP headers after they've
133:             * been optionally evaluated against the ValueStack.
134:             *
135:             * @param invocation an encapsulation of the action execution state.
136:             * @throws Exception if an error occurs when re-setting the headers.
137:             */
138:            public void execute(ActionInvocation invocation) throws Exception {
139:                HttpServletResponse response = ServletActionContext
140:                        .getResponse();
141:
142:                if (status != -1) {
143:                    response.setStatus(status);
144:                }
145:
146:                if (headers != null) {
147:                    ValueStack stack = ActionContext.getContext()
148:                            .getValueStack();
149:
150:                    for (Iterator iterator = headers.entrySet().iterator(); iterator
151:                            .hasNext();) {
152:                        Map.Entry entry = (Map.Entry) iterator.next();
153:                        String value = (String) entry.getValue();
154:                        String finalValue = parse ? TextParseUtil
155:                                .translateVariables(value, stack) : value;
156:                        response.addHeader((String) entry.getKey(), finalValue);
157:                    }
158:                }
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.