You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jr...@apache.org on 2010/11/11 02:22:28 UTC
svn commit: r1033794 - in
/wicket/trunk/wicket/src/main/java/org/apache/wicket: Application.java
ajax/AjaxRequestTarget.java markup/html/DecoratingHeaderResponse.java
markup/html/IHeaderResponseDecorator.java
markup/html/internal/HtmlHeaderContainer.java
Author: jrthomerson
Date: Thu Nov 11 01:22:27 2010
New Revision: 1033794
URL: http://svn.apache.org/viewvc?rev=1033794&view=rev
Log:
fixes WICKET-3149 - port functionality to allow wrapping of IHeaderResponse
Added:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/DecoratingHeaderResponse.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/IHeaderResponseDecorator.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/Application.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Application.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Application.java?rev=1033794&r1=1033793&r2=1033794&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Application.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Application.java Thu Nov 11 01:22:27 2010
@@ -40,6 +40,8 @@ import org.apache.wicket.event.IEventSin
import org.apache.wicket.javascript.DefaultJavascriptCompressor;
import org.apache.wicket.markup.MarkupFactory;
import org.apache.wicket.markup.MarkupParser;
+import org.apache.wicket.markup.html.IHeaderResponse;
+import org.apache.wicket.markup.html.IHeaderResponseDecorator;
import org.apache.wicket.markup.html.image.resource.DefaultButtonImageResourceFactory;
import org.apache.wicket.markup.parser.filter.EnclosureHandler;
import org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler;
@@ -220,6 +222,11 @@ public abstract class Application implem
private IProvider<ISessionStore> sessionStoreProvider;
/**
+ * The decorator this application uses to decorate any header responses created by Wicket
+ */
+ private IHeaderResponseDecorator headerResponseDecorator;
+
+ /**
* Checks if the <code>Application</code> threadlocal is set in this thread
*
* @return true if {@link Application#get()} can return the instance of application, false
@@ -1323,4 +1330,36 @@ public abstract class Application implem
public void onEvent(IEvent<?> event)
{
}
+
+ /**
+ * Sets an {@link IHeaderResponseDecorator} that you want your application to use to decorate
+ * header responses.
+ *
+ * @param headerResponseDecorator
+ * your custom decorator
+ */
+ public void setHeaderResponseDecorator(IHeaderResponseDecorator headerResponseDecorator)
+ {
+ this.headerResponseDecorator = headerResponseDecorator;
+ }
+
+ /**
+ * INTERNAL METHOD - You shouldn't need to call this. This is called every time Wicket creates
+ * an IHeaderResponse. It gives you the ability to incrementally add features to an
+ * IHeaderResponse implementation by wrapping it in another implementation.
+ *
+ * To decorate an IHeaderResponse in your application, set the {@link IHeaderResponseDecorator}
+ * on the application.
+ *
+ * @see IHeaderResponseDecorator
+ * @param response
+ * the response Wicket created
+ * @return the response Wicket should use in IHeaderContributor traversal
+ */
+ public final IHeaderResponse decorateHeaderResponse(IHeaderResponse response)
+ {
+ IHeaderResponse hr = headerResponseDecorator == null ? response
+ : headerResponseDecorator.decorate(response);
+ return hr;
+ }
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=1033794&r1=1033793&r2=1033794&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java Thu Nov 11 01:22:27 2010
@@ -1083,7 +1083,7 @@ public class AjaxRequestTarget implement
{
if (headerResponse == null)
{
- headerResponse = new AjaxHeaderResponse();
+ headerResponse = Application.get().decorateHeaderResponse(new AjaxHeaderResponse());
}
return headerResponse;
}
@@ -1165,6 +1165,7 @@ public class AjaxRequestTarget implement
}
});
}
+ header.getHeaderResponse().close();
// revert to old response
Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/DecoratingHeaderResponse.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/DecoratingHeaderResponse.java?rev=1033794&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/DecoratingHeaderResponse.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/DecoratingHeaderResponse.java Thu Nov 11 01:22:27 2010
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.markup.html;
+
+import org.apache.wicket.ResourceReference;
+import org.apache.wicket.Response;
+
+/**
+ * This is simply a helper implementation of IHeaderResponse that really delegates all of its method
+ * calls to the IHeaderResponse that is passed into the constructor. It is defined as abstract
+ * because it's only meant to be extended and not used a la carte. You can extend it and override
+ * only the methods that you want to change the functionality of.
+ *
+ * @see IHeaderResponseDecorator
+ * @see IHeaderResponse
+ * @author Jeremy Thomerson
+ */
+public abstract class DecoratingHeaderResponse implements IHeaderResponse
+{
+
+ private final IHeaderResponse realResponse;
+
+ /**
+ * Create a header response that simply delegates all methods to the one that is passed in here.
+ *
+ * @param real
+ * the actual response that this class delegates to by default
+ */
+ public DecoratingHeaderResponse(IHeaderResponse real)
+ {
+ realResponse = real;
+ }
+
+ /**
+ * Returns the actual response being decorated for subclasses to be able to pass it off to other
+ * objects if they need to do so.
+ *
+ * @return the actual wrapped IHeaderResponse
+ */
+ protected final IHeaderResponse getRealResponse()
+ {
+ return realResponse;
+ }
+
+ public void renderJavascriptReference(ResourceReference reference)
+ {
+ realResponse.renderJavascriptReference(reference);
+ }
+
+ public void renderJavascriptReference(ResourceReference reference, String id)
+ {
+ realResponse.renderJavascriptReference(reference, id);
+ }
+
+ public void renderJavascriptReference(String url)
+ {
+ realResponse.renderJavascriptReference(url);
+ }
+
+ public void renderJavascriptReference(String url, String id)
+ {
+ realResponse.renderJavascriptReference(url, id);
+ }
+
+ public void renderJavascript(CharSequence javascript, String id)
+ {
+ realResponse.renderJavascript(javascript, id);
+ }
+
+ public void renderCSSReference(ResourceReference reference)
+ {
+ realResponse.renderCSSReference(reference);
+ }
+
+ public void renderCSSReference(String url)
+ {
+ realResponse.renderCSSReference(url);
+ }
+
+ public void renderCSSReference(ResourceReference reference, String media)
+ {
+ realResponse.renderCSSReference(reference, media);
+ }
+
+ public void renderCSSReference(String url, String media)
+ {
+ realResponse.renderCSSReference(url, media);
+ }
+
+ public void renderString(CharSequence string)
+ {
+ realResponse.renderString(string);
+ }
+
+ public void markRendered(Object object)
+ {
+ realResponse.markRendered(object);
+ }
+
+ public boolean wasRendered(Object object)
+ {
+ return realResponse.wasRendered(object);
+ }
+
+ public Response getResponse()
+ {
+ return realResponse.getResponse();
+ }
+
+ public void renderOnDomReadyJavascript(String javascript)
+ {
+ realResponse.renderOnDomReadyJavascript(javascript);
+ }
+
+ public void renderOnLoadJavascript(String javascript)
+ {
+ realResponse.renderOnLoadJavascript(javascript);
+ }
+
+ public void renderOnEventJavascript(String target, String event, String javascript)
+ {
+ realResponse.renderOnEventJavascript(target, event, javascript);
+ }
+
+ public void close()
+ {
+ realResponse.close();
+ }
+
+ public boolean isClosed()
+ {
+ return realResponse.isClosed();
+ }
+
+}
Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/IHeaderResponseDecorator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/IHeaderResponseDecorator.java?rev=1033794&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/IHeaderResponseDecorator.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/IHeaderResponseDecorator.java Thu Nov 11 01:22:27 2010
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.markup.html;
+
+/**
+ * Setting an IHeaderResponseDecorator on an application allows you to wrap any IHeaderResponse
+ * created by Wicket in a separate implementation that incrementally adds functionality to the
+ * IHeaderResponse that is used by all IHeaderContributor components or behaviors.
+ *
+ * Everywhere that Wicket creates an instance of IHeaderResponse, it will call to your application
+ * and give it the opportunity to decorate that IHeaderResponse before using it.
+ *
+ * @see IHeaderResponse
+ * @see DecoratingHeaderResponse
+ * @author Jeremy Thomerson
+ */
+public interface IHeaderResponseDecorator
+{
+
+ /**
+ * The method that does the decorating of the IHeaderResponse.
+ *
+ * @param response
+ * the original response created by Wicket
+ * @return the response to be used by IHeaderContributors
+ */
+ IHeaderResponse decorate(IHeaderResponse response);
+}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java?rev=1033794&r1=1033793&r2=1033794&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java Thu Nov 11 01:22:27 2010
@@ -272,7 +272,7 @@ public class HtmlHeaderContainer extends
{
if (headerResponse == null)
{
- headerResponse = newHeaderResponse();
+ headerResponse = getApplication().decorateHeaderResponse(newHeaderResponse());
}
return headerResponse;
}