Author: ivaynberg
Date: Sun Feb 28 19:30:24 2010
New Revision: 917266

URL: http://svn.apache.org/viewvc?rev=917266&view=rev
Log:
improved content disposition api and handling

Added:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/ContentDisposition.java
   (with props)
Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestHandler.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java?rev=917266&r1=917265&r2=917266&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java
 Sun Feb 28 19:30:24 2010
@@ -21,13 +21,13 @@
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
 import org.apache.wicket.ng.request.cycle.RequestCycle;
+import org.apache.wicket.ng.resource.ContentDisposition;
 import org.apache.wicket.protocol.http.WicketURLEncoder;
 import org.apache.wicket.request.target.resource.ResourceStreamRequestHandler;
 import org.apache.wicket.util.resource.FileResourceStream;
 import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.string.Strings;
 
-
 /**
  * A link that streams a file to the client. When clicked this link will 
prompt the save as dialog
  * in the browser.
@@ -151,12 +151,6 @@
                        new ResourceStreamRequestHandler(resourceStream)
                        {
                                @Override
-                               public String getFileName()
-                               {
-                                       return fn;
-                               }
-
-                               @Override
                                public void respond(RequestCycle requestCycle)
                                {
                                        super.respond(requestCycle);
@@ -166,7 +160,7 @@
                                                file.delete();
                                        }
                                }
-                       });
+                       
}.setFileName(fn).setContentDisposition(ContentDisposition.ATTACHMENT));
        }
 
        /**

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java?rev=917266&r1=917265&r2=917266&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
 Sun Feb 28 19:30:24 2010
@@ -58,23 +58,6 @@
        protected abstract ResourceResponse newResourceResponse(Attributes 
attributes);
 
        /**
-        * Represents content disposition of a resource
-        * 
-        * @author Matej Knopp
-        */
-       public enum ContentDisposition {
-               /**
-                * Inline resources are usually displayed within the browser 
window
-                */
-               INLINE,
-
-               /**
-                * For attachment resources the browser should display a save 
dialog
-                */
-               ATTACHMENT;
-       };
-
-       /**
         * Represents data used to configure response and write resource data.
         * 
         * @author Matej Knopp

Added: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/ContentDisposition.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/ContentDisposition.java?rev=917266&view=auto
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/ContentDisposition.java
 (added)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/ContentDisposition.java
 Sun Feb 28 19:30:24 2010
@@ -0,0 +1,18 @@
+package org.apache.wicket.ng.resource;
+
+/**
+ * Represents content disposition of a resource
+ * 
+ * @author Matej Knopp
+ */
+public enum ContentDisposition {
+       /**
+        * Inline resources are usually displayed within the browser window
+        */
+       INLINE,
+
+       /**
+        * For attachment resources the browser should display a save dialog
+        */
+       ATTACHMENT;
+}
\ No newline at end of file

Propchange: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/ContentDisposition.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestHandler.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestHandler.java?rev=917266&r1=917265&r2=917266&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestHandler.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestHandler.java
 Sun Feb 28 19:30:24 2010
@@ -18,13 +18,13 @@
 
 import org.apache.wicket.IRequestHandler;
 import org.apache.wicket.ng.request.cycle.RequestCycle;
+import org.apache.wicket.ng.resource.ContentDisposition;
 import org.apache.wicket.ng.resource.ResourceStreamResource;
 import org.apache.wicket.ng.resource.IResource.Attributes;
 import org.apache.wicket.util.resource.IResourceStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * Request target that responds by sending its resource stream.
  * 
@@ -40,6 +40,7 @@
         * with web requests.
         */
        private String fileName;
+       private ContentDisposition contentDisposition;
 
        /** the resource stream for the response. */
        private final IResourceStream resourceStream;
@@ -95,7 +96,7 @@
         * @return Optional filename, used to set the content disposition 
header. Only meaningful when
         *         using with web requests.
         */
-       public String getFileName()
+       public final String getFileName()
        {
                return fileName;
        }
@@ -134,7 +135,7 @@
 
                ResourceStreamResource resource = new 
ResourceStreamResource(resourceStream);
                resource.setFileName(fileName);
-
+               resource.setContentDisposition(contentDisposition);
                resource.respond(attributes);
        }
 
@@ -145,7 +146,7 @@
         * 
         * @return The this.
         */
-       public ResourceStreamRequestHandler setFileName(String fileName)
+       public final ResourceStreamRequestHandler setFileName(String fileName)
        {
                this.fileName = fileName;
                return this;
@@ -158,7 +159,20 @@
        public String toString()
        {
                return "[ResourceStreamRequestTarget[resourceStream=" + 
resourceStream + ",fileName=" +
-                       fileName + "]";
+                       fileName + ", contentDisposition=" + contentDisposition 
+ "]";
+       }
+
+       public final ContentDisposition getContentDisposition()
+       {
+               return contentDisposition;
        }
 
+       public final ResourceStreamRequestHandler setContentDisposition(
+               ContentDisposition contentDisposition)
+       {
+               this.contentDisposition = contentDisposition;
+               return this;
+       }
+
+
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=917266&r1=917265&r2=917266&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
 Sun Feb 28 19:30:24 2010
@@ -1517,7 +1517,7 @@
         */
        public String getContentTypeFromResponseHeader()
        {
-               String contentType = 
getLastResponse().getHeader("Content-Type");
+               String contentType = getLastResponse().getContentType();
                if (contentType == null)
                {
                        throw new WicketRuntimeException("No Content-Type 
header found");


Reply via email to