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


001:        /*
002:         * $Id: ServletConfigInterceptor.java 502196 2007-02-01 11:28:57Z rgielen $
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.interceptor;
022:
023:        import java.util.Map;
024:
025:        import javax.servlet.ServletContext;
026:        import javax.servlet.http.HttpServletRequest;
027:        import javax.servlet.http.HttpServletResponse;
028:        import javax.portlet.PortletRequest;
029:
030:        import org.apache.struts2.StrutsStatics;
031:        import org.apache.struts2.servlet.interceptor.ServletPrincipalProxy;
032:        import org.apache.struts2.portlet.PortletActionConstants;
033:        import org.apache.struts2.portlet.interceptor.PortletPrincipalProxy;
034:        import org.apache.struts2.util.ServletContextAware;
035:
036:        import com.opensymphony.xwork2.ActionContext;
037:        import com.opensymphony.xwork2.ActionInvocation;
038:        import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
039:
040:        /**
041:         * <!-- START SNIPPET: description -->
042:         *
043:         * An interceptor which sets action properties based on the interfaces an action implements. For example, if the action
044:         * implements {@link ParameterAware} then the action context's parameter map will be set on it.
045:         *
046:         * <p/> This interceptor is designed to set all properties an action needs if it's aware of servlet parameters, the
047:         * servlet context, the session, etc. Interfaces that it supports are:
048:         *
049:         * <ul>
050:         *
051:         * <li>{@link ServletContextAware}</li>
052:         *
053:         * <li>{@link ServletRequestAware}</li>
054:         *
055:         * <li>{@link ServletResponseAware}</li>
056:         *
057:         * <li>{@link ParameterAware}</li>
058:         *
059:         * <li>{@link RequestAware}</li>
060:         *
061:         * <li>{@link SessionAware}</li>
062:         *
063:         * <li>{@link ApplicationAware}</li>
064:         *
065:         * <li>{@link PrincipalAware}</li>
066:         *
067:         * </ul>
068:         *
069:         * <!-- END SNIPPET: description -->
070:         *
071:         * <p/> <u>Interceptor parameters:</u>
072:         *
073:         * <!-- START SNIPPET: parameters -->
074:         *
075:         * <ul>
076:         *
077:         * <li>None</li>
078:         *
079:         * </ul>
080:         *
081:         * <!-- END SNIPPET: parameters -->
082:         *
083:         * <p/> <u>Extending the interceptor:</u>
084:         *
085:         * <p/>
086:         *
087:         * <!-- START SNIPPET: extending -->
088:         *
089:         * There are no known extension points for this interceptor.
090:         *
091:         * <!-- END SNIPPET: extending -->
092:         *
093:         * <p/> <u>Example code:</u>
094:         *
095:         * <pre>
096:         * <!-- START SNIPPET: example -->
097:         * &lt;action name="someAction" class="com.examples.SomeAction"&gt;
098:         *     &lt;interceptor-ref name="servlet-config"/&gt;
099:         *     &lt;interceptor-ref name="basicStack"/&gt;
100:         *     &lt;result name="success"&gt;good_result.ftl&lt;/result&gt;
101:         * &lt;/action&gt;
102:         * <!-- END SNIPPET: example -->
103:         * </pre>
104:         *
105:         * @see ServletContextAware
106:         * @see ServletRequestAware
107:         * @see ServletResponseAware
108:         * @see ParameterAware
109:         * @see SessionAware
110:         * @see ApplicationAware
111:         * @see PrincipalAware
112:         */
113:        public class ServletConfigInterceptor extends AbstractInterceptor
114:                implements  StrutsStatics {
115:
116:            private static final long serialVersionUID = 605261777858676638L;
117:
118:            /**
119:             * Sets action properties based on the interfaces an action implements. Things like application properties,
120:             * parameters, session attributes, etc are set based on the implementing interface.
121:             *
122:             * @param invocation an encapsulation of the action execution state.
123:             * @throws Exception if an error occurs when setting action properties.
124:             */
125:            public String intercept(ActionInvocation invocation)
126:                    throws Exception {
127:                final Object action = invocation.getAction();
128:                final ActionContext context = invocation.getInvocationContext();
129:
130:                if (action instanceof  ServletRequestAware) {
131:                    HttpServletRequest request = (HttpServletRequest) context
132:                            .get(HTTP_REQUEST);
133:                    ((ServletRequestAware) action).setServletRequest(request);
134:                }
135:
136:                if (action instanceof  ServletResponseAware) {
137:                    HttpServletResponse response = (HttpServletResponse) context
138:                            .get(HTTP_RESPONSE);
139:                    ((ServletResponseAware) action)
140:                            .setServletResponse(response);
141:                }
142:
143:                if (action instanceof  ParameterAware) {
144:                    ((ParameterAware) action).setParameters(context
145:                            .getParameters());
146:                }
147:
148:                if (action instanceof  RequestAware) {
149:                    ((RequestAware) action).setRequest((Map) context
150:                            .get("request"));
151:                }
152:
153:                if (action instanceof  SessionAware) {
154:                    ((SessionAware) action).setSession(context.getSession());
155:                }
156:
157:                if (action instanceof  ApplicationAware) {
158:                    ((ApplicationAware) action).setApplication(context
159:                            .getApplication());
160:                }
161:
162:                if (action instanceof  PrincipalAware) {
163:                    HttpServletRequest request = (HttpServletRequest) context
164:                            .get(HTTP_REQUEST);
165:                    Object portletRequest = context
166:                            .get(PortletActionConstants.REQUEST);
167:                    if (portletRequest != null) {
168:                        // We are in portlet environment, so principal information resides in PortletRequest
169:                        ((PrincipalAware) action)
170:                                .setPrincipalProxy(new PortletPrincipalProxy(
171:                                        (PortletRequest) portletRequest));
172:                    } else {
173:                        // We are in servtlet environment, so principal information resides in HttpServletRequest
174:                        ((PrincipalAware) action)
175:                                .setPrincipalProxy(new ServletPrincipalProxy(
176:                                        request));
177:                    }
178:                }
179:                if (action instanceof  ServletContextAware) {
180:                    ServletContext servletContext = (ServletContext) context
181:                            .get(SERVLET_CONTEXT);
182:                    ((ServletContextAware) action)
183:                            .setServletContext(servletContext);
184:                }
185:                return invocation.invoke();
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.