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


001:        /*
002:         * $Id: $
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.portlet.result;
022:
023:        import java.util.Arrays;
024:        import java.util.Iterator;
025:        import java.util.LinkedHashMap;
026:        import java.util.List;
027:        import java.util.Map;
028:
029:        import org.apache.struts2.dispatcher.ServletActionRedirectResult;
030:        import org.apache.struts2.dispatcher.mapper.ActionMapper;
031:        import org.apache.struts2.dispatcher.mapper.ActionMapping;
032:        import org.apache.struts2.views.util.UrlHelper;
033:
034:        import com.opensymphony.xwork2.ActionInvocation;
035:        import com.opensymphony.xwork2.config.entities.ResultConfig;
036:        import com.opensymphony.xwork2.inject.Inject;
037:
038:        /**
039:         *
040:         * Portlet modification of the {@link ServletActionRedirectResult}.
041:         *
042:         * <!-- START SNIPPET: description -->
043:
044:         * This result uses the {@link ActionMapper} provided by the {@link ActionMapperFactory} to instruct the render phase to
045:         * invoke the specified action and (optional) namespace. This is better than the {@link PortletResult}
046:         * because it does not require you to encode the URL patterns processed by the {@link ActionMapper} in to your struts.xml
047:         * configuration files. This means you can change your URL patterns at any point and your application will still work.
048:         * It is strongly recommended that if you are redirecting to another action, you use this result rather than the
049:         * standard redirect result.
050:         *
051:         * See examples below for an example of how request parameters could be passed in.
052:         *
053:         * <!-- END SNIPPET: description -->
054:         *
055:         * <b>This result type takes the following parameters:</b>
056:         *
057:         * <!-- START SNIPPET: params -->
058:         *
059:         * <ul>
060:         *
061:         * <li><b>actionName (default)</b> - the name of the action that will be redirect to</li>
062:         *
063:         * <li><b>namespace</b> - used to determine which namespace the action is in that we're redirecting to . If namespace is
064:         * null, this defaults to the current namespace</li>
065:         *
066:         * </ul>
067:         *
068:         * <!-- END SNIPPET: params -->
069:         *
070:         * <b>Example:</b>
071:         *
072:         * <pre><!-- START SNIPPET: example -->
073:         * &lt;package name="public" extends="struts-default"&gt;
074:         *     &lt;action name="login" class="..."&gt;
075:         *         &lt;!-- Redirect to another namespace --&gt;
076:         *         &lt;result type="redirect-action"&gt;
077:         *             &lt;param name="actionName"&gt;dashboard&lt;/param&gt;
078:         *             &lt;param name="namespace"&gt;/secure&lt;/param&gt;
079:         *         &lt;/result&gt;
080:         *     &lt;/action&gt;
081:         * &lt;/package&gt;
082:         *
083:         * &lt;package name="secure" extends="struts-default" namespace="/secure"&gt;
084:         *     &lt;-- Redirect to an action in the same namespace --&gt;
085:         *     &lt;action name="dashboard" class="..."&gt;
086:         *         &lt;result&gt;dashboard.jsp&lt;/result&gt;
087:         *         &lt;result name="error" type="redirect-action"&gt;error&lt;/result&gt;
088:         *     &lt;/action&gt;
089:         *
090:         *     &lt;action name="error" class="..."&gt;
091:         *         &lt;result&gt;error.jsp&lt;/result&gt;
092:         *     &lt;/action&gt;
093:         * &lt;/package&gt;
094:         *
095:         * &lt;package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters"&gt;
096:         *    &lt;-- Pass parameters (reportType, width and height) --&gt;
097:         *    &lt;!--
098:         *    The redirect-action url generated will be :
099:         *    /genReport/generateReport.action?reportType=pie&width=100&height=100
100:         *    --&gt;
101:         *    &lt;action name="gatherReportInfo" class="..."&gt;
102:         *       &lt;result name="showReportResult" type="redirect-action"&gt;
103:         *          &lt;param name="actionName"&gt;generateReport&lt;/param&gt;
104:         *          &lt;param name="namespace"&gt;/genReport&lt;/param&gt;
105:         *          &lt;param name="reportType"&gt;pie&lt;/param&gt;
106:         *          &lt;param name="width"&gt;100&lt;/param&gt;
107:         *          &lt;param name="height"&gt;100&lt;/param&gt;
108:         *       &lt;/result&gt;
109:         *    &lt;/action&gt;
110:         * &lt;/package&gt;
111:         *
112:         *
113:         * <!-- END SNIPPET: example --></pre>
114:         *
115:         * @see ActionMapper
116:         */
117:        public class PortletActionRedirectResult extends PortletResult {
118:
119:            private static final long serialVersionUID = -7627388936683562557L;
120:
121:            /** The default parameter */
122:            public static final String DEFAULT_PARAM = "actionName";
123:
124:            protected String actionName;
125:            protected String namespace;
126:            protected String method;
127:
128:            private Map<String, String> requestParameters = new LinkedHashMap<String, String>();
129:
130:            private ActionMapper actionMapper;
131:
132:            public PortletActionRedirectResult() {
133:                super ();
134:            }
135:
136:            public PortletActionRedirectResult(String actionName) {
137:                this (null, actionName, null);
138:            }
139:
140:            public PortletActionRedirectResult(String actionName, String method) {
141:                this (null, actionName, method);
142:            }
143:
144:            public PortletActionRedirectResult(String namespace,
145:                    String actionName, String method) {
146:                super (null);
147:                this .namespace = namespace;
148:                this .actionName = actionName;
149:                this .method = method;
150:            }
151:
152:            protected List<String> prohibitedResultParam = Arrays
153:                    .asList(new String[] { DEFAULT_PARAM, "namespace",
154:                            "method", "encode", "parse", "location",
155:                            "prependServletContext" });
156:
157:            @Inject
158:            public void setActionMapper(ActionMapper actionMapper) {
159:                this .actionMapper = actionMapper;
160:            }
161:
162:            /**
163:             * @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
164:             */
165:            public void execute(ActionInvocation invocation) throws Exception {
166:                actionName = conditionalParse(actionName, invocation);
167:                if (namespace == null) {
168:                    namespace = invocation.getProxy().getNamespace();
169:                } else {
170:                    namespace = conditionalParse(namespace, invocation);
171:                }
172:                if (method == null) {
173:                    method = "";
174:                } else {
175:                    method = conditionalParse(method, invocation);
176:                }
177:
178:                String resultCode = invocation.getResultCode();
179:                if (resultCode != null) {
180:                    ResultConfig resultConfig = invocation.getProxy()
181:                            .getConfig().getResults().get(resultCode);
182:                    Map resultConfigParams = resultConfig.getParams();
183:                    for (Iterator i = resultConfigParams.entrySet().iterator(); i
184:                            .hasNext();) {
185:                        Map.Entry e = (Map.Entry) i.next();
186:                        if (!prohibitedResultParam.contains(e.getKey())) {
187:                            requestParameters.put(e.getKey().toString(), e
188:                                    .getValue() == null ? ""
189:                                    : conditionalParse(e.getValue().toString(),
190:                                            invocation));
191:                        }
192:                    }
193:                }
194:
195:                StringBuffer tmpLocation = new StringBuffer(actionMapper
196:                        .getUriFromActionMapping(new ActionMapping(actionName,
197:                                namespace, method, null)));
198:                UrlHelper.buildParametersString(requestParameters, tmpLocation,
199:                        "&");
200:
201:                setLocation(tmpLocation.toString());
202:
203:                super .execute(invocation);
204:            }
205:
206:            /**
207:             * Sets the action name
208:             *
209:             * @param actionName The name
210:             */
211:            public void setActionName(String actionName) {
212:                this .actionName = actionName;
213:            }
214:
215:            /**
216:             * Sets the namespace
217:             *
218:             * @param namespace The namespace
219:             */
220:            public void setNamespace(String namespace) {
221:                this .namespace = namespace;
222:            }
223:
224:            /**
225:             * Sets the method
226:             *
227:             * @param method The method
228:             */
229:            public void setMethod(String method) {
230:                this .method = method;
231:            }
232:
233:            /**
234:             * Adds a request parameter to be added to the redirect url
235:             *
236:             * @param key The parameter name
237:             * @param value The parameter value
238:             */
239:            public PortletActionRedirectResult addParameter(String key,
240:                    Object value) {
241:                requestParameters.put(key, String.valueOf(value));
242:                return this;
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.