|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.markup.html.DecoratingHeaderResponse org.apache.wicket.resource.aggregation.AbstractResourceAggregatingHeaderResponse<R,K>
R
- the type of ResourceReferenceCollection returned by
newResourceReferenceCollection(Object)
and passed to all the methods that
take a ResourceReferenceCollection. You will typically just use
ResourceReferenceCollection for this param, unless you are returning a specific type
of ResourceReferenceCollection from your subclass.K
- the class of the key that you will create from
newGroupingKey(ResourceReferenceAndStringData)
public abstract class AbstractResourceAggregatingHeaderResponse<R extends ResourceReferenceCollection,K>
A header response that can be used to aggregate resources (primarily resource references) into
groups that can be rendered after the entire hierarchy of IHeaderContributors have been
traversed. A subclass of this could use that group to render a single URL to some aggregating
servlet (for example) that could cut down on the number of HTTP requests the client must make.
Resource references are aggregated according to the key that your subclass creates in the
newGroupingKey(ResourceReferenceAndStringData)
. This key is used in a Map, so it needs
to properly implement hashCode and equals.
If your key does not implement Comparable<KeyClass>, you need to also return a Comparator
for it from the getGroupingKeyComparator()
method.
Constructor Summary | |
---|---|
AbstractResourceAggregatingHeaderResponse(IHeaderResponse real)
Construct. |
Method Summary | |
---|---|
void |
close()
Mark Header rendering is completed and subsequent usage will be ignored. |
protected java.util.Comparator<K> |
getGroupingKeyComparator()
This comparator is used to sort the grouping keys that you return from newGroupingKey(ResourceReferenceAndStringData) . |
protected abstract K |
newGroupingKey(ResourceReferenceAndStringData ref)
This key is what is used to determine how to group (or aggregate) your resources. |
protected R |
newResourceReferenceCollection(K 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 |
render(ResourceReferenceAndStringData data)
Renders a single resource reference. |
protected void |
renderCollection(java.util.Set<ResourceReferenceAndStringData> alreadyRendered,
K key,
R coll)
When the entire hierarchy has been traversed and close() is called, we loop through
the grouped collections and render them in this method. |
void |
renderCSSReference(ResourceReference reference)
Writes a CSS reference, 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. |
protected void |
renderIfNotAlreadyRendered(java.util.Set<ResourceReferenceAndStringData> alreadyRendered,
ResourceReferenceAndStringData data)
Renders a single resource reference, only if it 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,
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. |
Methods inherited from class org.apache.wicket.markup.html.DecoratingHeaderResponse |
---|
getRealResponse, getResponse, isClosed, markRendered, renderCSS, renderCSSReference, renderCSSReference, renderCSSReference, renderJavaScript, renderJavaScriptReference, renderJavaScriptReference, renderJavaScriptReference, renderJavaScriptReference, renderJavaScriptReference, renderOnDomReadyJavaScript, renderOnEventJavaScript, renderOnLoadJavaScript, renderString, wasRendered |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractResourceAggregatingHeaderResponse(IHeaderResponse real)
real
- the wrapped header responseMethod Detail |
---|
public void renderJavaScriptReference(ResourceReference reference)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the javascript resourcepublic void renderJavaScriptReference(ResourceReference reference, java.lang.String id)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the javascript resourceid
- id that will be used to filter duplicate reference (it's still filtered by URL
too)public void renderCSSReference(ResourceReference reference)
IHeaderResponse
renderCSSReference
in interface IHeaderResponse
renderCSSReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the CSS resourcepublic void renderCSSReference(ResourceReference reference, java.lang.String media)
IHeaderResponse
renderCSSReference
in interface IHeaderResponse
renderCSSReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the CSS resourcemedia
- the media type for this CSS ("print", "screen", etc.)public void close()
IHeaderResponse
close
in interface java.io.Closeable
close
in interface IHeaderResponse
close
in class DecoratingHeaderResponse
protected R newResourceReferenceCollection(K key)
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
key
- the grouping key that will be used for this collection. all references added to it
will have the same key
protected abstract K newGroupingKey(ResourceReferenceAndStringData ref)
getGroupingKeyComparator()
and return a valid comparator that sorts
keys in the order you want references rendered.
ref
- the resource reference with associated data that came from the render*Reference
methods
protected java.util.Comparator<K> getGroupingKeyComparator()
newGroupingKey(ResourceReferenceAndStringData)
.
Note that if your grouping key class (K) implements Comparable<K>, you do not need to
override this method.
protected void renderCollection(java.util.Set<ResourceReferenceAndStringData> alreadyRendered, K key, R coll)
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.
alreadyRendered
- a set of resource references that have already been rendered in other groupskey
- they grouping key for this groupcoll
- the collection of resource references to renderprotected void renderIfNotAlreadyRendered(java.util.Set<ResourceReferenceAndStringData> alreadyRendered, ResourceReferenceAndStringData data)
render(ResourceReferenceAndStringData)
directly, which is called from this method if
the resource reference has not been rendered elsewhere.
alreadyRendered
- the set of references that have already been rendered in other groupsdata
- the reference (and associated data) to conditionally render.protected void render(ResourceReferenceAndStringData data)
renderIfNotAlreadyRendered(Set, ResourceReferenceAndStringData)
for references that
had not been rendered elsewhere.
data
- the reference (and associated data) to conditionally render.protected void onAllCollectionsRendered(java.util.List<ResourceReferenceAndStringData> allTopLevelReferences)
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)
allTopLevelReferences
- all the references that were rendered by the developerspublic void renderJavaScriptReference(java.lang.String url)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
url
- context-relative url of the the javascript resourcepublic void renderJavaScriptReference(java.lang.String url, java.lang.String id)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
url
- context-relative url of the the javascript resourceid
- id that will be used to filter duplicate reference (it's still filtered by URL
too)public void renderCSSReference(java.lang.String url)
IHeaderResponse
renderCSSReference
in interface IHeaderResponse
renderCSSReference
in class DecoratingHeaderResponse
url
- context-relative url of the CSS resourcepublic void renderCSSReference(java.lang.String url, java.lang.String media)
IHeaderResponse
renderCSSReference
in interface IHeaderResponse
renderCSSReference
in class DecoratingHeaderResponse
url
- context-relative url of the CSS resourcemedia
- the media type for this CSS ("print", "screen", etc.)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |