001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.components;
006:
007: import com.opensymphony.xwork.util.OgnlUtil;
008: import com.opensymphony.xwork.util.OgnlValueStack;
009: import com.opensymphony.webwork.WebWorkException;
010:
011: import javax.servlet.http.HttpServletRequest;
012: import javax.servlet.http.HttpServletResponse;
013: import java.io.Writer;
014: import java.util.ArrayList;
015: import java.util.Iterator;
016: import java.util.List;
017: import java.util.Map;
018:
019: /**
020: * <!-- START SNIPPET: javadoc -->
021: * <p>Renders an debug tag.</P>
022: *
023: * The debug information contain mostly stack information:
024: * <ul>
025: * <li>Value Stack Contents</li>
026: * <li>Stack Context</li>
027: * </ul>
028: * <!-- END SNIPPET: javadoc -->
029: *
030: * <p/> <b>Examples</b>
031: *
032: * <pre>
033: * <!-- START SNIPPET: example -->
034: * <ww:debug/>
035: * <!-- END SNIPPET: example -->
036: * </pre>
037: *
038: * @author Patrick Lightbody
039: * @author Rene Gielen
040: * @author Rainer Hermanns
041: * @version $Revision: 2647 $
042: * @since 2.2
043: *
044: * @ww.tag name="debug" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.DebugTag"
045: * description="Render debug tag"
046: */
047: public class Debug extends UIBean {
048: public static final String TEMPLATE = "debug";
049:
050: public Debug(OgnlValueStack stack, HttpServletRequest request,
051: HttpServletResponse response) {
052: super (stack, request, response);
053: }
054:
055: protected String getDefaultTemplate() {
056: return TEMPLATE;
057: }
058:
059: public boolean start(Writer writer) {
060: boolean result = super .start(writer);
061:
062: OgnlValueStack stack = getStack();
063: Iterator iter = stack.getRoot().iterator();
064: List stackValues = new ArrayList(stack.getRoot().size());
065: while (iter.hasNext()) {
066: Object o = iter.next();
067: Map values;
068: try {
069: values = OgnlUtil.getBeanMap(o);
070: } catch (Exception e) {
071: throw new WebWorkException(
072: "Caught an exception while getting the property values of "
073: + o, e);
074: }
075: stackValues.add(new DebugMapEntry(o.getClass().getName(),
076: values));
077: }
078:
079: addParameter("stackValues", stackValues);
080:
081: return result;
082: }
083:
084: private class DebugMapEntry implements Map.Entry {
085: private Object key;
086: private Object value;
087:
088: DebugMapEntry(Object key, Object value) {
089: this .key = key;
090: this .value = value;
091: }
092:
093: public Object getKey() {
094: return key;
095: }
096:
097: public Object getValue() {
098: return value;
099: }
100:
101: public Object setValue(Object newVal) {
102: Object oldVal = value;
103: value = newVal;
104: return oldVal;
105: }
106: }
107:
108: }
|