|
||||||||||
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 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(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(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 |
renderCSS(CharSequence css,
String media)
Renders CSS code to the response, if the CSS has not already been rendered. |
void |
renderCSSReference(ResourceReference reference)
Writes a CSS reference, if the specified reference hasn't been rendered yet. |
void |
renderCSSReference(ResourceReference reference,
PageParameters pageParameters,
String media)
Writes a CSS reference with query parameters, if the specified reference hasn't been rendered yet. |
void |
renderCSSReference(ResourceReference reference,
PageParameters pageParameters,
String media,
String condition)
Writes a conditional IE comment with a CSS reference with query parameters, if the specified reference hasn't been rendered yet. |
void |
renderCSSReference(ResourceReference reference,
String media)
Writes a CSS reference, if the specified reference hasn't been rendered yet. |
void |
renderCSSReference(String url)
Writes a CSS reference, if the specified reference hasn't been rendered yet. |
void |
renderCSSReference(String url,
String media)
Writes a link to a CSS resource, if the specified url hasn't been rendered yet. |
void |
renderCSSReference(String url,
String media,
String condition)
Writes a conditional IE comment for a link to a CSS resource, if the specified url hasn't been rendered yet. |
protected void |
renderIfNotAlreadyRendered(Set<ResourceReferenceAndStringData> alreadyRendered,
ResourceReferenceAndStringData data)
Renders a single resource reference, only if it has not already been rendered. |
void |
renderJavaScript(CharSequence javascript,
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 parameters,
String id)
Writes a javascript reference with query parameters, if the specified reference hasn't been rendered yet. |
void |
renderJavaScriptReference(ResourceReference reference,
PageParameters parameters,
String id,
boolean defer)
Writes a javascript reference with query parameters, if the specified reference hasn't been rendered yet. |
void |
renderJavaScriptReference(ResourceReference reference,
PageParameters parameters,
String id,
boolean defer,
String charset)
Writes a javascript reference with query parameters, if the specified reference hasn't been rendered yet. |
void |
renderJavaScriptReference(ResourceReference reference,
String id)
Writes a javascript reference, if the specified reference hasn't been rendered yet. |
void |
renderJavaScriptReference(String url)
Writes a javascript reference, if the specified reference hasn't been rendered yet. |
void |
renderJavaScriptReference(String url,
String id)
Writes a javascript reference, if the specified reference hasn't been rendered yet. |
void |
renderJavaScriptReference(String url,
String id,
boolean defer)
Writes a javascript reference, if the specified reference hasn't been rendered yet. |
void |
renderJavaScriptReference(String url,
String id,
boolean defer,
String charset)
Writes a javascript reference, if the specified reference hasn't been rendered yet. |
void |
renderOnDomReadyJavaScript(String javascript)
Renders javascript that is executed right after the DOM is built, before external resources (e.g. images) are loaded. |
void |
renderOnEventJavaScript(String target,
String event,
String javascript)
Renders javascript that is executed after the given event happens on specified target |
void |
renderOnLoadJavaScript(String javascript)
Renders javascript that is executed after the entire page is loaded. |
void |
renderString(CharSequence string)
Renders an arbitrary string to the header. |
Methods inherited from class org.apache.wicket.markup.html.DecoratingHeaderResponse |
---|
getRealResponse, getResponse, isClosed, markRendered, 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, 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, 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 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 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(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 IResource
), 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(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(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(String url)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
url
- context-relative url of the the javascript resourcepublic void renderJavaScriptReference(String url, 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(String url)
IHeaderResponse
renderCSSReference
in interface IHeaderResponse
renderCSSReference
in class DecoratingHeaderResponse
url
- context-relative url of the CSS resourcepublic void renderCSSReference(String url, 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.)public void renderJavaScriptReference(ResourceReference reference, PageParameters parameters, String id)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the javascript resourceparameters
- the parameters for this Javascript resource referenceid
- id that will be used to filter duplicate reference (it's still filtered by URL
too)public void renderJavaScriptReference(ResourceReference reference, PageParameters parameters, String id, boolean defer)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the javascript resourceparameters
- the parameters for this Javascript resource referenceid
- id that will be used to filter duplicate reference (it's still filtered by URL
too)defer
- specifies that the execution of a script should be deferred (delayed) until after
the page has been loaded.public void renderJavaScriptReference(ResourceReference reference, PageParameters parameters, String id, boolean defer, String charset)
IHeaderResponse
renderJavaScriptReference
in interface IHeaderResponse
renderJavaScriptReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the javascript resourceparameters
- the parameters for this Javascript resource referenceid
- id that will be used to filter duplicate reference (it's still filtered by URL
too)defer
- specifies that the execution of a script should be deferred (delayed) until after
the page has been loaded.charset
- a non null value specifies the charset attribute of the script tagpublic void renderJavaScriptReference(String url, String id, boolean defer)
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)defer
- specifies that the execution of a script should be deferred (delayed) until after
the page has been loaded.public void renderJavaScriptReference(String url, String id, boolean defer, String charset)
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)defer
- specifies that the execution of a script should be deferred (delayed) until after
the page has been loaded.charset
- a non null value specifies the charset attribute of the script tagpublic void renderJavaScript(CharSequence javascript, String id)
IHeaderResponse
script
tags will be added to the output.
renderJavaScript
in interface IHeaderResponse
renderJavaScript
in class DecoratingHeaderResponse
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.public void renderCSS(CharSequence css, String media)
IHeaderResponse
renderCSS
in interface IHeaderResponse
renderCSS
in class DecoratingHeaderResponse
css
- css content to be rendered.media
- unique id for the <style> element. This can be null
, however in
that case the ajax header contribution can't detect duplicate CSS fragments.public void renderCSSReference(ResourceReference reference, PageParameters pageParameters, String media)
IHeaderResponse
renderCSSReference
in interface IHeaderResponse
renderCSSReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the CSS resourcepageParameters
- the parameters for this CSS resource referencemedia
- the media type for this CSS ("print", "screen", etc.)public void renderCSSReference(ResourceReference reference, PageParameters pageParameters, String media, String condition)
IHeaderResponse
public void renderHead(IHeaderResponse response) {
WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo();
ClientProperties properties = clientInfo.getProperties();
if (properties.isBrowserInternetExplorer() && properties.getBrowserVersionMajor() >= 8) {
response.renderCSSReference(new PackageResourceReference(MyPage.class, "my-conditional.css" ));
}
}
renderCSSReference
in interface IHeaderResponse
renderCSSReference
in class DecoratingHeaderResponse
reference
- resource reference pointing to the CSS resourcepageParameters
- the parameters for this CSS resource referencemedia
- the media type for this CSS ("print", "screen", etc.)condition
- the condition to use for Internet Explorer conditional comments. E.g. "IE 7".public void renderCSSReference(String url, String media, String condition)
IHeaderResponse
public void renderHead(IHeaderResponse response) {
WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo();
ClientProperties properties = clientInfo.getProperties();
if (properties.isBrowserInternetExplorer() && properties.getBrowserVersionMajor() >= 8) {
response.renderCSSReference(new PackageResourceReference(MyPage.class, "my-conditional.css" ));
}
}
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.)condition
- the condition to use for Internet Explorer conditional comments. E.g. "IE 7".public void renderString(CharSequence string)
IHeaderResponse
Note: This method is kind of dangerous as users are able to write to the output whatever they like.
renderString
in interface IHeaderResponse
renderString
in class DecoratingHeaderResponse
string
- string to be rendered to headpublic void renderOnDomReadyJavaScript(String javascript)
IHeaderResponse
renderOnDomReadyJavaScript
in interface IHeaderResponse
renderOnDomReadyJavaScript
in class DecoratingHeaderResponse
public void renderOnLoadJavaScript(String javascript)
IHeaderResponse
renderOnLoadJavaScript
in interface IHeaderResponse
renderOnLoadJavaScript
in class DecoratingHeaderResponse
public void renderOnEventJavaScript(String target, String event, String javascript)
IHeaderResponse
renderOnEventJavaScript
in interface IHeaderResponse
renderOnEventJavaScript
in class DecoratingHeaderResponse
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |