KickJava   Java API By Example, From Geeks To Geeks.

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


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.common.util.QueryInfo;
20 import com.blandware.atleap.model.testimonials.Testimonial;
21 import com.blandware.atleap.service.testimonials.TestimonialManager;
22 import com.blandware.atleap.webapp.action.core.grid.BaseGridAction;
23 import com.blandware.atleap.webapp.taglib.core.grid.util.FilterConditions;
24 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid;
25 import com.blandware.atleap.webapp.taglib.core.grid.util.StringFilter;
26 import com.blandware.atleap.webapp.util.core.WebappConstants;
27 import com.blandware.atleap.webapp.util.core.WebappUtil;
28 import com.blandware.atleap.webapp.util.testimonials.TestimonialModuleWebConstants;
29 import org.apache.struts.Globals;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.ListIterator JavaDoc;
39 import java.util.Locale JavaDoc;
40 import java.util.Map JavaDoc;
41
42 /**
43  * <p>Forwards to the page with testimonials archive
44  * </p>
45  * <p><a HREF="TestimonialArchiveAction.java.htm"><i>View Source</i></a></p>
46  *
47  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
48  * @version $Revision: 1.4 $ $Date: 2005/08/05 17:48:26 $
49  * @struts.action path="/testimonials/showCollection"
50  * name="testimonialForm"
51  * validate="false"
52  * @struts.action-forward name="testimonialsCollection"
53  * path=".testimonials.collection"
54  */

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

65     public ActionForward execute(ActionMapping mapping, ActionForm form,
66                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
67
68
69         Grid testimonialGrid = getGridByName(TestimonialModuleWebConstants.TESTIMONIAL_COLLECTION_GRID, request.getSession());
70         if ( testimonialGrid == null ) {
71             testimonialGrid = new Grid(TestimonialModuleWebConstants.TESTIMONIAL_COLLECTION_GRID);
72         }
73
74         QueryInfo queryInfo = new QueryInfo();
75         StringFilter activeFilter = new StringFilter("testimonial.active");
76         activeFilter.createFirstClause(FilterConditions.STRING_EQUAL, "T");
77         testimonialGrid.addFilter(activeFilter);
78
79         queryInfo.setWhereClause(testimonialGrid.getWhereClause());
80
81         saveGrid(testimonialGrid, request.getSession());
82
83         Map JavaDoc queryParameters = new HashMap JavaDoc();
84         Locale JavaDoc locale = (Locale JavaDoc) request.getSession().getAttribute(Globals.LOCALE_KEY);
85         queryParameters.put("localeIdentifier", locale.getLanguage());
86         queryInfo.setQueryParameters(queryParameters);
87
88         TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN);
89         List JavaDoc testimonials = testimonialManager.listTestimonials(queryInfo).asList();
90
91         // set URI
92
for ( ListIterator JavaDoc i = testimonials.listIterator(); i.hasNext(); ) {
93             Testimonial testimonial = (Testimonial) i.next();
94             Testimonial tmp = new Testimonial();
95             WebappUtil.copyProperties(tmp, testimonial, request);
96             tmp.setUri(WebappUtil.getActionMappingURL(testimonial.getUri(), null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE));
97             i.set(tmp);
98         }
99
100         request.setAttribute(TestimonialModuleWebConstants.TESTIMONIALS_COLLECTION_KEY, testimonials);
101
102         // save transaction token in request
103
saveToken(request);
104         return mapping.findForward("testimonialsCollection");
105     }
106 }
Popular Tags