Turning off xml output when viewing debug console, exposing result

location information, storing action mapping in context for later
retrieval
WW-1459


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@451737 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2006-10-01 11:00:04 +00:00
parent f7f738ecbe
commit 6b393a1b26
5 changed files with 47 additions and 12 deletions
@@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest;
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 @@ public class ServletActionContext extends ActionContext implements StrutsStatics
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) {
@@ -68,6 +71,15 @@ public class ServletActionContext extends ActionContext implements StrutsStatics
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);
}
/**
* Returns the HTTP page context.
@@ -375,7 +375,9 @@ public class Dispatcher {
// 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 @@ public class Dispatcher {
* @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,
@@ -107,6 +107,7 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics {
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 abstract class StrutsResultSupport implements Result, StrutsStatics {
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 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics {
* @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);
}
/**
@@ -85,6 +85,8 @@ public class DebuggingInterceptor implements Interceptor {
private final static String DEBUG_PARAM = "debug";
private final static String EXPRESSION_PARAM = "expression";
private boolean enableXmlWithConsole = false;
/**
@@ -126,13 +128,15 @@ public class DebuggingInterceptor implements Interceptor {
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 @@ public class DebuggingInterceptor implements Interceptor {
stack.remove(bean);
}
/**
* @param enableXmlWithConsole the enableXmlWithConsole to set
*/
public void setEnableXmlWithConsole(boolean enableXmlWithConsole) {
this.enableXmlWithConsole = enableXmlWithConsole;
}
}
-2
View File
@@ -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>