KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.testimonials.TestimonialModuleWebConstants;
23 import com.blandware.atleap.model.core.ContentLocale;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 /**
35  * <p>Returns page with form to create new testimonial
36  * </p>
37  * <p><a HREF="CallCreateTestimonialAction.java.htm"><i>View Source</i></a></p>
38  * <p/>
39  *
40  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
41  * @version $Revision: 1.10 $ $Date: 2006/03/10 17:10:32 $
42  * @struts.action path="/testimonials/callCreateTestimonial"
43  * name="testimonialForm"
44  * validate="false"
45  * roles="testimonials-item-create"
46  * scope="request"
47  * @struts.action-forward name="createTestimonial"
48  * path=".testimonials.createTestimonial"
49  * @struts.action-forward name="listTestimonials"
50  * path="/testimonials/list.do"
51  * redirect="true"
52  */

53 public final class CallCreateTestimonialAction 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         TestimonialForm testimonialForm = (TestimonialForm) form;
67
68         request.getSession().removeAttribute(TestimonialModuleWebConstants.TESTIMONIAL_SUBMITTED_ACTION_KEY);
69
70         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
71         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
72
73         String JavaDoc localesMode = testimonialForm.getLocalesMode();
74         if ( !"current".equalsIgnoreCase(localesMode) && !"all".equalsIgnoreCase(localesMode) ) {
75             localesMode = "selected";
76         }
77         testimonialForm.setLocalesMode(localesMode);
78
79         if ("selected".equalsIgnoreCase(localesMode)) {
80             // mark all locales as checked
81
Map JavaDoc bodyCheckedBoxes = testimonialForm.getBodyCheckedBoxes();
82             for (Iterator JavaDoc i = contentLocales.iterator(); i.hasNext();) {
83                 ContentLocale contentLocale = (ContentLocale) i.next();
84                 bodyCheckedBoxes.put(contentLocale.getIdentifier(), Boolean.TRUE);
85             }
86
87             // check 'check all' ckeckbox
88
request.setAttribute(WebappConstants.SELECT_ALL_LOCALES_CHECKBOX_IS_CHECKED, Boolean.TRUE);
89         }
90
91         // save transaction token in request
92
saveToken(request);
93         return mapping.findForward("createTestimonial");
94     }
95 }
Popular Tags