KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentLocale > DeleteContentLocaleAction


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.contentLocale;
17
18 import com.blandware.atleap.persistence.exception.DeleteException;
19 import com.blandware.atleap.search.SearchManager;
20 import com.blandware.atleap.service.exception.BeanNotFoundException;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.ContentLocaleForm;
23 import com.blandware.atleap.webapp.util.core.CacheUtil;
24 import com.blandware.atleap.webapp.util.core.LocaleUtil;
25 import org.apache.commons.validator.GenericValidator;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 /**
36  * <p>Deletes content locale
37  * </p>
38  * <p><a HREF="DeleteContentLocaleAction.java.htm"><i>View Source</i></a></p>
39  * <p/>
40  *
41  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
42  * @version $Revision: 1.28 $ $Date: 2006/03/10 17:10:19 $
43  * @struts.action path="/core/contentLocale/delete"
44  * name="contentLocaleForm"
45  * input="inputForward"
46  * scope="request"
47  * validate="false"
48  * roles="core-contentLocale-delete"
49  * @struts.action-forward name="listContentLocales"
50  * path="/core/contentLocale/list.do"
51  * redirect="true"
52  * @struts.action-forward name="inputForward"
53  * path=".core.contentLocale.list"
54  * @struts.action-forward name="unsatisfiable"
55  * path="/core/contentLocale/list.do"
56  */

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

67     public ActionForward execute(ActionMapping mapping, ActionForm form,
68                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
69
70
71         ContentLocaleForm contentLocaleForm = (ContentLocaleForm) form;
72         String JavaDoc contentLocaleIdentifier = null;
73         if ( !GenericValidator.isBlankOrNull(contentLocaleForm.getIdentifier()) ) {
74             contentLocaleIdentifier = contentLocaleForm.getIdentifier();
75         } else {
76             if ( log.isWarnEnabled() ) {
77                 log.warn("Missing content locale identifier. Returning to list...");
78             }
79             return mapping.findForward("listContentLocales");
80         }
81
82         try {
83             LocaleUtil.getInstance(servlet.getServletContext()).deleteContentLocale(contentLocaleIdentifier);
84
85             // drop resource bundle for deleted locale
86
// ApplicationResources.getInstance(servlet.getServletContext()).dropBundle(contentLocaleIdentifier);
87

88             //remove from search index
89
SearchManager searchManager = SearchManager.getInstance(servlet.getServletContext());
90             searchManager.unIndexByLocale(contentLocaleIdentifier, request);
91
92             //remove from cache
93
CacheUtil cacheUtil = CacheUtil.getInstance(request);
94             cacheUtil.flushAllCache();
95
96         } catch ( BeanNotFoundException e ) {
97             // content locale not found. it might be deleted by someone else
98
ActionMessages errors = new ActionMessages();
99             errors.add("contentLocaleNotFound", new ActionMessage("core.contentLocale.errors.notFound"));
100             saveErrors(request, errors);
101             return mapping.findForward("listContentLocales");
102         } catch ( DeleteException e ) {
103             saveToken(request);
104             ActionMessages errors = new ActionMessages();
105             errors.add("contentLocaleCannotDelete", new ActionMessage("core.contentLocale.errors.cannotDelete"));
106             saveErrors(request, errors);
107             return mapping.findForward("listContentLocales");
108         }
109
110         return mapping.findForward("listContentLocales");
111     }
112 }
Popular Tags