You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by so...@apache.org on 2017/11/10 13:38:23 UTC
[1/2] wicket git commit: [WICKET-6491] ajax download seems to work
under both IE11 and Edge
Repository: wicket
Updated Branches:
refs/heads/master ae7abe411 -> d2286b2bc
[WICKET-6491] ajax download seems to work under both IE11 and Edge
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/e1e6235e
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/e1e6235e
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/e1e6235e
Branch: refs/heads/master
Commit: e1e6235e33156086fc3b7b13d49261ef10c2183d
Parents: ae7abe4
Author: Maxim Solodovnik <so...@gmail.com>
Authored: Thu Nov 9 19:15:26 2017 +0700
Committer: Maxim Solodovnik <so...@gmail.com>
Committed: Thu Nov 9 19:15:26 2017 +0700
----------------------------------------------------------------------
.../extensions/ajax/AjaxDownloadBehavior.java | 50 ++++++++++++++------
.../extensions/ajax/wicket-ajaxdownload.js | 36 +++++++-------
2 files changed, 54 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/e1e6235e/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
index 787c826..69e1d0d 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
@@ -48,11 +48,11 @@ import com.github.openjson.JSONObject;
* Download resources via Ajax.
* <p>
* Usage:
- *
+ *
* <pre>
* final AjaxDownload download = new AjaxDownload(resource);
* add(download);
- *
+ *
* add(new AjaxButton("download")
* {
* @Override
@@ -66,7 +66,7 @@ import com.github.openjson.JSONObject;
* <p>To set the name of the downloaded resource make use of
* {@link org.apache.wicket.request.resource.ResourceStreamResource#setFileName(String)} or
* {@link org.apache.wicket.request.resource.AbstractResource.ResourceResponse#setFileName(String)}</p>
- *
+ *
* @author svenmeier
* @author Martin Grigorov
* @author Maxim Solodovnik
@@ -130,7 +130,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
/**
* Download of a {@link Resource}.
- *
+ *
* @param resource
* resource to download
*/
@@ -147,7 +147,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
* The {@link IResource} returned by {@link ResourceReference#getResource()} must call
* {@link #markCompleted(Attributes)} when responding, otherwise the callback
* {@link #onDownloadSuccess(AjaxRequestTarget)} will not work.
- *
+ *
* @param reference
* reference to resource to download
*/
@@ -162,7 +162,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
* The {@link IResource} returned by {@link ResourceReference#getResource()} must call
* {@link #markCompleted(Attributes)} when responding, otherwise the callback
* {@link #onDownloadSuccess(AjaxRequestTarget)} will not work.
- *
+ *
* @param reference
* reference to resource to download
* @param resourceParameters
@@ -200,7 +200,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
/**
* Call this method to initiate the download.
- *
+ *
* @param target
* the initiating Ajax target
*/
@@ -230,11 +230,11 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
parameters.set(RESOURCE_PARAMETER_NAME, getName());
url = getComponent().getRequestCycle()
- .urlFor(new ResourceReferenceRequestHandler(resourceReference, parameters));
+ .urlFor(new ResourceReferenceRequestHandler(resourceReference, addAntiCache(parameters)));
}
else
{
- url = resourceBehavior.getUrl();
+ url = resourceBehavior.getUrl(addAntiCache(null));
}
JSONObject settings = new JSONObject();
@@ -323,10 +323,30 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
}
/**
+ * Controls if anti cache parameter should be added to the URL or not
+ *
+ * @return {@code true} to add the anti cache request parameter, {@code false} - otherwise
+ */
+ protected boolean shouldAddAntiCacheParameter() {
+ return true;
+ }
+
+ private PageParameters addAntiCache(PageParameters params) {
+ if (shouldAddAntiCacheParameter()) {
+ if (params == null) {
+ params = new PageParameters();
+ }
+ params.add("antiCache", String.valueOf(System.currentTimeMillis()));
+ }
+ return params;
+ }
+
+ /**
* The behavior responding with the actual resource.
*/
private class ResourceBehavior extends Behavior implements IRequestListener
{
+ private static final long serialVersionUID = 1L;
private final IResource resource;
private ResourceBehavior(IResource resource)
@@ -339,7 +359,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
{
return false;
}
-
+
@Override
public void onRequest()
{
@@ -352,9 +372,9 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
resource.respond(a);
}
- public CharSequence getUrl()
+ public CharSequence getUrl(PageParameters params)
{
- return getComponent().urlForListener(this, null);
+ return getComponent().urlForListener(this, params);
}
}
@@ -363,7 +383,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
* <p>
* Has to be called from {@link IResource#respond(Attributes)} when downloaded via
* {@link #AjaxDownloadBehavior(IResource)}.
- *
+ *
* @param attributes
* resource attributes
*/
@@ -377,12 +397,12 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
private static Cookie cookie(String name)
{
Cookie cookie = new Cookie(name, "complete");
-
+
// has to be on root, otherwise JavaScript will not be able to access the
// cookie when it is set from a different path - which is the case when a
// ResourceReference is used
cookie.setPath("/");
-
+
return cookie;
}
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/e1e6235e/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/wicket-ajaxdownload.js
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/wicket-ajaxdownload.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/wicket-ajaxdownload.js
index f8452ae..6aaa43a 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/wicket-ajaxdownload.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/wicket-ajaxdownload.js
@@ -108,29 +108,32 @@
var disposition = xhr.getResponseHeader("Content-Disposition");
if (disposition) {
var matches = /filename[^;=\n]*=(([""]).*?\2|[^;\n]*)/.exec(disposition);
- if (matches != null && matches[1]) {
+ if (matches !== null && matches[1]) {
filename = matches[1].replace(/[""]/g, "");
}
}
- var type = xhr.getResponseHeader("Content-Type");
- var blob = new Blob([xhr.response], {type: type});
+ if (typeof window.navigator.msSaveOrOpenBlob !== 'undefined') {
+ window.navigator.msSaveOrOpenBlob(xhr.response, filename);
+ } else {
+ var type = xhr.getResponseHeader("Content-Type");
+ var blob = new Blob([xhr.response], {type: type});
- var blobUrl = (window.URL || window.webkitURL).createObjectURL(blob);
+ var blobUrl = (window.URL || window.webkitURL).createObjectURL(blob);
- var anchor = jQuery("<a></a>")
- .prop("href", blobUrl)
- .prop("download", filename)
- .appendTo("body")
- .hide();
-
- anchor[0].click();
-
- setTimeout(function () {
- URL.revokeObjectURL(blobUrl);
- anchor.remove();
- }, 100);
+ var anchor = jQuery("<a></a>")
+ .prop("href", blobUrl)
+ .prop("download", filename)
+ .appendTo("body")
+ .hide();
+ anchor[0].click();
+
+ setTimeout(function () {
+ URL.revokeObjectURL(blobUrl);
+ anchor.remove();
+ }, 100);
+ }
notifyServer("success");
} else {
notifyServer("failed");
@@ -143,5 +146,4 @@
}
}
};
-
})();
[2/2] wicket git commit: [WICKET-6491] redundant anti-cache parameter
is removed
Posted by so...@apache.org.
[WICKET-6491] redundant anti-cache parameter is removed
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d2286b2b
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d2286b2b
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d2286b2b
Branch: refs/heads/master
Commit: d2286b2bcc391b9595bc48d8082fb8c6ee911d2c
Parents: e1e6235
Author: Maxim Solodovnik <so...@gmail.com>
Authored: Fri Nov 10 11:14:18 2017 +0700
Committer: Maxim Solodovnik <so...@gmail.com>
Committed: Fri Nov 10 11:14:18 2017 +0700
----------------------------------------------------------------------
.../extensions/ajax/AjaxDownloadBehavior.java | 50 ++++++--------------
1 file changed, 15 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/d2286b2b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
index 69e1d0d..787c826 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/AjaxDownloadBehavior.java
@@ -48,11 +48,11 @@ import com.github.openjson.JSONObject;
* Download resources via Ajax.
* <p>
* Usage:
- *
+ *
* <pre>
* final AjaxDownload download = new AjaxDownload(resource);
* add(download);
- *
+ *
* add(new AjaxButton("download")
* {
* @Override
@@ -66,7 +66,7 @@ import com.github.openjson.JSONObject;
* <p>To set the name of the downloaded resource make use of
* {@link org.apache.wicket.request.resource.ResourceStreamResource#setFileName(String)} or
* {@link org.apache.wicket.request.resource.AbstractResource.ResourceResponse#setFileName(String)}</p>
- *
+ *
* @author svenmeier
* @author Martin Grigorov
* @author Maxim Solodovnik
@@ -130,7 +130,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
/**
* Download of a {@link Resource}.
- *
+ *
* @param resource
* resource to download
*/
@@ -147,7 +147,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
* The {@link IResource} returned by {@link ResourceReference#getResource()} must call
* {@link #markCompleted(Attributes)} when responding, otherwise the callback
* {@link #onDownloadSuccess(AjaxRequestTarget)} will not work.
- *
+ *
* @param reference
* reference to resource to download
*/
@@ -162,7 +162,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
* The {@link IResource} returned by {@link ResourceReference#getResource()} must call
* {@link #markCompleted(Attributes)} when responding, otherwise the callback
* {@link #onDownloadSuccess(AjaxRequestTarget)} will not work.
- *
+ *
* @param reference
* reference to resource to download
* @param resourceParameters
@@ -200,7 +200,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
/**
* Call this method to initiate the download.
- *
+ *
* @param target
* the initiating Ajax target
*/
@@ -230,11 +230,11 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
parameters.set(RESOURCE_PARAMETER_NAME, getName());
url = getComponent().getRequestCycle()
- .urlFor(new ResourceReferenceRequestHandler(resourceReference, addAntiCache(parameters)));
+ .urlFor(new ResourceReferenceRequestHandler(resourceReference, parameters));
}
else
{
- url = resourceBehavior.getUrl(addAntiCache(null));
+ url = resourceBehavior.getUrl();
}
JSONObject settings = new JSONObject();
@@ -323,30 +323,10 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
}
/**
- * Controls if anti cache parameter should be added to the URL or not
- *
- * @return {@code true} to add the anti cache request parameter, {@code false} - otherwise
- */
- protected boolean shouldAddAntiCacheParameter() {
- return true;
- }
-
- private PageParameters addAntiCache(PageParameters params) {
- if (shouldAddAntiCacheParameter()) {
- if (params == null) {
- params = new PageParameters();
- }
- params.add("antiCache", String.valueOf(System.currentTimeMillis()));
- }
- return params;
- }
-
- /**
* The behavior responding with the actual resource.
*/
private class ResourceBehavior extends Behavior implements IRequestListener
{
- private static final long serialVersionUID = 1L;
private final IResource resource;
private ResourceBehavior(IResource resource)
@@ -359,7 +339,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
{
return false;
}
-
+
@Override
public void onRequest()
{
@@ -372,9 +352,9 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
resource.respond(a);
}
- public CharSequence getUrl(PageParameters params)
+ public CharSequence getUrl()
{
- return getComponent().urlForListener(this, params);
+ return getComponent().urlForListener(this, null);
}
}
@@ -383,7 +363,7 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
* <p>
* Has to be called from {@link IResource#respond(Attributes)} when downloaded via
* {@link #AjaxDownloadBehavior(IResource)}.
- *
+ *
* @param attributes
* resource attributes
*/
@@ -397,12 +377,12 @@ public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
private static Cookie cookie(String name)
{
Cookie cookie = new Cookie(name, "complete");
-
+
// has to be on root, otherwise JavaScript will not be able to access the
// cookie when it is set from a different path - which is the case when a
// ResourceReference is used
cookie.setPath("/");
-
+
return cookie;
}
}