KickJava   Java API By Example, From Geeks To Geeks.

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


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.WebappUtil;
23 import org.apache.commons.validator.GenericValidator;
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 import org.springframework.orm.ObjectOptimisticLockingFailureException;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 /**
35  * <p>Updates content locale
36  * </p>
37  * <p><a HREF="UpdateContentLocaleAction.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.19 $ $Date: 2006/03/10 17:10:19 $
42  * @struts.action path="/core/contentLocale/update"
43  * name="contentLocaleForm"
44  * scope="request"
45  * input="inputForward"
46  * validate="true"
47  * roles="core-contentLocale-update"
48  * @struts.action-forward name="inputForward"
49  * path=".core.contentLocale.update"
50  * @struts.action-forward name="listContentLocales"
51  * path="/core/contentLocale/list.do"
52  * redirect="true"
53  * @struts.action-forward name="callUpdateContentLocale"
54  * path="/core/contentLocale/callUpdate.do"
55  * redirect="false"
56  * @struts.action-forward name="unsatisfiable"
57  * path="/core/contentLocale/callUpdate.do"
58  */

59 public final class UpdateContentLocaleAction 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         if ( !isCancelled(request) ) {
73             ContentLocaleForm contentLocaleForm = (ContentLocaleForm) form;
74
75             String JavaDoc contentLocaleIdentifier = contentLocaleForm.getIdentifier();
76
77             if ( GenericValidator.isBlankOrNull(contentLocaleIdentifier) ) {
78                 if ( log.isWarnEnabled() ) {
79                     log.warn("Missing content locale identifier. Returning to list...");
80                 }
81                 return mapping.findForward("listContentLocales");
82             }
83
84             ContentLocale contentLocale = LocaleUtil.getInstance(servlet.getServletContext()).retrieveContentLocale(contentLocaleIdentifier);
85
86             if ( contentLocale == null ) {
87                 // content locale not found. it might be deleted by someone else
88
ActionMessages errors = new ActionMessages();
89                 errors.add("contentLocaleNotFound", new ActionMessage("core.contentLocale.errors.notFound"));
90                 saveErrors(request, errors);
91                 return mapping.findForward("listContentLocales");
92             }
93
94             WebappUtil.copyProperties(contentLocale, contentLocaleForm, request);
95             contentLocale.setTitle(contentLocaleForm.getTitleMap());
96
97             try {
98                 LocaleUtil.getInstance(servlet.getServletContext()).updateContentLocale(contentLocale);
99             } catch ( ObjectOptimisticLockingFailureException e ) {
100                 // content locale was updated or deleted by another transaction
101
ActionMessages errors = new ActionMessages();
102                 errors.add("updateFailed", new ActionMessage("core.contentLocale.errors.updateFailed"));
103                 saveErrors(request, errors);
104                 return mapping.findForward("callUpdateContentLocale");
105             }
106         }
107         return mapping.findForward("listContentLocales");
108     }
109 }
Popular Tags