1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
package net.smartlab.web; |
24 |
|
|
25 |
|
import java.io.InputStream; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Iterator; |
28 |
|
import java.util.List; |
29 |
|
import java.util.Locale; |
30 |
|
import java.util.MissingResourceException; |
31 |
|
import java.util.Properties; |
32 |
|
import javax.servlet.ServletContext; |
33 |
|
import javax.servlet.http.HttpServletRequest; |
34 |
|
import javax.servlet.http.HttpServletResponse; |
35 |
|
import net.smartlab.web.bean.Valorizer; |
36 |
|
import org.apache.commons.beanutils.locale.LocaleBeanUtilsBean; |
37 |
|
import org.apache.commons.beanutils.locale.LocaleConvertUtilsBean; |
38 |
|
import org.apache.commons.logging.Log; |
39 |
|
import org.apache.commons.logging.LogFactory; |
40 |
|
import org.apache.struts.Globals; |
41 |
|
import org.apache.struts.action.ActionErrors; |
42 |
|
import org.apache.struts.action.ActionForm; |
43 |
|
import org.apache.struts.action.ActionForward; |
44 |
|
import org.apache.struts.action.ActionMapping; |
45 |
|
import org.apache.struts.action.ActionMessage; |
46 |
|
import org.apache.struts.action.ActionMessages; |
47 |
|
import org.apache.struts.action.DynaActionForm; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@author |
55 |
|
@see |
56 |
|
|
57 |
|
|
58 |
|
|
|
|
| 9,3% |
Uncovered Elements: 97 (107) |
Complexity: 35 |
Complexity Density: 0,55 |
|
59 |
|
public abstract class Action extends org.apache.struts.action.Action { |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
public final static ActionForward DEFAULT_FORWARD = new ActionForward("default"); |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
protected final Log logger = LogFactory.getLog(this.getClass()); |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@see |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 10 |
Complexity Density: 0,48 |
|
81 |
0
|
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,... |
82 |
|
HttpServletResponse response) throws Exception { |
83 |
0
|
if (logger.isDebugEnabled()) { |
84 |
0
|
logger.debug("execute(" + mapping.getPath() + ") - start"); |
85 |
|
} |
86 |
0
|
ActionForward forward = null; |
87 |
0
|
if (super.isCancelled(request)) { |
88 |
0
|
if (logger.isDebugEnabled()) { |
89 |
0
|
logger.debug("execute(" + mapping.getPath() + ") - cancel"); |
90 |
|
} |
91 |
0
|
forward = this.cancel(form, request, response, mapping); |
92 |
0
|
if (forward == DEFAULT_FORWARD) { |
93 |
0
|
return mapping.getInputForward(); |
94 |
|
} else { |
95 |
0
|
return forward; |
96 |
|
} |
97 |
|
} |
98 |
0
|
forward = this.execute(form, request, response, mapping); |
99 |
0
|
try { |
100 |
0
|
if (request.getAttribute(Globals.ERROR_KEY) != null && forward == DEFAULT_FORWARD) { |
101 |
0
|
if (logger.isDebugEnabled()) { |
102 |
0
|
logger.debug("execute(" + mapping.getPath() + ") - errors"); |
103 |
0
|
if (logger.isTraceEnabled()) { |
104 |
0
|
logger.trace(" " + request.getAttribute(Globals.ERROR_KEY)); |
105 |
|
} |
106 |
|
} |
107 |
0
|
return mapping.getInputForward(); |
108 |
|
} |
109 |
0
|
return forward; |
110 |
|
} finally { |
111 |
0
|
if (logger.isTraceEnabled()) { |
112 |
0
|
logger.trace(" forward = " + forward); |
113 |
|
} |
114 |
|
} |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@param |
121 |
|
@param |
122 |
|
@param |
123 |
|
@param |
124 |
|
@return |
125 |
|
@throws |
126 |
|
|
127 |
|
|
128 |
|
protected abstract ActionForward execute(ActionForm form, HttpServletRequest request, HttpServletResponse response, |
129 |
|
ActionMapping mapping) throws Exception; |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@param |
138 |
|
@param |
139 |
|
@param |
140 |
|
@param |
141 |
|
@return |
142 |
|
@throws |
143 |
|
|
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0
|
protected ActionForward cancel(ActionForm form, HttpServletRequest request, HttpServletResponse response,... |
146 |
|
ActionMapping mapping) throws Exception { |
147 |
0
|
return DEFAULT_FORWARD; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@param |
156 |
|
|
157 |
|
@param |
158 |
|
@param |
159 |
|
@throws |
160 |
|
|
161 |
|
|
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
162 |
1
|
protected void valorize(ActionForm form, Object bean, Locale locale) throws ActionException {... |
163 |
1
|
try { |
164 |
1
|
if (logger.isDebugEnabled()) { |
165 |
0
|
logger.debug("valorize(" + form + ", " + bean + ") - start"); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
1
|
Valorizer.copy(form, bean, locale); |
170 |
|
} catch (Exception e) { |
171 |
|
logger.error("valorize(" + form + ", " + bean + ") - error", e); |
172 |
|
throw new ActionException("errors.valorize", e); |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
@param |
182 |
|
@param |
183 |
|
|
184 |
|
@param |
185 |
|
@throws |
186 |
|
|
187 |
|
|
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
188 |
1
|
protected void populate(ActionForm form, Object bean, Locale locale) throws ActionException {... |
189 |
1
|
try { |
190 |
1
|
if (logger.isDebugEnabled()) { |
191 |
0
|
logger.debug("populate(" + form + ", " + bean + ") - start"); |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
1
|
Valorizer.copy(bean, form, locale); |
196 |
|
} catch (Exception e) { |
197 |
|
logger.error("populate(" + form + ", " + bean + ") - error", e); |
198 |
|
throw new ActionException("errors.populate", e); |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
@return |
206 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
207 |
0
|
private LocaleBeanUtilsBean getConverter(Locale locale) {... |
208 |
0
|
LocaleConvertUtilsBean converter = new LocaleConvertUtilsBean(); |
209 |
0
|
converter.setDefaultLocale(locale); |
210 |
0
|
return new LocaleBeanUtilsBean(converter); |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
@param |
218 |
|
@param |
219 |
|
@param |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
221 |
0
|
public void reset(ActionForm form, HttpServletRequest request, ActionMapping mapping) {... |
222 |
0
|
if (form instanceof DynaActionForm) { |
223 |
0
|
((DynaActionForm)form).initialize(mapping); |
224 |
|
} else { |
225 |
0
|
form.reset(mapping, request); |
226 |
|
} |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
@param |
233 |
|
@return |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
0
|
protected boolean hasErrors(HttpServletRequest request) {... |
236 |
0
|
return request.getAttribute(Globals.ERROR_KEY) != null; |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
@param |
243 |
|
@param |
244 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
245 |
0
|
protected void addError(ActionMessage message, HttpServletRequest request) {... |
246 |
0
|
this.addError(ActionMessages.GLOBAL_MESSAGE, message, request); |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
@param |
253 |
|
@param |
254 |
|
@param |
255 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
256 |
0
|
protected void addError(String property, ActionMessage message, HttpServletRequest request) {... |
257 |
0
|
ActionErrors errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY); |
258 |
0
|
if (errors == null) { |
259 |
0
|
errors = new ActionErrors(); |
260 |
0
|
request.setAttribute(Globals.ERROR_KEY, errors); |
261 |
|
} |
262 |
0
|
errors.add(property, message); |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
@param |
269 |
|
@param |
270 |
|
@return |
271 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 4 |
Complexity Density: 1,33 |
|
272 |
0
|
public boolean isChecked(String name, HttpServletRequest request) {... |
273 |
0
|
if ("on".equalsIgnoreCase(request.getParameter("group")) |
274 |
|
|| "true".equalsIgnoreCase(request.getParameter("group")) |
275 |
|
|| "yes".equalsIgnoreCase(request.getParameter("group"))) { |
276 |
0
|
return true; |
277 |
|
} else { |
278 |
0
|
return false; |
279 |
|
} |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
@return |
286 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
287 |
0
|
protected ServletContext getServletContext() {... |
288 |
0
|
return super.getServlet().getServletContext(); |
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
@param |
295 |
|
@return |
296 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
297 |
0
|
protected String getRealPath(String path) {... |
298 |
0
|
return this.getServletContext().getRealPath(path); |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
@return |
305 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0,31 |
|
306 |
0
|
protected Properties getProperties() {... |
307 |
0
|
Class type = this.getClass(); |
308 |
0
|
List inputs = new ArrayList(); |
309 |
0
|
Properties result = new Properties(); |
310 |
0
|
while (type.getSuperclass().isAssignableFrom(Action.class)) { |
311 |
0
|
try { |
312 |
0
|
InputStream in = this.getClass().getResourceAsStream(this.getClass().getName() + ".prop"); |
313 |
0
|
inputs.add(in); |
314 |
|
} catch (Exception e) { |
315 |
|
if (logger.isDebugEnabled()) { |
316 |
|
logger.debug("getProperties() - descend", e); |
317 |
|
} |
318 |
|
} |
319 |
0
|
type = type.getSuperclass(); |
320 |
|
} |
321 |
0
|
Iterator iterator = inputs.iterator(); |
322 |
0
|
while (iterator.hasNext()) { |
323 |
0
|
try { |
324 |
0
|
InputStream in = (InputStream)iterator.next(); |
325 |
0
|
Properties properties = new Properties(); |
326 |
0
|
properties.load(in); |
327 |
0
|
result.putAll(properties); |
328 |
|
} catch (Exception e) { |
329 |
|
if (logger.isDebugEnabled()) { |
330 |
|
logger.debug("getProperties() - load", e); |
331 |
|
} |
332 |
|
} |
333 |
|
} |
334 |
0
|
throw new MissingResourceException("No properties defined for action", this.getClass().getName(), null); |
335 |
|
} |
336 |
|
} |