KickJava   Java API By Example, From Geeks To Geeks.

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


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.search.SearchManager;
21 import com.blandware.atleap.service.core.PageManager;
22 import com.blandware.atleap.webapp.action.core.BaseAction;
23 import com.blandware.atleap.webapp.form.ActionPageForm;
24 import com.blandware.atleap.webapp.util.core.CacheUtil;
25 import com.blandware.atleap.webapp.util.core.WebappConstants;
26 import com.blandware.atleap.webapp.util.core.WebappUtil;
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
37 /**
38  * <p>Deletes action page
39  * </p>
40  * <p><a HREF="DeleteActionPageAction.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  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
45  * @version $Revision: 1.30 $ $Date: 2006/03/22 11:22:01 $
46  * @struts.action path="/core/actionPage/delete"
47  * name="actionPageForm"
48  * scope="request"
49  * validate="false"
50  * roles="core-actionPage-delete"
51  * @struts.action-forward name="listActionPages"
52  * path="/core/actionPage/list.do"
53  * redirect="true"
54  * @struts.action-forward name="viewLinkedObjects"
55  * path="/core/linkedObjects/view.do"
56  * @struts.action-forward name="unsatisfiable"
57  * path="/core/actionPage/list.do"
58  */

59 public final class DeleteActionPageAction 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
72         ActionPageForm actionPageForm = (ActionPageForm) form;
73         Long JavaDoc actionPageId = null;
74         if ( !GenericValidator.isBlankOrNull(actionPageForm.getId()) ) {
75             actionPageId = Long.valueOf(actionPageForm.getId());
76         } else {
77             if ( log.isWarnEnabled() ) {
78                 log.warn("Missing action page ID. Returning to list...");
79             }
80             return mapping.findForward("listActionPages");
81         }
82
83         PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN);
84         ActionPage actionPage = pageManager.retrieveActionPage(actionPageId);
85
86         if ( actionPage == null ) {
87             // action page not found. it might be deleted by someone else
88
ActionMessages errors = new ActionMessages();
89             errors.add("actionPageNotFound", new ActionMessage("core.actionPage.errors.notFound"));
90             saveErrors(request, errors);
91             return mapping.findForward("listActionPages");
92         }
93
94         if ( !"true".equalsIgnoreCase(request.getParameter("force")) && actionPage.isInUse() ) {
95             // trying to delete used page - display warning
96
String JavaDoc action = mapping.findForward("listActionPages").getPath();
97             String JavaDoc redirectUrl = WebappUtil.getActionMappingURL(action, null, request, WebappConstants.URL_TYPE_DOMAIN_RELATIVE);
98             request.getSession().setAttribute(WebappConstants.LINKED_OBJECTS_REDIRECT_URL_KEY, redirectUrl);
99             ActionMessages messages = new ActionMessages();
100             messages.add("deleteWarning", new ActionMessage("core.actionPage.messages.deleteWarning"));
101             saveMessages(request, messages);
102             request.getSession().removeAttribute(WebappConstants.LINKED_OBJECTS_UPDATE_ACTION_KEY);
103             request.getSession().setAttribute(WebappConstants.LINKED_OBJECTS_DELETE_ACTION_KEY, "core/actionPage/delete");
104             request.setAttribute(WebappConstants.LINKED_OBJECT_ID_KEY, actionPage.getId());
105             request.setAttribute(WebappConstants.LINKED_OBJECT_TYPE_KEY, "page");
106             saveToken(request);
107             return mapping.findForward("viewLinkedObjects");
108         }
109
110         String JavaDoc uri = actionPage.getUri();
111         pageManager.deleteActionPage(actionPageId);
112
113         //unindex content page
114
SearchManager searchManager = SearchManager.getInstance(request.getSession().getServletContext());
115         searchManager.unIndexPage(uri, request);
116
117         //flush cache
118
CacheUtil cacheUtil = CacheUtil.getInstance(request);
119         cacheUtil.flushPageFieldValueCache(uri);
120         cacheUtil.flushFieldIndices();
121
122         //flush menu cache
123
cacheUtil.flushMenuCache();
124
125         return mapping.findForward("listActionPages");
126     }
127 }
Popular Tags