1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.components;
22
23 import com.opensymphony.xwork2.util.ValueStack;
24 import com.opensymphony.xwork2.util.OgnlUtil;
25
26 import javax.servlet.http.HttpServletResponse;
27 import javax.servlet.http.HttpServletRequest;
28 import java.io.Writer;
29 import java.util.Iterator;
30 import java.util.Map;
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import org.apache.struts2.views.annotations.StrutsTag;
35 import org.apache.struts2.StrutsException;
36
37 @StrutsTag(name="debug", tldTagClass="org.apache.struts2.views.jsp.ui.DebugTag",
38 description="Prints debugging information")
39 public class Debug extends UIBean {
40 public static final String TEMPLATE = "debug";
41
42 public Debug(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
43 super(stack, request, response);
44 }
45
46 protected String getDefaultTemplate() {
47 return TEMPLATE;
48 }
49
50 public boolean start(Writer writer) {
51 boolean result = super.start(writer);
52
53 ValueStack stack = getStack();
54 Iterator iter = stack.getRoot().iterator();
55 List stackValues = new ArrayList(stack.getRoot().size());
56 while (iter.hasNext()) {
57 Object o = iter.next();
58 Map values;
59 try {
60 values = OgnlUtil.getBeanMap(o);
61 } catch (Exception e) {
62 throw new StrutsException("Caught an exception while getting the property values of " + o, e);
63 }
64 stackValues.add(new DebugMapEntry(o.getClass().getName(), values));
65 }
66
67 addParameter("stackValues", stackValues);
68
69 return result;
70 }
71
72 private class DebugMapEntry implements Map.Entry {
73 private Object key;
74 private Object value;
75
76 DebugMapEntry(Object key, Object value) {
77 this.key = key;
78 this.value = value;
79 }
80
81 public Object getKey() {
82 return key;
83 }
84
85 public Object getValue() {
86 return value;
87 }
88
89 public Object setValue(Object newVal) {
90 Object oldVal = value;
91 value = newVal;
92 return oldVal;
93 }
94 }
95
96 }