Source Code Cross Referenced for HttpHeaderResult.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 com.opensymphony.webwork.ServletActionContext;
008:        import com.opensymphony.xwork.ActionContext;
009:        import com.opensymphony.xwork.ActionInvocation;
010:        import com.opensymphony.xwork.Result;
011:        import com.opensymphony.xwork.util.OgnlValueStack;
012:        import com.opensymphony.xwork.util.TextParseUtil;
013:
014:        import javax.servlet.http.HttpServletResponse;
015:        import java.util.HashMap;
016:        import java.util.Iterator;
017:        import java.util.Map;
018:
019:        /**
020:         * <!-- START SNIPPET: description -->
021:         *
022:         * A custom Result type for evaluating HTTP headers against the ValueStack.
023:         * 
024:         * <!-- END SNIPPET: description -->
025:         * <p/>
026:         * <b>This result type takes the following parameters:</b>
027:         *
028:         * <!-- START SNIPPET: params -->
029:         *
030:         * <ul>
031:         *
032:         * <li><b>status</b> - the http servlet response status code that should be set on a response.</li>
033:         *
034:         * <li><b>parse</b> - true by default. If set to false, the headers param will not be parsed for Ognl expressions.</li>
035:         *
036:         * <li><b>headers</b> - header values.</li>
037:         *
038:         * </ul>
039:         *
040:         * <!-- END SNIPPET: params -->
041:         *
042:         * <b>Example:</b>
043:         *
044:         * <pre><!-- START SNIPPET: example -->
045:         * &lt;result name="success" type="httpheader"&gt;
046:         *   &lt;param name="status"&gt;204&lt;/param&gt;
047:         *   &lt;param name="headers.a"&gt;a custom header value&lt;/param&gt;
048:         *   &lt;param name="headers.b"&gt;another custom header value&lt;/param&gt;
049:         * &lt;/result&gt;
050:         * <!-- END SNIPPET: example --></pre>
051:         *
052:         * @author Jason Carreira
053:         */
054:        public class HttpHeaderResult implements  Result {
055:
056:            public static final String DEFAULT_PARAM = "status";
057:
058:            protected boolean parse = true;
059:            private Map headers;
060:            private int status = -1;
061:
062:            /**
063:             * Returns a Map of all HTTP headers.
064:             *
065:             * @return a Map of all HTTP headers.
066:             */
067:            public Map getHeaders() {
068:                if (headers == null) {
069:                    headers = new HashMap();
070:                }
071:
072:                return headers;
073:            }
074:
075:            /**
076:             * Sets whether or not the HTTP header values should be evaluated against the ValueStack (by default they are).
077:             *
078:             * @param parse <tt>true</tt> if HTTP header values should be evaluated agains the ValueStack, <tt>false</tt>
079:             *              otherwise.
080:             */
081:            public void setParse(boolean parse) {
082:                this .parse = parse;
083:            }
084:
085:            /**
086:             * Sets the http servlet response status code that should be set on a response.
087:             *
088:             * @param status the Http status code
089:             * @see javax.servlet.http.HttpServletResponse#setStatus(int)
090:             */
091:            public void setStatus(int status) {
092:                this .status = status;
093:            }
094:
095:            /**
096:             * Sets the optional HTTP response status code and also re-sets HTTP headers after they've
097:             * been optionally evaluated against the ValueStack.
098:             *
099:             * @param invocation an encapsulation of the action execution state.
100:             * @throws Exception if an error occurs when re-setting the headers.
101:             */
102:            public void execute(ActionInvocation invocation) throws Exception {
103:                HttpServletResponse response = ServletActionContext
104:                        .getResponse();
105:
106:                if (status != -1) {
107:                    response.setStatus(status);
108:                }
109:
110:                if (headers != null) {
111:                    OgnlValueStack stack = ActionContext.getContext()
112:                            .getValueStack();
113:
114:                    for (Iterator iterator = headers.entrySet().iterator(); iterator
115:                            .hasNext();) {
116:                        Map.Entry entry = (Map.Entry) iterator.next();
117:                        String value = (String) entry.getValue();
118:                        String finalValue = parse ? TextParseUtil
119:                                .translateVariables(value, stack) : value;
120:                        response.addHeader((String) entry.getKey(), finalValue);
121:                    }
122:                }
123:            }
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.