KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentPage > DeleteContentPageAction


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.contentPage;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.ContentPage;
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.ContentPageForm;
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.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
36 /**
37  * <p>Deletes content page
38  * </p>
39  * <p><a HREF="DeleteContentPageAction.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  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
44  * @version $Revision: 1.30 $ $Date: 2006/03/22 11:22:01 $
45  * @struts.action path="/core/contentPage/delete"
46  * name="contentPageForm"
47  * scope="request"
48  * validate="false"
49  * roles="core-contentPage-delete"
50  * @struts.action-forward name="listContentPages"
51  * path="/core/contentPage/list.do"
52  * redirect="true"
53  * @struts.action-forward name="viewLinkedObjects"
54  * path="/core/linkedObjects/view.do"
55  * @struts.action-forward name="unsatisfiable"
56  * path="/core/contentPage/list.do"
57  */

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

68     public ActionForward execute(ActionMapping mapping, ActionForm form,
69                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
70
71         ContentPageForm contentPageForm = (ContentPageForm) form;
72         Long JavaDoc contentPageId = null;
73         if ( contentPageForm.getId() != null ) {
74             contentPageId = Long.valueOf(contentPageForm.getId());
75         } else {
76             if ( log.isWarnEnabled() ) {
77                 log.warn("Missing content page ID. Returning to list...");
78             }
79             return mapping.findForward("listContentPages");
80         }
81
82         PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN);
83         ContentPage contentPage = pageManager.retrieveContentPage(contentPageId);
84         if ( contentPage == null ) {
85             // content page not found. it might be deleted by someone else
86
ActionMessages errors = new ActionMessages();
87             errors.add("contentPageNotFound", new ActionMessage("core.contentPage.errors.notFound"));
88             saveErrors(request, errors);
89             return mapping.findForward("listContentPages");
90         }
91
92         if ( !"true".equalsIgnoreCase(request.getParameter("force")) && contentPage.isInUse() ) {
93             // trying to delete used page - display warning
94
String JavaDoc action = mapping.findForward("listContentPages").getPath();
95             String JavaDoc redirectUrl = WebappUtil.getActionMappingURL(action, null, request, WebappConstants.URL_TYPE_DOMAIN_RELATIVE);
96             request.getSession().setAttribute(WebappConstants.LINKED_OBJECTS_REDIRECT_URL_KEY, redirectUrl);
97             ActionMessages messages = new ActionMessages();
98             messages.add("deleteWarning", new ActionMessage("core.contentPage.messages.deleteWarning"));
99             saveMessages(request, messages);
100             request.getSession().removeAttribute(WebappConstants.LINKED_OBJECTS_UPDATE_ACTION_KEY);
101             request.getSession().setAttribute(WebappConstants.LINKED_OBJECTS_DELETE_ACTION_KEY, "core/contentPage/delete");
102             request.setAttribute(WebappConstants.LINKED_OBJECT_ID_KEY, contentPage.getId());
103             request.setAttribute(WebappConstants.LINKED_OBJECT_TYPE_KEY, "page");
104             saveToken(request);
105             return mapping.findForward("viewLinkedObjects");
106         }
107
108         String JavaDoc uri = contentPage.getUri();
109         pageManager.deleteContentPage(contentPageId);
110
111         //unindex action page
112
SearchManager searchManager = SearchManager.getInstance(request.getSession().getServletContext());
113         searchManager.unIndexPage(uri, request);
114
115         //flush cache
116
CacheUtil cacheUtil = CacheUtil.getInstance(request);
117         cacheUtil.flushPageFieldValueCache(uri);
118         cacheUtil.flushFieldIndices();
119         cacheUtil.flushContentPageCache(uri);
120
121         //flush menu cache
122
cacheUtil.flushMenuCache();
123
124         return mapping.findForward("listContentPages");
125     }
126 }
Popular Tags