Repository: wicket
Updated Branches:
  refs/heads/WICKET-6286-ajax-download 9292740e4 -> 0b7937185


WICKET-6286 Ajax Download

Minor improvements


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/0b793718
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/0b793718
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/0b793718

Branch: refs/heads/WICKET-6286-ajax-download
Commit: 0b793718585d8cb8c229e13fea4c16eaf23894fa
Parents: 9292740
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Wed Jan 4 23:11:47 2017 +0100
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Wed Jan 4 23:11:47 2017 +0100

----------------------------------------------------------------------
 .../examples/ajax/builtin/AjaxDownloadPage.html |  8 +++---
 .../examples/ajax/builtin/AjaxDownloadPage.java | 16 ++++++-----
 .../wicket/extensions/ajax/AjaxDownload.java    | 28 +++++++++++---------
 3 files changed, 29 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/0b793718/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.html
----------------------------------------------------------------------
diff --git 
a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.html
 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.html
index cbee184..2764b25 100644
--- 
a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.html
+++ 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.html
@@ -8,11 +8,11 @@
                left: 20%;
                right: 20%;
                color: white;
-               background-color: #E9601A80;
+               background-color: darkorange;
                font-size: 40px;
                text-align: center;
        }
-       
+
        .download-veil span {
                line-height: 128px;
        }
@@ -20,7 +20,7 @@
 </wicket:head>
 </head>
 <body>
-<wicket:extend xmlns:wicket="http://wicket.apache.org";>
+<wicket:extend>
 
 <p>
 This example demonstrates a <a wicket:id="download">download</a> initiated via 
Ajax.
@@ -38,4 +38,4 @@ A resource reference can be <a 
wicket:id="downloadReference">used too</a>.
 
 </wicket:extend>
 </body>
-</html>
\ No newline at end of file
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/0b793718/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
----------------------------------------------------------------------
diff --git 
a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
index 52520e0..a23368c 100644
--- 
a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
+++ 
b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AjaxDownloadPage.java
@@ -29,6 +29,8 @@ import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.resource.StringResourceStream;
 import org.apache.wicket.util.time.Duration;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * Ajax download.
  * 
@@ -62,7 +64,7 @@ public class AjaxDownloadPage extends BasePage
                                // simulate delay
                                try
                                {
-                                       Thread.sleep(5000);
+                                       TimeUnit.MILLISECONDS.sleep(5000);
                                }
                                catch (InterruptedException e)
                                {
@@ -71,7 +73,7 @@ public class AjaxDownloadPage extends BasePage
                                return new StringResourceStream("downloaded via 
ajax");
                        };
                        
-               
}.setFileName("file").setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.NONE);
+               
}.setFileName("File-from-IResource.txt").setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.NONE);
                
                final AjaxDownload download = new AjaxDownload(resource) {
                        
@@ -115,7 +117,7 @@ public class AjaxDownloadPage extends BasePage
                                // simulate delay
                                try
                                {
-                                       Thread.sleep(2000);
+                                       TimeUnit.MILLISECONDS.sleep(2000);
                                }
                                catch (InterruptedException e)
                                {
@@ -211,7 +213,7 @@ public class AjaxDownloadPage extends BasePage
        public static class StaticResource extends ResourceStreamResource {
 
                StaticResource() {
-                       setFileName("file");
+                       setFileName("File-from-ResourceReference");
                        setContentDisposition(ContentDisposition.ATTACHMENT);
                        setCacheDuration(Duration.NONE);
                }
@@ -230,13 +232,13 @@ public class AjaxDownloadPage extends BasePage
                        // simulate delay
                        try
                        {
-                               Thread.sleep(5000);
+                               TimeUnit.MILLISECONDS.sleep(5000);
                        }
                        catch (InterruptedException e)
                        {
                        }
                        
-                       return new StringResourceStream("downloaded via ajax 
with reference");
+                       return new StringResourceStream("downloaded via ajax 
with resource reference");
                }
        }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/0b793718/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownload.java
----------------------------------------------------------------------
diff --git 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownload.java
 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownload.java
index 055e55b..a879d5b 100644
--- 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownload.java
+++ 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownload.java
@@ -29,6 +29,7 @@ import org.apache.wicket.ajax.json.JsonFunction;
 import org.apache.wicket.behavior.Behavior;
 import org.apache.wicket.markup.head.IHeaderResponse;
 import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.request.Response;
 import org.apache.wicket.request.cycle.RequestCycle;
 import 
org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;
 import org.apache.wicket.request.http.WebResponse;
@@ -37,6 +38,7 @@ import org.apache.wicket.request.resource.IResource;
 import org.apache.wicket.request.resource.IResource.Attributes;
 import org.apache.wicket.request.resource.ResourceReference;
 import org.apache.wicket.resource.JQueryPluginResourceReference;
+import org.apache.wicket.util.lang.Args;
 
 /**
  * Download resources via Ajax.
@@ -57,19 +59,19 @@ import 
org.apache.wicket.resource.JQueryPluginResourceReference;
  * });
  * </pre>
  * 
- * @see 
+ * @author svenmeier
  */
 public class AjaxDownload extends AbstractDefaultAjaxBehavior
 {
+       private static final long serialVersionUID = 1L;
+
        /**
         * Name of parameter used to transfer the download identifier to the 
resource.
-        * 
+        *
         * @see #markCompleted(Attributes)
         */
        private static final String RESOURCE_PARAMETER_NAME = 
"wicket-ajaxdownload";
 
-       private static final long serialVersionUID = 1L;
-
        private static final ResourceReference JS = new 
JQueryPluginResourceReference(
                AjaxDownload.class, "wicket-ajaxdownload.js");
 
@@ -87,6 +89,7 @@ public class AjaxDownload extends AbstractDefaultAjaxBehavior
         */
        public AjaxDownload(IResource resource)
        {
+               Args.notNull(resource, "resource");
                this.resourceBehavior = new ResourceBehavior(resource);
                this.resourceReference = null;
        }
@@ -122,7 +125,7 @@ public class AjaxDownload extends 
AbstractDefaultAjaxBehavior
        {
                this.resourceBehavior = null;
 
-               this.resourceReference = reference;
+               this.resourceReference = Args.notNull(reference, "reference");
                this.resourceParameters = resourceParameters;
        }
 
@@ -242,20 +245,21 @@ public class AjaxDownload extends 
AbstractDefaultAjaxBehavior
         */
        private class ResourceBehavior extends Behavior implements 
IResourceListener
        {
-               private IResource resource;
+               private final IResource resource;
 
-               public ResourceBehavior(IResource resource)
+               private ResourceBehavior(IResource resource)
                {
-                       this.resource = resource;
+                       this.resource = Args.notNull(resource, "resource");
                }
 
                @Override
                public void onResourceRequested()
                {
-                       
((WebResponse)RequestCycle.get().getResponse()).addCookie(cookie(getName()));
+                       final RequestCycle requestCycle = RequestCycle.get();
+                       final Response response = requestCycle.getResponse();
+                       ((WebResponse) response).addCookie(cookie(getName()));
 
-                       Attributes a = new 
Attributes(RequestCycle.get().getRequest(),
-                               RequestCycle.get().getResponse(), null);
+                       Attributes a = new 
Attributes(requestCycle.getRequest(), response, null);
 
                        resource.respond(a);
                }
@@ -288,4 +292,4 @@ public class AjaxDownload extends 
AbstractDefaultAjaxBehavior
                cookie.setPath("/");
                return cookie;
        }
-}
\ No newline at end of file
+}

Reply via email to