1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2Toolkit library.
13 *
14 * The Initial Owner of the Original Code is Power Of Two S.R.L.
15 * Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16 * All Rights Reserved.
17 *
18 * Contributor(s):
19 */
20 package com.pow2.struts.action;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29
30
31 /***
32 * Generic dispatcher Action class
33 * <br>
34 * The target resource can be specified by:
35 * <br>
36 *
37 * <ul>
38 * <li>
39 * the <code>parameter</code> attribute of the action element
40 * of the struts configuration file
41 * </li>
42 * <li>
43 * the <code>fwd</code> request attribute; the <code>fwd</code>
44 * attribute value specifies the forward name of the ActionForward object to
45 * retrieve.
46 * <br>
47 * Action URL Example: <code>myDispatcher.do?fwd=showUserData</code>
48 * </li>
49 * </ul>
50 *
51 * @author Ted Husted
52 * @author Luca Fossato
53 * @version $Revision: 1.1.1.1 $ $Date: 2004/08/31 20:22:46 $
54 */
55 public class DispatcherAction extends BaseAction
56 {
57 /***
58 * Dispatch the client requests.
59 *
60 * @param mapping the ActionMapping used to select this instance
61 * @param request the HTTP request we are processing
62 * @param response the HTTP response we are creating
63 * @param form the ActionForm associated with this action (if any)
64 * @return the ActionForward object
65 * @exception java.io.IOException
66 * @exception javax.servlet.ServletException
67 */
68 public ActionForward execute(ActionMapping mapping,
69 ActionForm form,
70 HttpServletRequest request,
71 HttpServletResponse response)
72 throws
73 java.io.IOException,
74 javax.servlet.ServletException
75 {
76 ActionErrors errors = new ActionErrors();
77 ActionForward actionForward = null;
78 String forwardParam = null;
79
80
81
82
83
84
85 if (isCancelled(request))
86 {
87
88 if (form != null)
89 form.reset(mapping, request);
90
91 ActionForward cancelFwd = null;
92
93
94 if ((cancelFwd = mapping.findForward(FWD_CANCEL)) != null)
95 return cancelFwd;
96
97 cat.warn("::perform - the current form's cancel button was pressed but the system cannot retrieve the " + FWD_CANCEL + " forward");
98 }
99
100
101
102
103
104 forwardParam = mapping.getParameter();
105
106
107
108 if (forwardParam == null)
109 forwardParam = request.getParameter("fwd");
110
111
112 if (forwardParam != null)
113 actionForward = mapping.findForward(forwardParam);
114
115
116 if (actionForward == null)
117 cat.warn("::perform - cannot retrieve a valid ActionForward object using the forward parameter [" + forwardParam + "]; returning NULL");
118
119 return actionForward;
120 }
121 }