KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.testimonials.TestimonialModuleWebConstants;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * <p>Exposes bean to request to view its properties on JSP page (testimonial is
38  * to be viewed)
39  * </p>
40  * <p><a HREF="ViewTestimonialAction.java.htm"><i>View Source</i></a></p>
41  * <p/>
42  *
43  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
44  * @version $Revision: 1.6 $ $Date: 2006/03/10 17:10:33 $
45  * @struts.action path="/testimonials/viewTestimonial"
46  * name="testimonialForm"
47  * scope="request"
48  * validate="false"
49  * roles="testimonials-item-view"
50  * @struts.action-forward name="viewTestimonial"
51  * path=".testimonials.viewTestimonial"
52  * @struts.action-forward name="listTestimonials"
53  * path="/testimonials/list.do"
54  * redirect="true"
55  */

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

66     public ActionForward execute(ActionMapping mapping, ActionForm form,
67                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
68         TestimonialForm testimonialForm = (TestimonialForm) form;
69         Long JavaDoc testimonialId = null;
70         if ( testimonialForm.getId() != null ) {
71             testimonialId = Long.valueOf(testimonialForm.getId());
72         } else if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) {
73             testimonialId = (Long JavaDoc) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY);
74         } else {
75             if ( log.isWarnEnabled() ) {
76                 log.warn("Missing content page ID. Returning to list...");
77             }
78             return mapping.findForward("listTestimonials");
79         }
80
81         TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN);
82         Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId);
83         if ( testimonial == null ) {
84             // testimonial not found. it might be deleted by someone else
85
ActionMessages errors = new ActionMessages();
86             errors.add("testimonialNotFound", new ActionMessage("testimonials.errors.notFound"));
87             saveErrors(request, errors);
88             return mapping.findForward("listTestimonials");
89         }
90
91         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
92
93         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
94
95         request.setAttribute("testimonial", testimonial);
96         return mapping.findForward("viewTestimonial");
97     }
98 }
Popular Tags