You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2007/11/03 02:18:16 UTC
svn commit: r591531 - in /struts/struts2/trunk/core/src:
main/java/org/apache/struts2/dispatcher/StreamResult.java
test/java/org/apache/struts2/dispatcher/StreamResultTest.java
Author: mrdon
Date: Fri Nov 2 18:18:14 2007
New Revision: 591531
URL: http://svn.apache.org/viewvc?rev=591531&view=rev
Log:
Adding retrieval of result parameters from stack for stream result
WW-1281
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java?rev=591531&r1=591530&r2=591531&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StreamResult.java Fri Nov 2 18:18:14 2007
@@ -28,6 +28,7 @@
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: description -->
@@ -61,6 +62,9 @@
*
* </ul>
*
+ * <p>These parameters can also be set by exposing a similarly named getter method on your Action. For example, you can
+ * provide <code>getContentType()</code> to override that parameter for the current action.</p>N
+ *
* <!-- END SNIPPET: params -->
*
* <b>Example:</b>
@@ -173,6 +177,9 @@
*/
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+ // Override any parameters using values on the stack
+ resolveParamsFromStack(invocation.getStack());
+
OutputStream oOutput = null;
try {
@@ -237,6 +244,38 @@
finally {
if (inputStream != null) inputStream.close();
if (oOutput != null) oOutput.close();
+ }
+ }
+
+ /**
+ * Tries to lookup the parameters on the stack. Will override any existing parameters
+ *
+ * @param stack The current value stack
+ */
+ protected void resolveParamsFromStack(ValueStack stack) {
+ String disposition = stack.findString("contentDisposition");
+ if (disposition != null) {
+ setContentDisposition(disposition);
+ }
+
+ String contentType = stack.findString("contentType");
+ if (contentType != null) {
+ setContentLength(contentType);
+ }
+
+ String inputName = stack.findString("inputName");
+ if (inputName != null) {
+ setInputName(inputName);
+ }
+
+ String contentLength = stack.findString("contentLength");
+ if (contentLength != null) {
+ setContentLength(contentLength);
+ }
+
+ Integer bufferSize = (Integer) stack.findValue("bufferSize", Integer.class);
+ if (bufferSize != null) {
+ setBufferSize(bufferSize.intValue());
}
}
Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java?rev=591531&r1=591530&r2=591531&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StreamResultTest.java Fri Nov 2 18:18:14 2007
@@ -81,14 +81,14 @@
result.doExecute("helloworld", mai);
- assertEquals(null, result.getContentLength());
+ assertEquals("1185", result.getContentLength());
assertEquals("text/plain", result.getContentType());
assertEquals("streamForImage", result.getInputName());
assertEquals(1024, result.getBufferSize()); // 1024 is default
assertEquals("inline", result.getContentDisposition());
assertEquals("text/plain", response.getContentType());
- assertEquals(0, response.getContentLength());
+ assertEquals(1185, response.getContentLength());
assertEquals("inline", response.getHeader("Content-disposition"));
}