Author: mrdon
Date: Sun Oct  1 04:00:04 2006
New Revision: 451737

URL: http://svn.apache.org/viewvc?view=rev&rev=451737
Log:
Turning off xml output when viewing debug console, exposing result
location information, storing action mapping in context for later
retrieval
WW-1459

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/ServletActionContext.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
    struts/struts2/trunk/core/src/test/resources/struts.xml

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/ServletActionContext.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/ServletActionContext.java?view=diff&rev=451737&r1=451736&r2=451737
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/ServletActionContext.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/ServletActionContext.java
 Sun Oct  1 04:00:04 2006
@@ -24,6 +24,8 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.PageContext;
 
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.util.ValueStack;
 
@@ -38,6 +40,7 @@
        private static final long serialVersionUID = -666854718275106687L;
        
        public static final String STRUTS_VALUESTACK_KEY = "struts.valueStack";
+    public static final String ACTION_MAPPING = "struts.actionMapping";
 
     @SuppressWarnings("unused")
     private ServletActionContext(Map context) {
@@ -67,6 +70,15 @@
      */
     public static ValueStack getValueStack(HttpServletRequest req) {
         return (ValueStack) req.getAttribute(STRUTS_VALUESTACK_KEY);
+    }
+    
+    /**
+     * Gets the action mapping for this context
+     * 
+     * @return The action mapping
+     */
+    public static ActionMapping getActionMapping() {
+        return (ActionMapping) ActionContext.getContext().get(ACTION_MAPPING);
     }
 
     /**

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?view=diff&rev=451737&r1=451736&r2=451737
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
 Sun Oct  1 04:00:04 2006
@@ -375,7 +375,9 @@
         // application map wrapping the ServletContext
         Map application = new ApplicationMap(context);
 
-        return createContextMap(requestMap, params, session, application, 
request, response, context);
+        Map<String,Object> extraContext = createContextMap(requestMap, params, 
session, application, request, response, context);
+        extraContext.put(ServletActionContext.ACTION_MAPPING, mapping);
+        return extraContext;
     }
 
     /**
@@ -388,7 +390,7 @@
      * @param applicationMap a Map of all servlet context attributes.
      * @param request        the HttpServletRequest object.
      * @param response       the HttpServletResponse object.
-     * @param servletContext the ServletContext object.
+     * @param servletContext the ServletContextmapping object.
      * @return a HashMap representing the <tt>Action</tt> context.
      */
     public HashMap<String,Object> createContextMap(Map requestMap,

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java?view=diff&rev=451737&r1=451736&r2=451737
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
 Sun Oct  1 04:00:04 2006
@@ -107,6 +107,7 @@
     protected boolean parse = true;
     protected boolean encode = false;
     protected String location;
+    protected String lastFinalLocation;
 
     /**
      * The location to go to after action execution. This could be a JSP page 
or another action.
@@ -119,6 +120,13 @@
     public void setLocation(String location) {
         this.location = location;
     }
+    
+    /**
+     * Returns the last parsed and encoded location value
+     */
+    public String getLastFinalLocation() {
+        return lastFinalLocation;
+    }
 
     /**
      * Set parse to <tt>true</tt> to indicate that the location should be 
parsed as an OGNL expression. This
@@ -149,7 +157,8 @@
      * @throws Exception if an error occurs while executing the result.
      */
     public void execute(ActionInvocation invocation) throws Exception {
-        doExecute(conditionalParse(location, invocation), invocation);
+        lastFinalLocation = conditionalParse(location, invocation);
+        doExecute(lastFinalLocation, invocation);
     }
     
     /**

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java?view=diff&rev=451737&r1=451736&r2=451737
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
 Sun Oct  1 04:00:04 2006
@@ -85,6 +85,8 @@
 
     private final static String DEBUG_PARAM = "debug";
     private final static String EXPRESSION_PARAM = "expression";
+    
+    private boolean enableXmlWithConsole = false;
 
 
     /**
@@ -126,13 +128,15 @@
                 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);
+                                if (enableXmlWithConsole) {
+                                    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");
@@ -339,5 +343,15 @@
         stack.remove(bean);
     }
 
+
+    /**
+     * @param enableXmlWithConsole the enableXmlWithConsole to set
+     */
+    public void setEnableXmlWithConsole(boolean enableXmlWithConsole) {
+        this.enableXmlWithConsole = enableXmlWithConsole;
+    }
+
+    
+    
 }
 

Modified: struts/struts2/trunk/core/src/test/resources/struts.xml
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/struts.xml?view=diff&rev=451737&r1=451736&r2=451737
==============================================================================
--- struts/struts2/trunk/core/src/test/resources/struts.xml (original)
+++ struts/struts2/trunk/core/src/test/resources/struts.xml Sun Oct  1 04:00:04 
2006
@@ -2,8 +2,6 @@
           "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
           "http://struts.apache.org/dtds/struts-2.0.dtd";>
 <struts>
-    <include file="struts-default.xml"/>
-
     <package name="default" extends="struts-default">
         <action name="hello" class="com.opensymphony.xwork2.ActionSupport">
             <result name="success">hello.jsp</result>


Reply via email to