KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > actionPage > SwitchLayoutAction


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.actionPage;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.Layout;
20 import com.blandware.atleap.service.core.LayoutManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.core.SwitchActionPageLayoutForm;
23 import com.blandware.atleap.webapp.util.core.WebappConstants;
24 import org.apache.commons.validator.GenericValidator;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * <p>Returns page with a list of menu items and form for switching action page
36  * layout (to simplify "testing" of changed layout -- allows to see new/changed
37  * menu items).
38  * </p>
39  * <p><a HREF="CallCreateActionPageAction.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.10 $ $Date: 2006/03/10 17:10:15 $
44  * @struts.action name="switchActionPageLayoutForm"
45  * path="/core/actionPage/switchLayout"
46  * validate="false"
47  * roles="core-actionPage-switchLayout"
48  * scope="session"
49  * @struts.action-forward name="listMenuItems"
50  * path="/core/menuItem/list.do"
51  * redirect="false"
52  * @struts.action-forward name="unsatisfiable"
53  * path="/core/actionPage/list.do"
54  */

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

65     public ActionForward execute(ActionMapping mapping, ActionForm form,
66                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
67
68         SwitchActionPageLayoutForm switchLayoutForm = (SwitchActionPageLayoutForm) form;
69
70         Long JavaDoc actionPageId = null;
71         if ( !GenericValidator.isBlankOrNull(switchLayoutForm.getActionPageId()) ) {
72             actionPageId = Long.valueOf(switchLayoutForm.getActionPageId());
73         } else {
74             if ( log.isWarnEnabled() ) {
75                 log.warn("Missing action page ID. Returning to index...");
76             }
77             return mapping.findForward("admin");
78         }
79
80         String JavaDoc layoutDefinition = switchLayoutForm.getLayoutDefinition();
81         if ( GenericValidator.isBlankOrNull(layoutDefinition) ) {
82             // get first layout
83
LayoutManager layoutManager = (LayoutManager) getBean(Constants.LAYOUT_MANAGER_BEAN);
84             List JavaDoc layouts = null;
85             layouts = layoutManager.listLayouts(null).asList();
86
87             if ( layouts == null ) {
88                 // no layout found
89
layouts = new ArrayList JavaDoc();
90             }
91
92             if ( !layouts.isEmpty() ) {
93                 Layout layout = (Layout) layouts.get(0);
94                 layoutDefinition = layout.getDefinition();
95             }
96         }
97
98         request.getSession().setAttribute(WebappConstants.LAYOUT_DEFINITION_KEY, layoutDefinition);
99         request.getSession().setAttribute(WebappConstants.OWNER_ID_KEY, actionPageId);
100         return mapping.findForward("listMenuItems");
101     }
102 }
Popular Tags