KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2004 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.common.Constants;
19 import com.blandware.atleap.model.core.MenuItem;
20 import com.blandware.atleap.service.core.MenuManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.MenuItemForm;
23 import com.blandware.atleap.webapp.util.core.LocaleUtil;
24 import com.blandware.atleap.webapp.util.core.WebappConstants;
25 import com.blandware.atleap.webapp.util.core.WebappUtil;
26 import org.apache.commons.validator.GenericValidator;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33 import java.util.LinkedList JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * <p>Returns page with form to create new menu item
38  * </p>
39  * <p><a HREF="CallCreateMenuItemAction.java.htm"><i>View Source</i></a></p>
40  * <p/>
41  *
42  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
43  * @version $Revision: 1.17 $ $Date: 2006/03/10 17:10:27 $
44  * @struts.action path="/core/menuItem/callCreate"
45  * name="menuItemForm"
46  * validate="false"
47  * roles="core-menuItem-create"
48  * @struts.action-forward name="createMenuItem"
49  * path=".core.menuItem.create"
50  * @struts.action-forward name="listMenuItems"
51  * path="/core/menuItem/list.do"
52  * redirect="false"
53  */

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

64     public ActionForward execute(ActionMapping mapping, ActionForm form,
65                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
66
67         MenuItemForm menuItemForm = (MenuItemForm) form;
68
69         Long JavaDoc ownerId = null;
70         if ( !GenericValidator.isBlankOrNull(menuItemForm.getOwnerId()) ) {
71             ownerId = Long.valueOf(menuItemForm.getOwnerId());
72         } else {
73             if ( log.isWarnEnabled() ) {
74                 log.warn("Missing owner ID. Returning to index...");
75             }
76             return mapping.findForward("admin");
77         }
78
79         // remove attribute under which locale suffix is saved in session
80
request.getSession().removeAttribute(WebappConstants.BROWSER_LOCALE_SUFFIX_KEY);
81
82         request.getSession().setAttribute(WebappConstants.OWNER_ID_KEY, ownerId);
83
84         Long JavaDoc parentItemId = (Long JavaDoc) request.getSession().getAttribute(WebappConstants.MENU_ITEM_PARENT_ID_KEY);
85         if ( parentItemId == null ) {
86             // can't create items in root
87
return mapping.findForward("listMenuItems");
88         }
89
90         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
91
92         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
93
94         // save owner info
95
request.setAttribute(WebappConstants.OWNER_INFO_KEY, WebappUtil.getLocalizableInfo(ownerId, request));
96
97         // save path
98
MenuManager menuManager = (MenuManager) getBean(Constants.MENU_MANAGER_BEAN);
99         MenuItem parentItem = menuManager.retrieveMenuItem(parentItemId);
100
101         if ( parentItem != null ) {
102             // parent item is not null, save list of parents
103
LinkedList JavaDoc parents = new LinkedList JavaDoc();
104             while ( parentItem != null ) {
105                 parents.addFirst(parentItem);
106                 parentItem = parentItem.getParentItem();
107             }
108             request.setAttribute(WebappConstants.MENU_ITEM_PARENTS_LIST_KEY, parents);
109         }
110
111         // save transaction token in request
112
saveToken(request);
113
114         return mapping.findForward("createMenuItem");
115     }
116 }
Popular Tags