KickJava   Java API By Example, From Geeks To Geeks.

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


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.model.core.ContentLocale;
19 import com.blandware.atleap.webapp.action.core.BaseAction;
20 import com.blandware.atleap.webapp.form.ContentLocaleForm;
21 import com.blandware.atleap.webapp.util.core.LocaleUtil;
22 import com.blandware.atleap.webapp.util.core.WebappConstants;
23 import com.blandware.atleap.webapp.util.core.WebappUtil;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionMessage;
28 import org.apache.struts.action.ActionMessages;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * <p>Prepares form bean to update content locale's data
36  * </p>
37  * <p><a HREF="CallUpdateContentLocaleAction.java.htm"><i>View Source</i></a></p>
38  * <p/>
39  *
40  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
41  * @version $Revision: 1.15 $ $Date: 2006/03/10 17:10:19 $
42  * @struts.action path="/core/contentLocale/callUpdate"
43  * name="contentLocaleForm"
44  * scope="request"
45  * validate="false"
46  * roles="core-contentLocale-update, core-contentLocale-view"
47  * @struts.action-forward name="updateContentLocale"
48  * path=".core.contentLocale.update"
49  * @struts.action-forward name="listContentLocales"
50  * path="/core/contentLocale/list.do"
51  * redirect="true"
52  */

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

63     public ActionForward execute(ActionMapping mapping, ActionForm form,
64                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
65
66         if ( isCancelled(request) ) {
67             return mapping.findForward("listContentLocales");
68         }
69
70         if (!request.isUserInRole("core-contentLocale-update")) {
71             response.sendError(HttpServletResponse.SC_FORBIDDEN);
72             return null;
73         }
74
75         ContentLocaleForm contentLocaleForm = (ContentLocaleForm) form;
76         String JavaDoc localeIdentifier = null;
77         if ( contentLocaleForm.getIdentifier() != null ) {
78             localeIdentifier = contentLocaleForm.getIdentifier();
79         } else if ( request.getSession().getAttribute(WebappConstants.CONTENT_LOCALE_IDENTIFIER_KEY) != null ) {
80             localeIdentifier = (String JavaDoc) request.getSession().getAttribute(WebappConstants.CONTENT_LOCALE_IDENTIFIER_KEY);
81         } else {
82             if ( log.isWarnEnabled() ) {
83                 log.warn("Missing content locale identifier. Returning to list...");
84             }
85             return mapping.findForward("listContentLocales");
86         }
87
88         ContentLocale contentLocale = LocaleUtil.getInstance(servlet.getServletContext()).retrieveContentLocale(localeIdentifier);
89
90         if ( contentLocale == null ) {
91             // content locale not found. it might be deleted by someone else
92
ActionMessages errors = new ActionMessages();
93             errors.add("contentLocaleNotFound", new ActionMessage("core.contentLocale.errors.notFound"));
94             saveErrors(request, errors);
95             return mapping.findForward("listContentLocales");
96         }
97
98         WebappUtil.copyProperties(contentLocaleForm, contentLocale, request);
99         contentLocaleForm.setTitleMap(contentLocale.getTitle());
100
101
102         // get list of all existent locales
103
List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
104         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
105
106         // save transaction token in request
107
saveToken(request);
108         return mapping.findForward("updateContentLocale");
109     }
110
111 }
Popular Tags