KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > testimonials > CallUpdateTestimonialBodyAction


1 /*
2  * Copyright 2005 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.testimonials;
17
18 import com.blandware.atleap.common.TestimonialModuleConstants;
19 import com.blandware.atleap.model.testimonials.Testimonial;
20 import com.blandware.atleap.service.testimonials.TestimonialManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.TestimonialForm;
23 import com.blandware.atleap.webapp.util.core.LocaleUtil;
24 import com.blandware.atleap.webapp.util.core.WebappConstants;
25 import com.blandware.atleap.webapp.util.core.WebappUtil;
26 import com.blandware.atleap.webapp.util.testimonials.TestimonialModuleWebConstants;
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 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37
38
39 /**
40  * <p>Prepares form bean to update testimonial body</p>
41  * <p/>
42  * <p><a HREF="CallUpdateTestimonialBodyAction.java.htm"></a><i>View source</i></p>
43  *
44  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
45  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
46  * @version $Revision: 1.9 $ $Date: 2006/03/10 17:10:32 $
47  * @struts.action path="/testimonials/callUpdateTestimonialBody"
48  * input="inputForward"
49  * name="testimonialForm"
50  * scope="request"
51  * validate="false"
52  * roles="testimonials-item-update"
53  * @struts.action-forward name="inputForward"
54  * path=".testimonials.updateTestimonial"
55  * @struts.action-forward name="updateTestimonialBody"
56  * path=".testimonials.updateTestimonialBody"
57  * @struts.action-forward name="listTestimonials"
58  * path="/testimonials/list.do"
59  * redirect="true"
60  */

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

71     public ActionForward execute(ActionMapping mapping, ActionForm form,
72                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
73
74         request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY);
75
76         if ( isCancelled(request) ) {
77             if ( request.getSession().getAttribute(WebappConstants.REDIRECT_URL_KEY) != null ) {
78                 String JavaDoc redirectUrl = (String JavaDoc) request.getSession().getAttribute(WebappConstants.REDIRECT_URL_KEY);
79                 ActionForward redirect = new ActionForward(redirectUrl, true);
80                 return redirect;
81             }
82             return mapping.findForward("listTestimonials");
83         }
84         TestimonialForm testimonialForm = (TestimonialForm) form;
85
86         // Check whether user came here not from previous page (or he switched
87
// edit mode/language during editing testimonial)
88
String JavaDoc localesMode = testimonialForm.getLocalesMode();
89         if ( !"current".equalsIgnoreCase(localesMode) && !"all".equalsIgnoreCase(localesMode) && testimonialForm.getBodyCheckedBoxes().size() == 0 ) {
90             request.setAttribute("beginPage", mapping.findForward("listTestimonials").getPath());
91             return mapping.findForward("unsatisfiablePage");
92         }
93
94         if ( !WebappUtil.hasCorrectValues(testimonialForm.getTitleMap()) ) {
95             // title must be specified
96

97             // check 'check all' ckeckbox if needed
98
testimonialForm.setAllCheckedFlagForBodyCheckboxes(request, localesMode);
99
100             request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY);
101             ActionMessages errors = new ActionMessages();
102             errors.add("title", new ActionMessage("core.commons.errors.required", getMessage(request, "testimonials.form.title")));
103             saveErrors(request, errors, false);
104             saveToken(request);
105             return mapping.getInputForward();
106         }
107
108         Long JavaDoc testimonialId = null;
109         if ( testimonialForm.getId() != null ) {
110             testimonialId = Long.valueOf(testimonialForm.getId());
111         } else if ( request.getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) {
112             testimonialId = (Long JavaDoc) request.getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY);
113         } else if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) {
114             testimonialId = (Long JavaDoc) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY);
115         } else {
116             if ( log.isWarnEnabled() ) {
117                 log.warn("Missing testimonial item ID. Returning to list...");
118             }
119             return mapping.findForward("listTestimonials");
120         }
121
122         if ( !"current".equals(localesMode) && !"all".equals(localesMode) ) {
123             localesMode = "selected";
124         }
125         testimonialForm.setLocalesMode(localesMode);
126
127         TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN);
128         Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId);
129         if ( testimonial == null ) {
130             // testimonial not found. it might be deleted by someone else
131
ActionMessages errors = new ActionMessages();
132             errors.add("testimonialNotFound", new ActionMessage("testimonials.errors.notFound"));
133             saveErrors(request, errors);
134             return mapping.findForward("listTestimonials");
135         }
136
137         if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_MERGED_BODY_KEY) != null ) {
138             Map JavaDoc mergedBody = (Map JavaDoc) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_MERGED_BODY_KEY);
139             testimonialForm.setBodyMap(mergedBody);
140             request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_MERGED_BODY_KEY);
141         }
142
143         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
144
145         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
146
147         // save transaction token in request
148
saveToken(request);
149         return mapping.findForward("updateTestimonialBody");
150     }
151 }
152
Popular Tags