KickJava   Java API By Example, From Geeks To Geeks.

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


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.ActionPage;
20 import com.blandware.atleap.model.core.Layout;
21 import com.blandware.atleap.service.core.LayoutManager;
22 import com.blandware.atleap.service.core.PageManager;
23 import com.blandware.atleap.webapp.action.core.BaseAction;
24 import com.blandware.atleap.webapp.form.ActionPageForm;
25 import com.blandware.atleap.webapp.util.core.LocaleUtil;
26 import com.blandware.atleap.webapp.util.core.WebappConstants;
27 import org.apache.commons.validator.GenericValidator;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.struts.action.ActionMessage;
32 import org.apache.struts.action.ActionMessages;
33
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.List JavaDoc;
38
39 /**
40  * <p>Exposes bean to request to view its properties on JSP page (action page
41  * is to be viewed)
42  * </p>
43  * <p><a HREF="ViewActionPageAction.java.htm"><i>View Source</i></a></p>
44  * <p/>
45  *
46  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
47  * @version $Revision: 1.21 $ $Date: 2006/03/10 17:10:15 $
48  * @struts.action path="/core/actionPage/view"
49  * name="actionPageForm"
50  * scope="request"
51  * validate="false"
52  * roles="core-actionPage-view"
53  * @struts.action-forward name="viewActionPage"
54  * path=".core.actionPage.view"
55  * @struts.action-forward name="listActionPages"
56  * path="/core/actionPage/list.do"
57  * redirect="true"
58  */

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

69     public ActionForward execute(ActionMapping mapping, ActionForm form,
70                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
71         ActionPageForm actionPageForm = (ActionPageForm) form;
72         Long JavaDoc actionPageId = null;
73         if ( !GenericValidator.isBlankOrNull(actionPageForm.getId()) ) {
74             actionPageId = Long.valueOf(actionPageForm.getId());
75         } else if ( request.getSession().getAttribute(WebappConstants.ACTION_PAGE_ID_KEY) != null ) {
76             actionPageId = (Long JavaDoc) request.getSession().getAttribute(WebappConstants.ACTION_PAGE_ID_KEY);
77         } else {
78             if ( log.isWarnEnabled() ) {
79                 log.warn("Missing action page ID. Returning to list...");
80             }
81             return mapping.findForward("listActionPages");
82         }
83
84         PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN);
85         ActionPage actionPage = pageManager.retrieveActionPage(actionPageId);
86
87         if ( actionPage == null ) {
88             // action page not found. it might be deleted by someone else
89
ActionMessages errors = new ActionMessages();
90             errors.add("actionPageNotFound", new ActionMessage("core.actionPage.errors.notFound"));
91             saveErrors(request, errors);
92             return mapping.findForward("listActionPages");
93         }
94
95
96         // save owner ID in session
97
request.getSession().setAttribute(WebappConstants.OWNER_ID_KEY, actionPage.getId());
98
99
100         request.setAttribute("actionPage", actionPage);
101
102         // Populate layout drop-down list
103
LayoutManager layoutManager = (LayoutManager) getBean(Constants.LAYOUT_MANAGER_BEAN);
104         List JavaDoc layouts = null;
105         layouts = layoutManager.listLayouts(null).asList();
106
107         if ( layouts == null ) {
108             // no layout found
109
layouts = new ArrayList JavaDoc();
110         }
111
112         if ( layouts.isEmpty() ) {
113             request.getSession().removeAttribute(WebappConstants.LAYOUT_DEFINITION_KEY);
114         } else if ( request.getSession().getAttribute(WebappConstants.LAYOUT_DEFINITION_KEY) == null ) {
115             // if there is no attribute in session with name 'layoutDefinition', create one
116
Layout layout = (Layout) layouts.iterator().next();
117             request.getSession().setAttribute(WebappConstants.LAYOUT_DEFINITION_KEY, layout.getDefinition());
118         }
119
120         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
121
122         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
123
124         request.setAttribute(WebappConstants.LAYOUT_COLLECTION_KEY, layouts);
125
126         saveToken(request);
127         return mapping.findForward("viewActionPage");
128     }
129 }
Popular Tags