1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.sourceforge.servletspy.handler.struts;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Map;
29
30 import net.sourceforge.servletspy.IContext;
31 import net.sourceforge.servletspy.IContextHandler;
32 import net.sourceforge.servletspy.config.Param;
33
34 import org.apache.struts.action.ActionErrors;
35 import org.apache.struts.action.DynaActionForm;
36
37 /***
38 * @author arno schumacher
39 */
40 public class StrutsHandler implements IContextHandler {
41
42
43
44
45
46 public void handle(IContext context) throws Exception {
47
48
49 if (context.getSubject() instanceof ActionErrors) {
50 final ActionErrors errors = (ActionErrors) context.getSubject();
51 final Iterator it = errors.properties();
52 final Map map = new HashMap();
53
54 while (it.hasNext()) {
55 final String key = it.next().toString();
56 final Object value = errors.get(key);
57 final Iterator errorIt = (Iterator) value;
58 final List errorList = new ArrayList();
59
60 while (errorIt.hasNext()) {
61 errorList.add(errorIt.next());
62 }
63
64 map.put(key, errorList);
65 }
66
67 context.setSubject(map);
68 } else if (context.getSubject() instanceof DynaActionForm) {
69 context
70 .setSubject(((DynaActionForm) context.getSubject())
71 .getMap());
72 }
73 context.proceed();
74 }
75
76
77
78
79
80
81 public void init(Param[] params) {
82 }
83
84
85
86
87
88
89 public void destroy() {
90 }
91 }