org.apache.wicket.markup.html
Class DynamicWebResource

java.lang.Object
  extended by org.apache.wicket.Resource
      extended by org.apache.wicket.markup.html.WebResource
          extended by org.apache.wicket.markup.html.DynamicWebResource
All Implemented Interfaces:
java.io.Serializable, IClusterable, IRequestListener, IResourceListener
Direct Known Subclasses:
DynamicImageResource

public abstract class DynamicWebResource
extends WebResource

An WebResource subclass for dynamic resources (resources created programmatically).

This class caches the generated resource in memory, and is thus very useful for things you generate dynamically, but reuse for a while after that. If you need resources that stream directly and are not cached, extend WebResource directly and implement Resource.getResourceStream() yourself.

Author:
Jonathan Locke, Johan Compagner, Gili Tzabari
See Also:
Serialized Form

Nested Class Summary
static class DynamicWebResource.ResourceState
          The resource state returned by the getResourceState() method.
 
Field Summary
 
Fields inherited from interface org.apache.wicket.IResourceListener
INTERFACE
 
Constructor Summary
DynamicWebResource()
          Creates a dynamic resource.
DynamicWebResource(java.util.Locale locale)
          Creates a dynamic resource from for the given locale
DynamicWebResource(java.util.Locale locale, java.lang.String filename)
          Creates a dynamic resource from for the given locale
DynamicWebResource(java.lang.String filename)
          Creates a dynamic resource.
 
Method Summary
 java.util.Locale getLocale()
          Returns the resource locale.
protected abstract  DynamicWebResource.ResourceState getResourceState()
          Gets the byte array for our dynamic resource.
 IResourceStream getResourceStream()
           
protected  void setHeaders(WebResponse response)
          Subclasses can override this to set there headers when the resource is being served.
 
Methods inherited from class org.apache.wicket.markup.html.WebResource
configureResponse, getCacheDuration
 
Methods inherited from class org.apache.wicket.Resource
getParameters, invalidate, isCacheable, onResourceRequested, setCacheable, setParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicWebResource

public DynamicWebResource()
Creates a dynamic resource.


DynamicWebResource

public DynamicWebResource(java.lang.String filename)
Creates a dynamic resource.

Parameters:
filename - The filename that will be set as the Content-Disposition header.

DynamicWebResource

public DynamicWebResource(java.util.Locale locale)
Creates a dynamic resource from for the given locale

Parameters:
locale - The locale of this resource

DynamicWebResource

public DynamicWebResource(java.util.Locale locale,
                          java.lang.String filename)
Creates a dynamic resource from for the given locale

Parameters:
locale - The locale of this resource
filename - The filename that will be set as the Content-Disposition header.
Method Detail

setHeaders

protected void setHeaders(WebResponse response)
Description copied from class: WebResource
Subclasses can override this to set there headers when the resource is being served. By default 2 headers will be set if the Resource is cacheable
 response.setDateHeader("Expires", System.currentTimeMillis() + (3600 * 1000));
 response.setHeader("Cache-Control", "max-age=" + 3600);
 
So if a resource wants to control this or doesn't want to set this info it should override this method and don't call super.

Overrides:
setHeaders in class WebResource
Parameters:
response - The WebResponse where set(Date)Header can be called on.
See Also:
WebResource.setHeaders(org.apache.wicket.protocol.http.WebResponse)

getLocale

public java.util.Locale getLocale()
Returns the resource locale.

Returns:
The locale of this resource

getResourceStream

public IResourceStream getResourceStream()
Specified by:
getResourceStream in class Resource
Returns:
Gets the resource to attach to the component.

getResourceState

protected abstract DynamicWebResource.ResourceState getResourceState()
Gets the byte array for our dynamic resource. If the subclass regenerates the data, it should set the lastModifiedTime too. This ensures that resource caching works correctly.

Returns:
The byte array for this dynamic resource.


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.