01: /*
02: * $Id: Debug.java 497654 2007-01-19 00:21:57Z rgielen $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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",description="Prints debugging information")
38: public class Debug extends UIBean {
39: public static final String TEMPLATE = "debug";
40:
41: public Debug(ValueStack stack, HttpServletRequest request,
42: 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(
63: "Caught an exception while getting the property values of "
64: + o, e);
65: }
66: stackValues.add(new DebugMapEntry(o.getClass().getName(),
67: values));
68: }
69:
70: addParameter("stackValues", stackValues);
71:
72: return result;
73: }
74:
75: private class DebugMapEntry implements Map.Entry {
76: private Object key;
77: private Object value;
78:
79: DebugMapEntry(Object key, Object value) {
80: this .key = key;
81: this .value = value;
82: }
83:
84: public Object getKey() {
85: return key;
86: }
87:
88: public Object getValue() {
89: return value;
90: }
91:
92: public Object setValue(Object newVal) {
93: Object oldVal = value;
94: value = newVal;
95: return oldVal;
96: }
97: }
98:
99: }
|