WICKET-5307 Export resources' version cache attribute as request cycle metadata
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/823e571d Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/823e571d Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/823e571d Branch: refs/heads/5299-ajax-strategy Commit: 823e571d5377afc56a7d9e6b9f0a6dd35f7aa22f Parents: 104f13a Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org> Authored: Wed Aug 7 14:24:57 2013 +0200 Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org> Committed: Wed Aug 7 14:25:27 2013 +0200 ---------------------------------------------------------------------- .../FilenameWithVersionResourceCachingStrategy.java | 10 ++++++++++ .../resource/caching/IResourceCachingStrategy.java | 10 ++++++++++ .../QueryStringWithVersionResourceCachingStrategy.java | 11 +++++++++++ 3 files changed, 31 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/823e571d/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategy.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategy.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategy.java index d470986..0d00cef 100644 --- a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategy.java +++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/FilenameWithVersionResourceCachingStrategy.java @@ -16,6 +16,7 @@ */ package org.apache.wicket.request.resource.caching; +import org.apache.wicket.request.cycle.RequestCycle; import org.apache.wicket.request.http.WebResponse; import org.apache.wicket.request.resource.AbstractResource; import org.apache.wicket.request.resource.caching.version.IResourceVersion; @@ -175,6 +176,15 @@ public class FilenameWithVersionResourceCachingStrategy implements IResourceCach // create filename without version string // (required for working resource lookup) url.setFileName(extension == null? basename : basename + extension); + + // store the version in the request cycle + RequestCycle requestCycle = RequestCycle.get(); + if (requestCycle != null) + { + int idx = fullname.indexOf(versionPrefix); + String urlVersion = fullname.substring(pos + idx + 1); + requestCycle.setMetaData(URL_VERSION, urlVersion); + } } } http://git-wip-us.apache.org/repos/asf/wicket/blob/823e571d/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/IResourceCachingStrategy.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/IResourceCachingStrategy.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/IResourceCachingStrategy.java index 1397067..c62a61a 100644 --- a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/IResourceCachingStrategy.java +++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/IResourceCachingStrategy.java @@ -16,6 +16,7 @@ */ package org.apache.wicket.request.resource.caching; +import org.apache.wicket.MetaDataKey; import org.apache.wicket.request.resource.AbstractResource; /** @@ -31,6 +32,15 @@ import org.apache.wicket.request.resource.AbstractResource; */ public interface IResourceCachingStrategy { + + /** + * A key used to store the extracted resource's version in + * {@linkplain #undecorateUrl(ResourceUrl)} into the request cycle + */ + final MetaDataKey<String> URL_VERSION = new MetaDataKey<String>() + { + }; + /** * add caching related information to filename + parameters * http://git-wip-us.apache.org/repos/asf/wicket/blob/823e571d/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategy.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategy.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategy.java index 34826f8..292f159 100644 --- a/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategy.java +++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/caching/QueryStringWithVersionResourceCachingStrategy.java @@ -16,11 +16,13 @@ */ package org.apache.wicket.request.resource.caching; +import org.apache.wicket.request.cycle.RequestCycle; import org.apache.wicket.request.http.WebResponse; import org.apache.wicket.request.mapper.parameter.INamedParameters; import org.apache.wicket.request.resource.AbstractResource; import org.apache.wicket.request.resource.caching.version.IResourceVersion; import org.apache.wicket.util.lang.Args; +import org.apache.wicket.util.string.StringValue; /** * resource caching strategy that adds a version string to the query parameters of the resource @@ -109,6 +111,15 @@ public class QueryStringWithVersionResourceCachingStrategy implements IResourceC if (parameters != null) { + // store the version in the request cycle + StringValue versionValue = parameters.get(versionParameter); + RequestCycle requestCycle = RequestCycle.get(); + if (versionValue.isEmpty() == false && requestCycle != null) + { + requestCycle.setMetaData(URL_VERSION, versionValue.toString()); + } + + // undecorate parameters.remove(versionParameter); } }