KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > menuItem > ProcessItemSetAction


1 /*
2  * Copyright 2005 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.action.core.menuItem;
17
18 import com.blandware.atleap.webapp.action.core.BaseAction;
19 import com.blandware.atleap.webapp.form.core.SwitchMenuItemSetVisibilityForm;
20 import com.blandware.atleap.webapp.util.core.WebappConstants;
21 import org.apache.struts.action.ActionForward;
22 import org.apache.struts.action.ActionMapping;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.commons.validator.GenericValidator;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Map JavaDoc;
30
31
32 /**
33  * <p>Process set of selected menu items
34  * </p>
35  * <p><a HREF="ProcessItemSetAction.java.htm"></a><i>View source</i></p>
36  *
37  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
38  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
39  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
40  * @version $Revision: 1.6 $ $Date: 2006/03/10 17:10:28 $
41  * @struts.action path="/core/menuItem/processItemSet"
42  * name="switchMenuItemSetVisibilityForm"
43  * scope="request"
44  * validate="false"
45  * roles="core-menuItem-switchVisibility"
46  * @struts.action-forward name="switchMenuItemVisibility"
47  * path="/core/menuItem/switchVisibility.do"
48  * redirect="false"
49  * @struts.action-forward name="listMenuItems"
50  * path="/core/menuItem/list.do"
51  * redirect="false"
52  */

53 public final class ProcessItemSetAction extends BaseAction {
54     /**
55      * @param mapping The ActionMapping used to select this instance
56      * @param form The optional ActionForm bean for this request (if any)
57      * @param request The HTTP request we are proceeding
58      * @param response The HTTP response we are creating
59      * @return an ActionForward instance describing where and how
60      * control should be forwarded, or null if response
61      * has already been completed
62      */

63     public ActionForward execute(ActionMapping mapping, ActionForm form,
64                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
65
66         SwitchMenuItemSetVisibilityForm processSetForm = (SwitchMenuItemSetVisibilityForm) form;
67         ArrayList JavaDoc selectedItemIdsList = new ArrayList JavaDoc(processSetForm.getCheckedBoxes().keySet());
68         Map JavaDoc positions = processSetForm.getPositions();
69
70         if ( selectedItemIdsList.isEmpty() ) {
71             return mapping.findForward("listMenuItems");
72         }
73
74         String JavaDoc ownerId = request.getParameter("ownerId");
75         if (GenericValidator.isBlankOrNull(ownerId)) {
76             return mapping.findForward("listMenuItems");
77         }
78
79         String JavaDoc mode = null;
80         String JavaDoc multipleOperation = request.getParameter("multipleOperation");
81
82         ActionForward forward = null;
83         forward = mapping.findForward("switchMenuItemVisibility");
84         if (!GenericValidator.isBlankOrNull(multipleOperation)) {
85             if ("hideSelected".equalsIgnoreCase(multipleOperation)) {
86                 mode = "invisible";
87             } else if ("showSelected".equalsIgnoreCase(multipleOperation)) {
88                 mode = "visible";
89             } else if ("inheritVisibilityForSelected".equalsIgnoreCase(multipleOperation)) {
90                 mode = "heritable";
91             } else {
92                 return mapping.findForward("listMenuItems");
93             }
94         } else {
95             if ( request.getParameter("hideSelected") != null ) {
96                 mode = "invisible";
97             } else if ( request.getParameter("showSelected") != null ) {
98                 mode = "visible";
99             } else if ( request.getParameter("inheritVisibilityForSelected") != null ) {
100                 mode = "heritable";
101             } else {
102                 return mapping.findForward("listMenuItems");
103             }
104         }
105
106         request.setAttribute(WebappConstants.MENU_ITEM_SELECTED_IDS_KEY, selectedItemIdsList);
107         request.setAttribute(WebappConstants.MENU_ITEM_VISIBILITY_MODE_FOR_SELECTED_KEY, mode);
108         request.setAttribute(WebappConstants.MENU_ITEM_OWNER_ID_FOR_SELECTED_KEY, ownerId);
109         request.setAttribute(WebappConstants.MENU_ITEM_POSITIONS_KEY, positions);
110
111         return forward;
112     }
113 }
114
Popular Tags