KickJava   Java API By Example, From Geeks To Geeks.

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


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.webapp.action.core.BaseAction;
19 import com.blandware.atleap.webapp.form.TestimonialForm;
20 import com.blandware.atleap.webapp.util.core.LocaleUtil;
21 import com.blandware.atleap.webapp.util.core.WebappConstants;
22 import com.blandware.atleap.webapp.util.core.WebappUtil;
23 import com.blandware.atleap.webapp.util.testimonials.TestimonialModuleWebConstants;
24 import org.apache.commons.validator.GenericValidator;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.ActionMessage;
29 import org.apache.struts.action.ActionMessages;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33 import java.util.List JavaDoc;
34
35
36 /**
37  * <p>Prepares form bean to create testimonial body</p>
38  * <p/>
39  * <p><a HREF="CallCreateTestimonialBodyAction.java.htm"></a><i>View source</i></p>
40  *
41  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
42  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
43  * @version $Revision: 1.7 $ $Date: 2006/03/10 17:10:32 $
44  * @struts.action path="/testimonials/callCreateTestimonialBody"
45  * input="inputForward"
46  * name="testimonialForm"
47  * scope="request"
48  * validate="false"
49  * roles="testimonials-item-create"
50  * @struts.action-forward name="inputForward"
51  * path=".testimonials.createTestimonial"
52  * @struts.action-forward name="createTestimonialBody"
53  * path=".testimonials.createTestimonialBody"
54  * @struts.action-forward name="listTestimonials"
55  * path="/testimonials/list.do"
56  * redirect="true"
57  */

58 public final class CallCreateTestimonialBodyAction 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         request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY);
72
73         if ( isCancelled(request) ) {
74             return mapping.findForward("listTestimonials");
75         }
76         TestimonialForm testimonialForm = (TestimonialForm) form;
77
78         // Check whether user came here not from previous page (or he switched
79
// edit mode/languge during creating testimonial)
80
String JavaDoc localesMode = testimonialForm.getLocalesMode();
81         if ( !"current".equalsIgnoreCase(localesMode) && !"all".equalsIgnoreCase(localesMode) && testimonialForm.getBodyCheckedBoxes().size() == 0 ) {
82             request.setAttribute("beginPage", mapping.findForward("listTestimonials").getPath());
83             return mapping.findForward("unsatisfiablePage");
84         }
85
86         if ( !WebappUtil.hasCorrectValues(testimonialForm.getTitleMap()) ) {
87             // title must be specified
88

89             // check 'check all' ckeckbox if needed
90
testimonialForm.setAllCheckedFlagForBodyCheckboxes(request, localesMode);
91
92             request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY);
93             ActionMessages errors = new ActionMessages();
94             errors.add("title", new ActionMessage("core.commons.errors.required", getMessage(request, "testimonials.form.title")));
95             saveErrors(request, errors, false);
96             saveToken(request);
97             return mapping.getInputForward();
98         }
99
100         String JavaDoc redirectUrl = request.getParameter("redirectUrl");
101         if ( GenericValidator.isBlankOrNull(redirectUrl) ) {
102             redirectUrl = (String JavaDoc) request.getAttribute(WebappConstants.REDIRECT_URL_KEY);
103         }
104         if ( !GenericValidator.isBlankOrNull(redirectUrl) ) {
105             request.getSession().setAttribute(WebappConstants.REDIRECT_URL_KEY, redirectUrl);
106         } else {
107             request.getSession().removeAttribute(WebappConstants.REDIRECT_URL_KEY);
108         }
109
110         if ( !"current".equals(localesMode) && !"all".equals(localesMode) ) {
111             localesMode = "selected";
112         }
113         testimonialForm.setLocalesMode(localesMode);
114
115         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
116
117         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
118
119         // save transaction token in request
120
saveToken(request);
121         return mapping.findForward("createTestimonialBody");
122     }
123 }
124
Popular Tags