Author: plightbo
Date: Fri May 19 13:06:30 2006
New Revision: 407898

URL: http://svn.apache.org/viewvc?rev=407898&view=rev
Log:
put the AC in the session on all requests (if in devMoe)

Modified:
    
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java

Modified: 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java?rev=407898&r1=407897&r2=407898&view=diff
==============================================================================
--- 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java
 (original)
+++ 
struts/action2/trunk/core/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java
 Fri May 19 13:06:30 2006
@@ -17,6 +17,17 @@
  */
 package org.apache.struts.action2.interceptor.debugging;
 
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.interceptor.Interceptor;
+import com.opensymphony.xwork.interceptor.PreResultListener;
+import com.opensymphony.xwork.util.OgnlValueStack;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action2.ServletActionContext;
+import org.apache.struts.action2.views.freemarker.FreemarkerResult;
+
+import javax.servlet.http.HttpServletResponse;
 import java.beans.BeanInfo;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
@@ -25,53 +36,33 @@
 import java.io.StringWriter;
 import java.lang.reflect.Array;
 import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.struts.action2.ServletActionContext;
-import org.apache.struts.action2.views.freemarker.FreemarkerResult;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import com.opensymphony.xwork.ActionContext;
-import com.opensymphony.xwork.ActionInvocation;
-import com.opensymphony.xwork.interceptor.Interceptor;
-import com.opensymphony.xwork.interceptor.PreResultListener;
-import com.opensymphony.xwork.util.OgnlValueStack;
+import java.util.*;
 
 /**
- *  Provides several different debugging screens to provide insight into the
- *  data behind the page. The value of the 'debug' request parameter determines
- *  the screen:
- *  <ul>
- *    <li> <code>xml</code> - Dumps the parameters, context, session, and value
- *    stack as an XML document.</li>
- *    <li> <code>console</code> - Shows a popup 'OGNL Console' that allows the
- *    user to test OGNL expressions against the value stack. The XML data from
- *    the 'xml' mode is inserted at the top of the page.</li>
- *    <li> <code>command</code> - Tests an OGNL expression and returns the
- *    string result. Only used by the OGNL console.</li>
- *  </ul>
- *  <p>
- *
- *  This interceptor only is activated when devMode is enabled in
- *  struts.properties. The 'debug' parameter is removed from the parameter list
- *  before the action is executed. All operations occur before the natural
- *  Result has a chance to execute. </p>
+ * Provides several different debugging screens to provide insight into the
+ * data behind the page. The value of the 'debug' request parameter determines
+ * the screen:
+ * <ul>
+ * <li> <code>xml</code> - Dumps the parameters, context, session, and value
+ * stack as an XML document.</li>
+ * <li> <code>console</code> - Shows a popup 'OGNL Console' that allows the
+ * user to test OGNL expressions against the value stack. The XML data from
+ * the 'xml' mode is inserted at the top of the page.</li>
+ * <li> <code>command</code> - Tests an OGNL expression and returns the
+ * string result. Only used by the OGNL console.</li>
+ * </ul>
+ * <p/>
+ * <p/>
+ * This interceptor only is activated when devMode is enabled in
+ * struts.properties. The 'debug' parameter is removed from the parameter list
+ * before the action is executed. All operations occur before the natural
+ * Result has a chance to execute. </p>
  */
 public class DebuggingInterceptor implements Interceptor {
 
-       private static final long serialVersionUID = -3097324155953078783L;
+    private static final long serialVersionUID = -3097324155953078783L;
 
-       private final static Log log = 
LogFactory.getLog(DebuggingInterceptor.class);
+    private final static Log log = 
LogFactory.getLog(DebuggingInterceptor.class);
 
     private String[] ignorePrefixes = new String[]{"org.apache.struts.",
             "com.opensymphony.xwork.", "xwork."};
@@ -89,12 +80,18 @@
     private final static String EXPRESSION_PARAM = "expression";
 
 
-    /**  Unused. */
-    public void init() { }
+    /**
+     * Unused.
+     */
+    public void init() {
+    }
 
 
-    /**  Unused. */
-    public void destroy() { }
+    /**
+     * Unused.
+     */
+    public void destroy() {
+    }
 
 
     /*
@@ -107,43 +104,41 @@
         Boolean devMode = (Boolean) ActionContext.getContext().get(
                 ActionContext.DEV_MODE);
         boolean cont = true;
-        if (devMode.booleanValue()) {
+        if (devMode) {
             final ActionContext ctx = ActionContext.getContext();
             String type = getParameter(DEBUG_PARAM);
             ctx.getParameters().remove(DEBUG_PARAM);
             if (XML_MODE.equals(type)) {
                 inv.addPreResultListener(
-                    new PreResultListener() {
-                        public void beforeResult(ActionInvocation inv, String 
result) {
-                            printContext();
-                        }
-                    });
+                        new PreResultListener() {
+                            public void beforeResult(ActionInvocation inv, 
String result) {
+                                printContext();
+                            }
+                        });
             } else if (CONSOLE_MODE.equals(type)) {
                 inv.addPreResultListener(
-                    new PreResultListener() {
-                        public void beforeResult(ActionInvocation inv, String 
actionResult) {
-                            StringWriter writer = new StringWriter();
-                            printContext(new PrettyPrintWriter(writer));
-                            String xml = writer.toString();
-                            xml = xml.replaceAll("&", "&amp;");
-                            xml = xml.replaceAll(">", "&gt;");
-                            xml = xml.replaceAll("<", "&lt;");
-                            ActionContext.getContext().put("debugXML", xml);
-
-                            ctx.getSession().put(SESSION_KEY, 
ctx.get(ActionContext.VALUE_STACK));
-
-                            FreemarkerResult result = new FreemarkerResult();
-                            result.setContentType("text/html");
-                            
result.setLocation("org/apache/struts/action2/interceptor/debugging/console.ftl");
-                            result.setParse(false);
-                            try {
-                                result.execute(inv);
-                            } catch (Exception ex) {
-                                log.error("Unable to create debugging 
console", ex);
-                            }
+                        new PreResultListener() {
+                            public void beforeResult(ActionInvocation inv, 
String actionResult) {
+                                StringWriter writer = new StringWriter();
+                                printContext(new PrettyPrintWriter(writer));
+                                String xml = writer.toString();
+                                xml = xml.replaceAll("&", "&amp;");
+                                xml = xml.replaceAll(">", "&gt;");
+                                xml = xml.replaceAll("<", "&lt;");
+                                ActionContext.getContext().put("debugXML", 
xml);
+
+                                FreemarkerResult result = new 
FreemarkerResult();
+                                result.setContentType("text/html");
+                                
result.setLocation("/org/apache/struts/action2/interceptor/debugging/console.ftl");
+                                result.setParse(false);
+                                try {
+                                    result.execute(inv);
+                                } catch (Exception ex) {
+                                    log.error("Unable to create debugging 
console", ex);
+                                }
 
-                        }
-                    });
+                            }
+                        });
             } else if (COMMAND_MODE.equals(type)) {
                 OgnlValueStack stack = (OgnlValueStack) 
ctx.getSession().get(SESSION_KEY);
                 String cmd = getParameter(EXPRESSION_PARAM);
@@ -163,18 +158,25 @@
             }
         }
         if (cont) {
-            return inv.invoke();
-       } else {
+            try {
+                return inv.invoke();
+            } finally {
+                if (devMode) {
+                    final ActionContext ctx = ActionContext.getContext();
+                    ctx.getSession().put(SESSION_KEY, 
ctx.get(ActionContext.VALUE_STACK));
+                }
+            }
+        } else {
             return null;
         }
     }
 
 
     /**
-     *  Gets a single string from the request parameters
+     * Gets a single string from the request parameters
      *
-     [EMAIL PROTECTED]  key  The key
-     [EMAIL PROTECTED]      The parameter value
+     * @param key The key
+     * @return The parameter value
      */
     private String getParameter(String key) {
         String[] arr = (String[]) 
ActionContext.getContext().getParameters().get(key);
@@ -185,7 +187,9 @@
     }
 
 
-    /**  Prints the current context to the response in XML format. */
+    /**
+     * Prints the current context to the response in XML format.
+     */
     protected void printContext() {
         HttpServletResponse res = ServletActionContext.getResponse();
         res.setContentType("text/xml");
@@ -202,9 +206,9 @@
 
 
     /**
-     *  Prints the current request to the existing writer.
+     * Prints the current request to the existing writer.
      *
-     [EMAIL PROTECTED]  writer  The XML writer
+     * @param writer The XML writer
      */
     protected void printContext(PrettyPrintWriter writer) {
         ActionContext ctx = ActionContext.getContext();
@@ -214,12 +218,12 @@
         writer.startNode("context");
         String key;
         Map ctxMap = ctx.getContextMap();
-        for (Iterator i = ctxMap.keySet().iterator(); i.hasNext(); ) {
-            key = i.next().toString();
+        for (Object o : ctxMap.keySet()) {
+            key = o.toString();
             boolean print = !ignoreKeys.contains(key);
 
-            for (int x = 0; x < ignorePrefixes.length; x++) {
-                if (key.startsWith(ignorePrefixes[x])) {
+            for (String ignorePrefixe : ignorePrefixes) {
+                if (key.startsWith(ignorePrefixe)) {
                     print = false;
                     break;
                 }
@@ -239,26 +243,26 @@
 
 
     /**
-     *  Recursive function to serialize objects to XML. Currently it will
-     *  serialize Collections, maps, Arrays, and JavaBeans. It maintains a 
stack
-     *  of objects serialized already in the current functioncall. This is used
-     *  to avoid looping (stack overflow) of circular linked objects. Struts 
and
-     *  XWork objects are ignored.
+     * Recursive function to serialize objects to XML. Currently it will
+     * serialize Collections, maps, Arrays, and JavaBeans. It maintains a stack
+     * of objects serialized already in the current functioncall. This is used
+     * to avoid looping (stack overflow) of circular linked objects. Struts and
+     * XWork objects are ignored.
      *
-     [EMAIL PROTECTED]  bean    The object you want serialized.
-     [EMAIL PROTECTED]  name    The name of the object, used for element 
&lt;name/&gt;
-     [EMAIL PROTECTED]  writer  The XML writer
-     [EMAIL PROTECTED]  stack   List of objects we're serializing since the 
first calling
-     *      of this function (to prevent looping on circular references).
+     * @param bean   The object you want serialized.
+     * @param name   The name of the object, used for element &lt;name/&gt;
+     * @param writer The XML writer
+     * @param stack  List of objects we're serializing since the first calling
+     *               of this function (to prevent looping on circular 
references).
      */
     protected void serializeIt(Object bean, String name,
-            PrettyPrintWriter writer, List stack) {
+                               PrettyPrintWriter writer, List stack) {
         writer.flush();
         // Check stack for this object
         if ((bean != null) && (stack.contains(bean))) {
             if (log.isInfoEnabled()) {
                 log.info("Circular reference detected, not serializing object: 
"
-                         + name);
+                        + name);
             }
             return;
         } else if (bean != null) {
@@ -279,16 +283,15 @@
 
             // Iterate through components, and call ourselves to process
             // elements
-            for (Iterator i = col.iterator(); i.hasNext(); ) {
-                serializeIt(i.next(), "value", writer, stack);
+            for (Object aCol : col) {
+                serializeIt(aCol, "value", writer, stack);
             }
         } else if (bean instanceof Map) {
 
             Map map = (Map) bean;
 
             // Loop through keys and call ourselves
-            for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
-                Object key = i.next();
+            for (Object key : map.keySet()) {
                 Object Objvalue = map.get(key);
                 serializeIt(Objvalue, key.toString(), writer, stack);
             }
@@ -301,7 +304,7 @@
             if (clsName != null && clsName.startsWith("org.apache.struts")) {
                 // ignore
             } else if (clsName != null
-                     && clsName.startsWith("com.opensymphony.xwork")) {
+                    && clsName.startsWith("com.opensymphony.xwork")) {
                 // ignore
             } else if (clsName.startsWith("java.lang")) {
                 writer.setValue(bean.toString());
@@ -312,14 +315,14 @@
                     BeanInfo info = Introspector.getBeanInfo(bean.getClass());
                     PropertyDescriptor[] props = info.getPropertyDescriptors();
 
-                    for (int i = 0; i < props.length; i++) {
-                        String n = props[i].getName();
-                        Method m = props[i].getReadMethod();
+                    for (PropertyDescriptor prop : props) {
+                        String n = prop.getName();
+                        Method m = prop.getReadMethod();
 
                         // Call ourselves with the result of the method
                         // invocation
                         if (m != null) {
-                            serializeIt(m.invoke(bean, null), n, writer, 
stack);
+                            serializeIt(m.invoke(bean), n, writer, stack);
                         }
                     }
                 } catch (Exception e) {


Reply via email to