org.apache.wicket.resource.filtering
Class HeaderResponseContainerFilteringHeaderResponse

java.lang.Object
  extended by org.apache.wicket.markup.html.DecoratingHeaderResponse
      extended by org.apache.wicket.resource.filtering.HeaderResponseContainerFilteringHeaderResponse
All Implemented Interfaces:
java.io.Closeable, IHeaderResponse
Direct Known Subclasses:
JavaScriptFilteredIntoFooterHeaderResponse

public class HeaderResponseContainerFilteringHeaderResponse
extends DecoratingHeaderResponse

This header response allows you to separate things that are added to the IHeaderResponse into different buckets. Then, you can render those different buckets in separate areas of the page based on your filter logic. A typical use case for this header response is to move the loading of JavaScript files (and inline script tags) to the footer of the page.

Author:
Jeremy Thomerson
See Also:
HeaderResponseFilteredResponseContainer, CssAcceptingHeaderResponseFilter, JavaScriptAcceptingHeaderResponseFilter

Nested Class Summary
static interface HeaderResponseContainerFilteringHeaderResponse.IHeaderResponseFilter
          A filter used to bucket your resources, inline scripts, etc, into different responses.
 
Constructor Summary
HeaderResponseContainerFilteringHeaderResponse(IHeaderResponse response, java.lang.String headerFilterName, HeaderResponseContainerFilteringHeaderResponse.IHeaderResponseFilter[] filters)
          Construct.
 
Method Summary
 void close()
          Mark Header rendering is completed and subsequent usage will be ignored.
static HeaderResponseContainerFilteringHeaderResponse get()
           
 java.lang.CharSequence getContent(java.lang.String filterName)
          Gets the content that was rendered to this header response and matched the filter with the given name.
 void renderCSSReference(ResourceReference reference)
          Writes a CSS reference, if the specified reference hasn't been rendered yet.
 void renderCSSReference(ResourceReference reference, PageParameters pageParameters, java.lang.String media)
          Writes a CSS reference with query parameters, if the specified reference hasn't been rendered yet.
 void renderCSSReference(ResourceReference reference, java.lang.String media)
          Writes a CSS reference, if the specified reference hasn't been rendered yet.
 void renderCSSReference(java.lang.String url)
          Writes a CSS reference, if the specified reference hasn't been rendered yet.
 void renderCSSReference(java.lang.String url, java.lang.String media)
          Writes a link to a CSS resource, if the specified url hasn't been rendered yet.
 void renderJavaScript(java.lang.CharSequence javascript, java.lang.String id)
          Renders javascript code to the response, if the javascript has not already been rendered.
 void renderJavaScriptReference(ResourceReference reference)
          Writes a javascript reference, if the specified reference hasn't been rendered yet.
 void renderJavaScriptReference(ResourceReference reference, PageParameters pageParameters, java.lang.String id)
          Writes a javascript reference with query parameters, if the specified reference hasn't been rendered yet.
 void renderJavaScriptReference(ResourceReference reference, java.lang.String id)
          Writes a javascript reference, if the specified reference hasn't been rendered yet.
 void renderJavaScriptReference(java.lang.String url)
          Writes a javascript reference, if the specified reference hasn't been rendered yet.
 void renderJavaScriptReference(java.lang.String url, java.lang.String id)
          Writes a javascript reference, if the specified reference hasn't been rendered yet.
 void renderOnDomReadyJavaScript(java.lang.String javascript)
          Renders javascript that is executed right after the DOM is built, before external resources (e.g.
 void renderOnEventJavaScript(java.lang.String target, java.lang.String event, java.lang.String javascript)
          Renders javascript that is executed after the given event happens on specified target
 void renderOnLoadJavaScript(java.lang.String javascript)
          Renders javascript that is executed after the entire page is loaded.
protected  void runWithFilter(java.lang.Runnable runnable, java.lang.String filterName)
          If subclasses of this class have special cases where they force something into a particular bucket, regardless of the filters, they can create a Runnable that renders to the real response, and pass it to this method with the name of the filter (bucket) that they want it to appear in.
protected  void setFilters(HeaderResponseContainerFilteringHeaderResponse.IHeaderResponseFilter[] filters)
           
 
Methods inherited from class org.apache.wicket.markup.html.DecoratingHeaderResponse
getRealResponse, getResponse, isClosed, markRendered, renderCSS, renderCSSReference, renderCSSReference, renderJavaScriptReference, renderJavaScriptReference, renderJavaScriptReference, renderJavaScriptReference, renderString, wasRendered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HeaderResponseContainerFilteringHeaderResponse

public HeaderResponseContainerFilteringHeaderResponse(IHeaderResponse response,
                                                      java.lang.String headerFilterName,
                                                      HeaderResponseContainerFilteringHeaderResponse.IHeaderResponseFilter[] filters)
Construct.

Parameters:
response - the wrapped IHeaderResponse
headerFilterName - the name that the filter for things that should appear in the head (default Wicket location) uses
filters - the filters to use to bucket things. There will be a bucket created for each filter, by name. There should typically be at least one filter with the same name as your headerFilterName
Method Detail

setFilters

protected void setFilters(HeaderResponseContainerFilteringHeaderResponse.IHeaderResponseFilter[] filters)

get

public static HeaderResponseContainerFilteringHeaderResponse get()
Returns:
the HeaderResponseContainerFilteringHeaderResponse being used in this RequestCycle

renderJavaScriptReference

public void renderJavaScriptReference(ResourceReference reference)
Description copied from interface: IHeaderResponse
Writes a javascript reference, if the specified reference hasn't been rendered yet.

Specified by:
renderJavaScriptReference in interface IHeaderResponse
Overrides:
renderJavaScriptReference in class DecoratingHeaderResponse
Parameters:
reference - resource reference pointing to the javascript resource

renderJavaScriptReference

public void renderJavaScriptReference(ResourceReference reference,
                                      java.lang.String id)
Description copied from interface: IHeaderResponse
Writes a javascript reference, if the specified reference hasn't been rendered yet.

Specified by:
renderJavaScriptReference in interface IHeaderResponse
Overrides:
renderJavaScriptReference in class DecoratingHeaderResponse
Parameters:
reference - resource reference pointing to the javascript resource
id - id that will be used to filter duplicate reference (it's still filtered by URL too)

renderJavaScriptReference

public void renderJavaScriptReference(ResourceReference reference,
                                      PageParameters pageParameters,
                                      java.lang.String id)
Description copied from interface: IHeaderResponse
Writes a javascript reference with query parameters, if the specified reference hasn't been rendered yet.

Specified by:
renderJavaScriptReference in interface IHeaderResponse
Overrides:
renderJavaScriptReference in class DecoratingHeaderResponse
Parameters:
reference - resource reference pointing to the javascript resource
pageParameters - the parameters for this Javascript resource reference
id - id that will be used to filter duplicate reference (it's still filtered by URL too)

renderJavaScriptReference

public void renderJavaScriptReference(java.lang.String url)
Description copied from interface: IHeaderResponse
Writes a javascript reference, if the specified reference hasn't been rendered yet.

Specified by:
renderJavaScriptReference in interface IHeaderResponse
Overrides:
renderJavaScriptReference in class DecoratingHeaderResponse
Parameters:
url - context-relative url of the the javascript resource

renderJavaScriptReference

public void renderJavaScriptReference(java.lang.String url,
                                      java.lang.String id)
Description copied from interface: IHeaderResponse
Writes a javascript reference, if the specified reference hasn't been rendered yet.

Specified by:
renderJavaScriptReference in interface IHeaderResponse
Overrides:
renderJavaScriptReference in class DecoratingHeaderResponse
Parameters:
url - context-relative url of the the javascript resource
id - id that will be used to filter duplicate reference (it's still filtered by URL too)

renderJavaScript

public void renderJavaScript(java.lang.CharSequence javascript,
                             java.lang.String id)
Description copied from interface: IHeaderResponse
Renders javascript code to the response, if the javascript has not already been rendered. the necessary surrounding script tags will be added to the output.

Specified by:
renderJavaScript in interface IHeaderResponse
Overrides:
renderJavaScript in class DecoratingHeaderResponse
Parameters:
javascript - javascript content to be rendered.
id - unique id for the javascript element. This can be null, however in that case the ajax header contribution can't detect duplicate script fragments.

renderCSSReference

public void renderCSSReference(ResourceReference reference)
Description copied from interface: IHeaderResponse
Writes a CSS reference, if the specified reference hasn't been rendered yet.

Specified by:
renderCSSReference in interface IHeaderResponse
Overrides:
renderCSSReference in class DecoratingHeaderResponse
Parameters:
reference - resource reference pointing to the CSS resource

renderCSSReference

public void renderCSSReference(java.lang.String url)
Description copied from interface: IHeaderResponse
Writes a CSS reference, if the specified reference hasn't been rendered yet.

Specified by:
renderCSSReference in interface IHeaderResponse
Overrides:
renderCSSReference in class DecoratingHeaderResponse
Parameters:
url - context-relative url of the CSS resource

renderCSSReference

public void renderCSSReference(ResourceReference reference,
                               java.lang.String media)
Description copied from interface: IHeaderResponse
Writes a CSS reference, if the specified reference hasn't been rendered yet.

Specified by:
renderCSSReference in interface IHeaderResponse
Overrides:
renderCSSReference in class DecoratingHeaderResponse
Parameters:
reference - resource reference pointing to the CSS resource
media - the media type for this CSS ("print", "screen", etc.)

renderCSSReference

public void renderCSSReference(ResourceReference reference,
                               PageParameters pageParameters,
                               java.lang.String media)
Description copied from interface: IHeaderResponse
Writes a CSS reference with query parameters, if the specified reference hasn't been rendered yet.

Specified by:
renderCSSReference in interface IHeaderResponse
Overrides:
renderCSSReference in class DecoratingHeaderResponse
Parameters:
reference - resource reference pointing to the CSS resource
pageParameters - the parameters for this CSS resource reference
media - the media type for this CSS ("print", "screen", etc.)

renderCSSReference

public void renderCSSReference(java.lang.String url,
                               java.lang.String media)
Description copied from interface: IHeaderResponse
Writes a link to a CSS resource, if the specified url hasn't been rendered yet.

Specified by:
renderCSSReference in interface IHeaderResponse
Overrides:
renderCSSReference in class DecoratingHeaderResponse
Parameters:
url - context-relative url of the CSS resource
media - the media type for this CSS ("print", "screen", etc.)

renderOnDomReadyJavaScript

public void renderOnDomReadyJavaScript(java.lang.String javascript)
Description copied from interface: IHeaderResponse
Renders javascript that is executed right after the DOM is built, before external resources (e.g. images) are loaded.

Specified by:
renderOnDomReadyJavaScript in interface IHeaderResponse
Overrides:
renderOnDomReadyJavaScript in class DecoratingHeaderResponse

renderOnLoadJavaScript

public void renderOnLoadJavaScript(java.lang.String javascript)
Description copied from interface: IHeaderResponse
Renders javascript that is executed after the entire page is loaded.

Specified by:
renderOnLoadJavaScript in interface IHeaderResponse
Overrides:
renderOnLoadJavaScript in class DecoratingHeaderResponse

renderOnEventJavaScript

public void renderOnEventJavaScript(java.lang.String target,
                                    java.lang.String event,
                                    java.lang.String javascript)
Description copied from interface: IHeaderResponse
Renders javascript that is executed after the given event happens on specified target

Specified by:
renderOnEventJavaScript in interface IHeaderResponse
Overrides:
renderOnEventJavaScript in class DecoratingHeaderResponse

close

public void close()
Description copied from interface: IHeaderResponse
Mark Header rendering is completed and subsequent usage will be ignored. If some kind of buffering is used internally, this action will mark that the contents has to be flushed out.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface IHeaderResponse
Overrides:
close in class DecoratingHeaderResponse

getContent

public final java.lang.CharSequence getContent(java.lang.String filterName)
Gets the content that was rendered to this header response and matched the filter with the given name.

Parameters:
filterName - the name of the filter to get the bucket for
Returns:
the content that was accepted by the filter with this name

runWithFilter

protected final void runWithFilter(java.lang.Runnable runnable,
                                   java.lang.String filterName)
If subclasses of this class have special cases where they force something into a particular bucket, regardless of the filters, they can create a Runnable that renders to the real response, and pass it to this method with the name of the filter (bucket) that they want it to appear in. Example: public void renderJavascriptIntoHead(final String js, final String id) { runWithFilter(new Runnable() { public void run() { getRealResponse().renderJavascript(js, id); } }, "headerBucket"); }

Parameters:
runnable - the runnable that renders to the real response.
filterName - the name of the filter bucket that you want the runnable to render into


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.