KickJava   Java API By Example, From Geeks To Geeks.

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


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.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
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 /**
33  * <p>Show testimonial to customer
34  * </p>
35  * <p><a HREF="ShowTestimonialAction.java.htm"><i>View Source</i></a></p>
36  * <p/>
37  *
38  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
39  * @version $Revision: 1.2 $ $Date: 2005/06/24 20:32:55 $
40  * @struts.action path="/testimonials/showTestimonial"
41  * name="testimonialForm"
42  * scope="request"
43  * validate="false"
44  * @struts.action-forward name="viewTestimonial"
45  * path=".testimonials.showTestimonial"
46  * @struts.action-forward name="listTestimonials"
47  * path="/testimonials/list.do"
48  * redirect="true"
49  */

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

60     public ActionForward execute(ActionMapping mapping, ActionForm form,
61                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
62         TestimonialForm testimonialForm = (TestimonialForm) form;
63         Long JavaDoc testimonialId = null;
64         if ( !GenericValidator.isBlankOrNull(testimonialForm.getId()) ) {
65             testimonialId = Long.valueOf(testimonialForm.getId());
66         } else if ( request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY) != null ) {
67             testimonialId = (Long JavaDoc) request.getSession().getAttribute(TestimonialModuleWebConstants.TESTIMONIAL_ID_KEY);
68         } else {
69             if ( log.isWarnEnabled() ) {
70                 log.warn("Missing content page ID. Returning to list...");
71             }
72             return mapping.findForward("listTestimonials");
73         }
74
75         TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN);
76         Testimonial testimonial = testimonialManager.retrieveTestimonial(testimonialId);
77         if ( testimonial == null ) {
78             response.sendError(HttpServletResponse.SC_NOT_FOUND);
79             return null;
80         }
81
82         if ( !testimonial.getActive().booleanValue() ) {
83             response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
84             return null;
85         }
86
87         request.setAttribute("testimonial", testimonial);
88         return mapping.findForward("viewTestimonial");
89     }
90 }
Popular Tags