Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../img/srcFileCovDistChart0.png 29% of files have more coverage
29   222   16   5,8
18   78   0,55   5
5     3,2  
1    
1,9% of code in this file is excluded from these metrics.
 
  AbstractArchiveAction       Line # 47 29 16 0% 0.0
 
No Tests
 
1    /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10    * This library is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this library; if not, write to the Free Software
17    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18    *
19    * For further informations on the SmartWeb Framework please visit
20    *
21    * http://smartweb.sourceforge.net
22    */
23    package net.smartlab.web;
24   
25    import java.beans.Introspector;
26    import java.beans.PropertyDescriptor;
27    import java.util.ArrayList;
28    import java.util.List;
29    import javax.servlet.ServletRequest;
30    import javax.servlet.http.HttpServletRequest;
31    import javax.servlet.http.HttpServletResponse;
32    import net.smartlab.web.DataAccessObject.SearchInfo;
33    import org.apache.struts.action.ActionForm;
34    import org.apache.struts.action.ActionMapping;
35    import org.apache.struts.action.DynaActionForm;
36   
37    /**
38    * This is the base action for generic archive management. The class provides
39    * template methods for common archive management operations and provides
40    * support methods to handle common problems like multiple selections and search
41    * criteria.
42    *
43    * @author rlogiacco
44    * @uml.dependency supplier="net.smartlab.web.EmptyMarkerTag"
45    * @uml.dependency supplier="net.smartlab.web.Validator"
46    */
 
47    public abstract class AbstractArchiveAction extends DynaAction {
48   
49    /**
50    * The standard name for a multiple selection request parameter.
51    */
52    public final static String SELECTION = "selection";
53   
54   
55    /**
56    * This action method should be invoked to list items matching a set of
57    * specified criteria.
58    *
59    * @param form the html form submitted with this request.
60    * @param request the user request.
61    * @param response the representation of the response channel.
62    * @param mapping the system control mapping.
63    * @return the name of a defined global or local forward.
64    * @throws Exception if something unexpected happend during the request
65    * execution.
66    */
67    public abstract String search(ActionForm form, HttpServletRequest request, HttpServletResponse response,
68    ActionMapping mapping) throws Exception;
69   
70    /**
71    * This action method should be invoked to retrieve a specific item.
72    *
73    * @param form the html form submitted with this request.
74    * @param request the user request.
75    * @param response the representation of the response channel.
76    * @param mapping the system control mapping.
77    * @return the name of a defined global or local forward.
78    * @throws Exception if something unexpected happend during the request
79    * execution.
80    */
81    public abstract String select(ActionForm form, HttpServletRequest request, HttpServletResponse response,
82    ActionMapping mapping) throws Exception;
83   
84    /**
85    * This action method should be invoked to save or update an item.
86    *
87    * @param form the html form submitted with this request.
88    * @param request the user request.
89    * @param response the representation of the response channel.
90    * @param mapping the system control mapping.
91    * @return the name of a defined global or local forward.
92    * @throws Exception if something unexpected happend during the request
93    * execution.
94    */
95    public abstract String update(ActionForm form, HttpServletRequest request, HttpServletResponse response,
96    ActionMapping mapping) throws Exception;
97   
98    /**
99    * This action method should be invoked to permanently remove an item.
100    *
101    * @param form the html form submitted with this request.
102    * @param request the user request.
103    * @param response the representation of the response channel.
104    * @param mapping the system control mapping.
105    * @return the name of a defined global or local forward.
106    * @throws Exception if something unexpected happend during the request
107    * execution.
108    */
109    public abstract String remove(ActionForm form, HttpServletRequest request, HttpServletResponse response,
110    ActionMapping mapping) throws Exception;
111   
112    /**
113    * This action method should be invoked to permanently remove a set of
114    * items.
115    *
116    * @param form the html form submitted with this request.
117    * @param request the user request.
118    * @param response the representation of the response channel.
119    * @param mapping the system control mapping.
120    * @return the name of a defined global or local forward.
121    * @throws Exception if something unexpected happend during the request
122    * execution.
123    */
124    public abstract String removeAll(ActionForm form, HttpServletRequest request, HttpServletResponse response,
125    ActionMapping mapping) throws Exception;
126   
127    /**
128    * TODO documentation
129    *
130    * @param request the user request.
131    * @return
132    */
 
133  0 toggle public String[] getListSelection(ServletRequest request) {
134  0 return request.getParameterValues("selection");
135    }
136   
137    /**
138    * TODO documentation
139    *
140    * @param request the user request.
141    * @param form
142    * @param name
143    * @return
144    */
 
145  0 toggle public String[] getSelection(ActionForm form, String name) {
146  0 String[] values = null;
147  0 if (form instanceof DynaActionForm) {
148  0 values = (String[])((DynaActionForm)form).get(name);
149    } else {
150  0 try {
151  0 PropertyDescriptor[] descriptors = Introspector.getBeanInfo(form.getClass()).getPropertyDescriptors();
152  0 for (int i = 0; i < descriptors.length; i++) {
153  0 if (descriptors[i].getName().equals(name)) {
154  0 values = (String[])descriptors[i].getReadMethod().invoke(form, null);
155    }
156    }
157    } catch (Exception e) {
158    // FIXME
159    logger.warn(e);
160    }
161    }
162  0 if (values.length == 0) {
163  0 return null;
164  0 } else if (values.length == 1 && EmptyMarkerTag.EMPTY_MARKER.equals(values[0])) {
165  0 return new String[0];
166    } else {
167  0 List selection = new ArrayList();
168  0 for (int i = 0; i < values.length; i++) {
169  0 if (!EmptyMarkerTag.EMPTY_MARKER.equals(values[i])) {
170  0 selection.add(values[i]);
171    }
172    }
173  0 return (String[])selection.toArray(new String[selection.size()]);
174    }
175    }
176   
177    /**
178    * TODO documentation
179    *
180    * @param form
181    * @param name
182    * @param values
183    */
 
184  0 toggle public void setSelection(ActionForm form, String name, String[] values) {
185  0 if (form instanceof DynaActionForm) {
186  0 ((DynaActionForm)form).set(name, values);
187    } else {
188    // FIXME
189  0 throw new ClassCastException();
190    }
191    }
192   
193    /**
194    * TODO documentation
195    *
196    * @param form
197    * @param name
198    */
 
199  0 toggle public void resetSelection(ActionForm form, String name) {
200  0 if (form instanceof DynaActionForm) {
201  0 ((DynaActionForm)form).set(name, new String[0]);
202    } else {
203    // FIXME
204  0 throw new ClassCastException();
205    }
206    }
207   
208    /**
209    * Parses the request searching for standard filtering and ordering
210    * parameters.
211    *
212    * @param request the received request.
213    * @return filtering and ordering parameters.
214    */
 
215  0 toggle public SearchInfo getSearchInfo(ServletRequest request) {
216  0 SearchInfo info = new SearchInfo();
217  0 info.setFilters(request.getParameterValues("filter"));
218  0 info.setUnion(request.getParameter("union"));
219  0 info.setOrder(request.getParameter("order"));
220  0 return info;
221    }
222    }