Anonymous avatar Anonymous committed 1aefad6

better parsing coce and javadocs

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@647 573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (3)

src/java/com/opensymphony/webwork/dispatcher/StreamResult.java

 /**
  * Implements an XWork Result that takes an InputStream object available from a chained
  * Action and redirects it to the browser.
+ *
  * <p/>
- * The following declaration must be added to the xwork.xml file after the <package>
+ *
+ * The following declaration must be added to the xwork.xml file after the &lt;package&gt;
  * element:
+ *
  * <p/>
- * <result-types>
- * <result-type name="stream" class="StreamResult"/>
- * </result-types>
+ *
+ * <pre>
+ * &lt;result-types&gt;
+ * &lt;result-type name="stream" class="com.opensymphony.webwork.dispatcher.StreamResult"/&gt;
+ * &lt;/result-types&gt;
+ * </pre>
+ *
  * <p/>
+ *
  * To use the stream result type add the following as part of the action declaration:
+ *
  * <p/>
- * <result name="success" type="stream">
- * <param name="contentType">image/jpeg</param>
- * <param name="inputName">imageStream</param>
- * <param name="bufferSize">1024</param>
- * </result>
+ *
+ * <pre>
+ * &lt;result name="success" type="stream"&gt;
+ * &lt;param name="contentType"&gt;image/jpeg&lt/param&gt;
+ * &lt;param name="inputName"&gt;imageStream&lt/param&gt;
+ * &lt;param name="contentDisposition"&gt;filename="document.pdf"&lt/param&gt;
+ * &lt;param name="bufferSize"&gt;1024&lt/param&gt;
+ * &lt;/result&gt;
+ * </pre>
+ *
  * <p/>
- * contentType = the stream mime-type as sent to the web browser
- * contentDispostion = (optional) the content disposition header value (for sending files)
- * inputName = the name of the InputStream property from the chained action (default = "inputStream")
- * bufferSize = the size of the buffer to copy from input to output (defaul = 1024)
+ *
+ * <ul>
+ * <li>contentType - the stream mime-type as sent to the web browser</li>
+ * <li>contentDispostion - (optional) the content disposition header value (for sending files)</li>
+ * <li>inputName - the name of the InputStream property from the chained action (default = "inputStream")</li>
+ * <li>bufferSize - the size of the buffer to copy from input to output (defaul = 1024)</li>
+ * </ul>
  *
  * @author mcrawford
  */
      * @see com.opensymphony.xwork.Result#execute(com.opensymphony.xwork.ActionInvocation)
      */
     protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
-
         // Find the inputstream from the invocation variable stack
-        InputStream oInput = (InputStream) invocation.getStack().findValue(inputName);
+        InputStream oInput = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation));
 
         // Find the Response in context
         HttpServletResponse oResponse = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE);
 
         // Set the content type
-        oResponse.setContentType(contentType);
+        oResponse.setContentType(conditionalParse(contentType, invocation));
 
         // Set the content-disposition
         if (contentDisposition != null) {
-            oResponse.addHeader("Content-Disposition", contentDisposition);
+            oResponse.addHeader("Content-Disposition", conditionalParse(contentDisposition, invocation));
         }
 
         // Get the outputstream

src/java/com/opensymphony/webwork/dispatcher/WebWorkResultSupport.java

      * @throws Exception if an error occurs while executing the result.
      */
     public void execute(ActionInvocation invocation) throws Exception {
-        String finalLocation = location;
+        doExecute(conditionalParse(location, invocation), invocation);
+    }
 
+    protected String conditionalParse(String param, ActionInvocation invocation) {
         if (parse) {
-            OgnlValueStack stack = ActionContext.getContext().getValueStack();
-            finalLocation = TextParseUtil.translateVariables(location, stack);
+            return TextParseUtil.translateVariables(param, invocation.getStack());
+        } else {
+            return param;
         }
-
-        doExecute(finalLocation, invocation);
     }
 
     /**

src/java/com/opensymphony/webwork/views/jasperreports/JasperReportsResult.java

 import com.opensymphony.webwork.dispatcher.WebWorkResultSupport;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.util.OgnlValueStack;
-import com.opensymphony.xwork.util.TextParseUtil;
 import net.sf.jasperreports.engine.*;
 import net.sf.jasperreports.engine.export.*;
 import net.sf.jasperreports.engine.util.JRLoader;
  * <ul>
  * <li>format - the format in which the report should be generated. Valid values can be found
  * in {@link JasperReportConstants}. If no format is specified, PDF will be used.</li>
- * <li>contentDisposition : disposition (default : inline)</li>
+ * <li>contentDisposition : disposition (no default, value is typically <i>filename="document.pdf"</i>)</li>
  * <li>documentName : name of the document (will generate the http header Content-disposition = X; filename=X.[format])</li>
  * </ul>
  * <p/>
         OgnlValueStack stack = invocation.getStack();
         OgnlValueStackDataSource stackDataSource = new OgnlValueStackDataSource(stack, dataSource);
 
-        // parse if needed
-        if (parse) {
-            format = TextParseUtil.translateVariables(format, stack);
-            dataSource = TextParseUtil.translateVariables(dataSource, stack);
+        format = conditionalParse(format, invocation);
+        dataSource = conditionalParse(dataSource, invocation);
 
-            if (contentDisposition != null) {
-            	contentDisposition = TextParseUtil.translateVariables(contentDisposition, stack);
-            }
+        if (contentDisposition != null) {
+            contentDisposition = conditionalParse(contentDisposition, invocation);
+        }
 
-            if (documentName != null) {
-            	documentName = TextParseUtil.translateVariables(documentName, stack);
-            }
+        if (documentName != null) {
+            documentName = conditionalParse(documentName, invocation);
         }
 
         // (Map) ActionContext.getContext().getSession().get("IMAGES_MAP");
 
             // Fill the report and produce a print object
             try {
-    			JasperReport jasperReport = (JasperReport) JRLoader.loadObject(systemId);
-
-    			jasperPrint =
-    				JasperFillManager.fillReport(
-    					jasperReport,
-    					parameters,
-    					stackDataSource
-    					);
+                JasperReport jasperReport = (JasperReport) JRLoader.loadObject(systemId);
+
+                jasperPrint =
+                        JasperFillManager.fillReport(jasperReport,
+                                parameters,
+                                stackDataSource);
             } catch (JRException e) {
                 LOG.error("Error building report for uri " + systemId, e);
                 throw new ServletException(e.getMessage(), e);
             // Export the print object to the desired output format
             try {
                 if (contentDisposition != null || documentName != null) {
-					final StringBuffer tmp = new StringBuffer();
-					tmp.append((contentDisposition == null) ? "inline" : contentDisposition);
-
-					if (documentName != null) {
-						tmp.append("; filename=");
-						tmp.append(documentName);
-						tmp.append(".");
-						tmp.append(format.toLowerCase());
-					}
+                    final StringBuffer tmp = new StringBuffer();
+                    tmp.append((contentDisposition == null) ? "inline" : contentDisposition);
+
+                    if (documentName != null) {
+                        tmp.append("; filename=");
+                        tmp.append(documentName);
+                        tmp.append(".");
+                        tmp.append(format.toLowerCase());
+                    }
 
-					response.setHeader("Content-disposition", tmp.toString());
-				}
+                    response.setHeader("Content-disposition", tmp.toString());
+                }
 
                 if (format.equals(FORMAT_PDF)) {
                     response.setContentType("application/pdf");
      * @param jasperPrint The Print object to render as CSV
      * @param exporter    The exporter to use to export the report
      * @return A CSV formatted report
-     * @throws net.sf.jasperreports.engine.JRException If there is a problem running the report
+     * @throws net.sf.jasperreports.engine.JRException
+     *          If there is a problem running the report
      */
     private byte[] exportReportToBytes(JasperPrint jasperPrint, JRExporter exporter) throws JRException {
         byte[] output;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.