Updated Branches:
  refs/heads/master 021c8269e -> d30af7d18

WICKET-4533: addResourceReplacement methods to provide alternative resources


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

Branch: refs/heads/master
Commit: d30af7d183c399f664324b2d0173465f2cb5ce00
Parents: 021c826
Author: Emond Papegaaij <[email protected]>
Authored: Fri May 4 18:32:21 2012 +0200
Committer: Emond Papegaaij <[email protected]>
Committed: Fri May 4 18:33:43 2012 +0200

----------------------------------------------------------------------
 .../wicket/protocol/http/WebApplication.java       |   67 +++++++++++++--
 1 files changed, 58 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/d30af7d1/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index 1f88dbd..7627daf 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -32,7 +32,14 @@ import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.ajax.AjaxRequestHandler;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.AjaxRequestTargetListenerCollection;
+import org.apache.wicket.core.request.handler.RenderPageRequestHandler;
+import org.apache.wicket.core.request.mapper.MountedMapper;
+import org.apache.wicket.core.request.mapper.PackageMapper;
+import org.apache.wicket.core.request.mapper.ResourceMapper;
+import org.apache.wicket.core.util.file.WebApplicationPath;
 import org.apache.wicket.markup.MarkupType;
+import org.apache.wicket.markup.head.CssHeaderItem;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
 import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.markup.html.form.AutoLabelResolver;
 import org.apache.wicket.markup.html.form.AutoLabelTextResolver;
@@ -50,16 +57,16 @@ import org.apache.wicket.request.Request;
 import org.apache.wicket.request.Response;
 import org.apache.wicket.request.Url;
 import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.core.request.handler.RenderPageRequestHandler;
 import org.apache.wicket.request.handler.render.PageRenderer;
 import org.apache.wicket.request.handler.render.WebPageRenderer;
 import org.apache.wicket.request.http.WebRequest;
 import org.apache.wicket.request.http.WebResponse;
-import org.apache.wicket.core.request.mapper.MountedMapper;
-import org.apache.wicket.core.request.mapper.PackageMapper;
-import org.apache.wicket.core.request.mapper.ResourceMapper;
 import org.apache.wicket.request.mapper.mount.MountMapper;
+import org.apache.wicket.request.resource.CssResourceReference;
+import org.apache.wicket.request.resource.ExternalUrlResourceReference;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
 import org.apache.wicket.request.resource.ResourceReference;
+import org.apache.wicket.resource.bundles.ResourceBundleReference;
 import org.apache.wicket.session.HttpSessionStore;
 import org.apache.wicket.session.ISessionStore;
 import org.apache.wicket.util.IContextProvider;
@@ -68,7 +75,6 @@ import org.apache.wicket.util.crypt.CharEncoding;
 import org.apache.wicket.util.file.FileCleaner;
 import org.apache.wicket.util.file.IFileCleaner;
 import org.apache.wicket.util.file.IResourceFinder;
-import org.apache.wicket.core.util.file.WebApplicationPath;
 import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.lang.PackageName;
 import org.apache.wicket.util.string.Strings;
@@ -393,6 +399,48 @@ public abstract class WebApplication extends Application
        }
 
        /**
+        * Registers a replacement resource for the given javascript resource. 
This replacement can be
+        * another {@link JavaScriptResourceReference} for a packaged resource, 
but it can also be an
+        * {@link ExternalUrlResourceReference} to replace the resource by a 
resource hosted on a CDN.
+        * Registering a replacement will cause the resource to replaced by the 
given resource
+        * throughout the application: if {@code base} is added, {@code 
replacement} will be added
+        * instead.
+        * 
+        * @param base
+        *            The resource to replace
+        * @param replacement
+        *            The replacement
+        */
+       public final void addResourceReplacement(JavaScriptResourceReference 
base,
+               ResourceReference replacement)
+       {
+               ResourceBundleReference bundle = new 
ResourceBundleReference(replacement);
+               
bundle.addProvidedResources(JavaScriptHeaderItem.forReference(base));
+               
getResourceBundles().addBundle(JavaScriptHeaderItem.forReference(bundle));
+       }
+
+       /**
+        * Registers a replacement resource for the given CSS resource. This 
replacement can be another
+        * {@link CssResourceReference} for a packaged resource, but it can 
also be an
+        * {@link ExternalUrlResourceReference} to replace the resource by a 
resource hosted on a CDN.
+        * Registering a replacement will cause the resource to replaced by the 
given resource
+        * throughout the application: if {@code base} is added, {@code 
replacement} will be added
+        * instead.
+        * 
+        * @param base
+        *            The resource to replace
+        * @param replacement
+        *            The replacement
+        */
+       public final void addResourceReplacement(CssResourceReference base,
+               ResourceReference replacement)
+       {
+               ResourceBundleReference bundle = new 
ResourceBundleReference(replacement);
+               bundle.addProvidedResources(CssHeaderItem.forReference(base));
+               
getResourceBundles().addBundle(CssHeaderItem.forReference(bundle));
+       }
+
+       /**
         * Create a new WebRequest. Subclasses of WebRequest could e.g. decode 
and obfuscate URL which
         * has been encoded by an appropriate WebResponse.
         * 
@@ -626,7 +674,7 @@ public abstract class WebApplication extends Application
                {
                        throw new IllegalStateException(
                                "Configuration type is write-once. You can not 
change it. " + "" +
-                               "Current value='" + configurationType + "'");
+                                       "Current value='" + configurationType + 
"'");
                }
                this.configurationType = Args.notNull(configurationType, 
"configurationType");
        }
@@ -705,8 +753,9 @@ public abstract class WebApplication extends Application
         * <p>
         * Default implementation: the page mime type must be 
"application/xhtml+xml" and request
         * HTTP_ACCEPT header must include "application/xhtml+xml" to 
automatically include the xml
-        * decl. Please see <a 
href="https://developer.mozilla.org/en/Writing_JavaScript_for_XHTML#Finally:_Content_Negotiation";>Writing
 JavaScript for XHTML</a>
-        * for details.
+        * decl. Please see <a href=
+        * 
"https://developer.mozilla.org/en/Writing_JavaScript_for_XHTML#Finally:_Content_Negotiation";
+        * >Writing JavaScript for XHTML</a> for details.
         * <p>
         * Please note that xml decls in Wicket's markup are only used for 
reading the markup. The
         * markup's xml decl will always be removed and never be used to 
configure the response.
@@ -900,7 +949,7 @@ public abstract class WebApplication extends Application
         *            the new provider
         */
        public void setAjaxRequestTargetProvider(
-                       IContextProvider<AjaxRequestTarget, Page> 
ajaxRequestTargetProvider)
+               IContextProvider<AjaxRequestTarget, Page> 
ajaxRequestTargetProvider)
        {
                this.ajaxRequestTargetProvider = ajaxRequestTargetProvider;
        }

Reply via email to