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


001:        /*
002:         * $Id: EventDispatchAction.java 471754 2006-11-06 14:55:09Z 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.struts.actions;
022:
023:        import java.util.StringTokenizer;
024:
025:        import javax.servlet.ServletException;
026:        import javax.servlet.http.HttpServletRequest;
027:        import javax.servlet.http.HttpServletResponse;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:        import org.apache.struts.action.ActionForm;
032:        import org.apache.struts.action.ActionMapping;
033:        import org.apache.struts.action.ActionForward;
034:
035:        /**
036:         * <p>An <strong>Action</strong> that dispatches to to one of the public methods
037:         * that are named in the <code>parameter</code> attribute of the corresponding
038:         * ActionMapping and matches a submission parameter. This is useful for
039:         * developers who prefer to use many submit buttons, images, or submit links
040:         * on a single form and whose related actions exist in a single Action class.</p>
041:         *
042:         * <p>The method(s) must have the same signature (other than method name) of the
043:         * standard Action.execute method.</p>
044:         *
045:         * <p>To configure the use of this action in your
046:         * <code>struts-config.xml</code> file, create an entry like this:</p>
047:         *
048:         * <pre><code>
049:         *   &lt;action path="/saveSubscription"
050:         *           type="org.example.SubscriptionAction"
051:         *           name="subscriptionForm"
052:         *          scope="request"
053:         *          input="/subscription.jsp"
054:         *      parameter="save,back,recalc=recalculate,default=save"/&gt;
055:         * </code></pre>
056:         *
057:         * <p>where <code>parameter</code> contains three possible methods and one
058:         * default method if nothing matches (such as the user pressing the enter key).</p>
059:         *
060:         * <p>For utility purposes, you can use the <code>key=value</code> notation to
061:         * alias methods so that they are exposed as different form element names, in the
062:         * event of a naming conflict or otherwise. In this example, the <em>recalc</em>
063:         * button (via a request parameter) will invoke the <code>recalculate</code>
064:         * method. The security-minded person may find this feature valuable to
065:         * obfuscate and not expose the methods.</p>
066:         *
067:         * <p>The <em>default</em> key is purely optional. If this is not specified
068:         * and no parameters match the list of method keys, <code>null</code> is
069:         * returned which means the <code>unspecified</code> method will be invoked.</p>
070:         *
071:         * <p>The order of the parameters are guaranteed to be iterated in the order
072:         * specified. If multiple buttons were accidently submitted, the first match in
073:         * the list will be dispatched.</p>
074:         *
075:         * @since Struts 1.2.9
076:         */
077:        public class EventDispatchAction extends DispatchAction {
078:
079:            /**
080:             * Commons Logging instance.
081:             */
082:            private static final Log LOG = LogFactory
083:                    .getLog(EventDispatchAction.class);
084:
085:            /**
086:             * The method key, if present, to use if other specified method keys
087:             * do not match a request parameter.
088:             */
089:            private static final String DEFAULT_METHOD_KEY = "default";
090:
091:            // --------------------------------------------------------- Protected Methods
092:
093:            /**
094:             * Method which is dispatched to when there is no value for specified
095:             * request parameter included in the request.  Subclasses of
096:             * <code>DispatchAction</code> should override this method if they wish to
097:             * provide default behavior different than throwing a ServletException.
098:             *
099:             * @param mapping  The ActionMapping used to select this instance
100:             * @param form     The optional ActionForm bean for this request (if any)
101:             * @param request  The non-HTTP request we are processing
102:             * @param response The non-HTTP response we are creating
103:             * @return The forward to which control should be transferred, or
104:             *         <code>null</code> if the response has been completed.
105:             * @throws Exception if the application business logic throws an
106:             *                   exception.
107:             */
108:            protected ActionForward unspecified(ActionMapping mapping,
109:                    ActionForm form, HttpServletRequest request,
110:                    HttpServletResponse response) throws Exception {
111:                String message = messages.getMessage("event.parameter", mapping
112:                        .getPath(), mapping.getParameter());
113:
114:                LOG.error(message + " " + mapping.getParameter());
115:
116:                throw new ServletException(message);
117:            }
118:
119:            /**
120:             * Returns the method name, given a parameter's value.
121:             *
122:             * @param mapping   The ActionMapping used to select this instance
123:             * @param form      The optional ActionForm bean for this request (if
124:             *                  any)
125:             * @param request   The HTTP request we are processing
126:             * @param response  The HTTP response we are creating
127:             * @param parameter The <code>ActionMapping</code> parameter's name
128:             * @return The method's name.
129:             * @throws Exception if an error occurs.
130:             */
131:            protected String getMethodName(ActionMapping mapping,
132:                    ActionForm form, HttpServletRequest request,
133:                    HttpServletResponse response, String parameter)
134:                    throws Exception {
135:
136:                StringTokenizer st = new StringTokenizer(parameter, ",");
137:                String defaultMethodName = null;
138:
139:                while (st.hasMoreTokens()) {
140:                    String methodKey = st.nextToken().trim();
141:                    String methodName = methodKey;
142:
143:                    // The key can either be a direct method name or an alias
144:                    // to a method as indicated by a "key=value" signature
145:                    int equals = methodKey.indexOf('=');
146:                    if (equals > -1) {
147:                        methodName = methodKey.substring(equals + 1).trim();
148:                        methodKey = methodKey.substring(0, equals).trim();
149:                    }
150:
151:                    // Set the default if it passes by
152:                    if (methodKey.equals(DEFAULT_METHOD_KEY)) {
153:                        defaultMethodName = methodName;
154:                    }
155:
156:                    // If the method key exists as a standalone parameter or with
157:                    // the image suffixes (.x/.y), the method name has been found.
158:                    if ((request.getParameter(methodKey) != null)
159:                            || (request.getParameter(methodKey + ".x") != null)) {
160:                        return methodName;
161:                    }
162:                }
163:
164:                return defaultMethodName;
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.