KickJava   Java API By Example, From Geeks To Geeks.

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


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.service.core.PageManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.ActionPageForm;
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 import org.apache.struts.action.ActionMessage;
31 import org.apache.struts.action.ActionMessages;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import java.util.List JavaDoc;
36
37 /**
38  * <p>Prepares form bean to update action page's data
39  * </p>
40  * <p><a HREF="CallUpdateActionPageAction.java.htm"><i>View Source</i></a></p>
41  * <p/>
42  *
43  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
44  * @version $Revision: 1.21 $ $Date: 2006/03/10 17:10:14 $
45  * @struts.action name="actionPageForm"
46  * path="/core/actionPage/callUpdate"
47  * scope="request"
48  * validate="false"
49  * roles="core-actionPage-update, core-actionPage-updateContent, core-actionPage-view"
50  * @struts.action-forward name="updateActionPage"
51  * path=".core.actionPage.update"
52  * @struts.action-forward name="listActionPages"
53  * path="/core/actionPage/list.do"
54  * redirect="true"
55  */

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

66     public ActionForward execute(ActionMapping mapping, ActionForm form,
67                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
68
69         if ( isCancelled(request) ) {
70             return mapping.findForward("listActionPages");
71         }
72
73         if ( !request.isUserInRole("core-actionPage-update") && !request.isUserInRole("core-actionPage-updateContent") ) {
74             response.sendError(HttpServletResponse.SC_FORBIDDEN);
75             return null;
76         }
77
78         ActionPageForm actionPageForm = (ActionPageForm) form;
79         Long JavaDoc actionPageId = null;
80         if ( !GenericValidator.isBlankOrNull(actionPageForm.getId()) ) {
81             actionPageId = Long.valueOf(actionPageForm.getId());
82         } else if ( request.getSession().getAttribute(WebappConstants.ACTION_PAGE_ID_KEY) != null ) {
83             actionPageId = (Long JavaDoc) request.getSession().getAttribute(WebappConstants.ACTION_PAGE_ID_KEY);
84         } else {
85             if ( log.isWarnEnabled() ) {
86                 log.warn("Missing action page ID. Returning to list...");
87             }
88             return mapping.findForward("listActionPages");
89         }
90
91         PageManager actionPageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN);
92         ActionPage actionPage = actionPageManager.retrieveActionPage(actionPageId);
93
94         if ( actionPage == null ) {
95             // action page not found. it might be deleted by someone else
96
ActionMessages errors = new ActionMessages();
97             errors.add("actionPageNotFound", new ActionMessage("core.actionPage.errors.notFound"));
98             saveErrors(request, errors);
99             return mapping.findForward("listActionPages");
100         }
101
102         WebappUtil.copyProperties(actionPageForm, actionPage, request);
103         actionPageForm.setTitleMap(actionPage.getTitle());
104         actionPageForm.setDescriptionMap(actionPage.getDescription());
105         actionPageForm.setKeywordsMap(actionPage.getKeywords());
106
107         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
108
109         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
110
111         // save transaction token in request
112
saveToken(request);
113         return mapping.findForward("updateActionPage");
114     }
115
116 }
Popular Tags