Adding retrieval of result parameters from stack for stream result

WW-1281


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@591531 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2007-11-03 01:18:14 +00:00
parent d643feff6c
commit c3ce93739b
2 changed files with 41 additions and 2 deletions
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
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 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory;
*
* </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 @@ public class StreamResult extends StrutsResultSupport {
*/
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
// Override any parameters using values on the stack
resolveParamsFromStack(invocation.getStack());
OutputStream oOutput = null;
try {
@@ -240,4 +247,36 @@ public class StreamResult extends StrutsResultSupport {
}
}
/**
* 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());
}
}
}
@@ -81,14 +81,14 @@ public class StreamResultTest extends StrutsTestCase {
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"));
}