org.apache.wicket.examples.resourcedecoration
Class GroupingHeaderResponse

java.lang.Object
  extended by org.apache.wicket.markup.html.DecoratingHeaderResponse
      extended by org.apache.wicket.resource.aggregation.AbstractResourceAggregatingHeaderResponse<HttpAggregatingResourceReferenceCollection,BasicGroupingKey>
          extended by org.apache.wicket.examples.resourcedecoration.GroupingHeaderResponse
All Implemented Interfaces:
java.io.Closeable, IHeaderResponse

public class GroupingHeaderResponse
extends AbstractResourceAggregatingHeaderResponse<HttpAggregatingResourceReferenceCollection,BasicGroupingKey>

A IHeaderResponse decorator that groups the resources by type (css or js) and by custom groups

Author:
jthomerson

Constructor Summary
GroupingHeaderResponse(IHeaderResponse real)
          Construct.
 
Method Summary
protected  BasicGroupingKey newGroupingKey(ResourceReferenceAndStringData ref)
          This key is what is used to determine how to group (or aggregate) your resources.
protected  HttpAggregatingResourceReferenceCollection newResourceReferenceCollection(BasicGroupingKey key)
          creates a ResourceReferenceCollection.
protected  void onAllCollectionsRendered(java.util.List<ResourceReferenceAndStringData> allTopLevelReferences)
          After all the collections have been rendered, we call this callback so your subclass can add any other logic as needed.
protected  void renderCollection(java.util.Set<ResourceReferenceAndStringData> alreadyRendered, BasicGroupingKey key, HttpAggregatingResourceReferenceCollection coll)
          When the entire hierarchy has been traversed and AbstractResourceAggregatingHeaderResponse.close() is called, we loop through the grouped collections and render them in this method.
 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 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.
 
Methods inherited from class org.apache.wicket.resource.aggregation.AbstractResourceAggregatingHeaderResponse
close, getGroupingKeyComparator, render, renderCSSReference, renderCSSReference, renderCSSReference, renderCSSReference, renderIfNotAlreadyRendered, renderJavaScriptReference, renderJavaScriptReference, renderJavaScriptReference, renderJavaScriptReference
 
Methods inherited from class org.apache.wicket.markup.html.DecoratingHeaderResponse
getRealResponse, getResponse, isClosed, markRendered, renderCSS, renderCSSReference, renderCSSReference, renderCSSReference, renderJavaScriptReference, 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

GroupingHeaderResponse

public GroupingHeaderResponse(IHeaderResponse real)
Construct.

Parameters:
real -
Method Detail

renderCollection

protected void renderCollection(java.util.Set<ResourceReferenceAndStringData> alreadyRendered,
                                BasicGroupingKey key,
                                HttpAggregatingResourceReferenceCollection coll)
Description copied from class: AbstractResourceAggregatingHeaderResponse
When the entire hierarchy has been traversed and AbstractResourceAggregatingHeaderResponse.close() is called, we loop through the grouped collections and render them in this method. This method is typically overridden to render your collection how you want to render them. For instance, if you want to aggregate your groups into a single HTTP request, you can override this method, create the URL to your aggregation servlet (or Resource), and then call getRealResponse().renderJavaScriptReference(yourUrl), or the appropriate method to render the URL for a group of CSS references.

Overrides:
renderCollection in class AbstractResourceAggregatingHeaderResponse<HttpAggregatingResourceReferenceCollection,BasicGroupingKey>
Parameters:
alreadyRendered - a set of resource references that have already been rendered in other groups
key - they grouping key for this group
coll - the collection of resource references to render

onAllCollectionsRendered

protected void onAllCollectionsRendered(java.util.List<ResourceReferenceAndStringData> allTopLevelReferences)
Description copied from class: AbstractResourceAggregatingHeaderResponse
After all the collections have been rendered, we call this callback so your subclass can add any other logic as needed. For instance, if you are aggregating YUI resources, your AbstractResourceAggregatingHeaderResponse.renderCollection(Set, Object, ResourceReferenceCollection) method might have rendered only a YUI constructor that loaded all the JS files for each group. Then, you need to loop through the references again, and render any JS inside a sandboxed YUI.use() statement. You would render those here by creating the YUI.use statement, and call getHeaderResponse().renderJavaScript(yourJS, null)

Overrides:
onAllCollectionsRendered in class AbstractResourceAggregatingHeaderResponse<HttpAggregatingResourceReferenceCollection,BasicGroupingKey>
Parameters:
allTopLevelReferences - all the references that were rendered by the developers

newResourceReferenceCollection

protected HttpAggregatingResourceReferenceCollection newResourceReferenceCollection(BasicGroupingKey key)
Description copied from class: AbstractResourceAggregatingHeaderResponse
creates a ResourceReferenceCollection. If you want a specific type of ResourceReferenceCollection for your subclass of AbstractResourceAggregatingHeaderResponse, override this method. Note that because of the generics definition, you will probably have to cast to R. R is the parameter used when creating your subclass defining the type of ResourceReferenceCollection this returns and is passed into all methods that take a ResourceReferenceCollection

Overrides:
newResourceReferenceCollection in class AbstractResourceAggregatingHeaderResponse<HttpAggregatingResourceReferenceCollection,BasicGroupingKey>
Parameters:
key - the grouping key that will be used for this collection. all references added to it will have the same key
Returns:
a newly created collection to contain resource references

newGroupingKey

protected BasicGroupingKey newGroupingKey(ResourceReferenceAndStringData ref)
Description copied from class: AbstractResourceAggregatingHeaderResponse
This key is what is used to determine how to group (or aggregate) your resources. It must implement equals and hashCode correctly so that it can be used as a key in a HashMap. These methods must be implemented so that if two references are given over the course of the hierarchy traversal, and those two references should be grouped (or aggregated), the keys returned for each should equal each other and their hash codes should be equal as well. Typical implementations should use whether or not the resource reference is CSS as their first grouping parameter, since you don't want to render JS and CSS in the same tag (one needs to be in a link tag and one in a script tag). Note that if your grouping key class (K) does not implement Comparable<K>, you must also override AbstractResourceAggregatingHeaderResponse.getGroupingKeyComparator() and return a valid comparator that sorts keys in the order you want references rendered.

Specified by:
newGroupingKey in class AbstractResourceAggregatingHeaderResponse<HttpAggregatingResourceReferenceCollection,BasicGroupingKey>
Parameters:
ref - the resource reference with associated data that came from the render*Reference methods
Returns:
a new key used to group the references.

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.

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

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

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


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