org.apache.wicket.request.resource
Class PackageResource

java.lang.Object
  extended by org.apache.wicket.request.resource.AbstractResource
      extended by org.apache.wicket.request.resource.PackageResource
All Implemented Interfaces:
Serializable, IStaticCacheableResource, IResource, IClusterable
Direct Known Subclasses:
CssPackageResource, JavaScriptPackageResource

public class PackageResource
extends AbstractResource
implements IStaticCacheableResource

Represents a localizable static resource.

Use like eg:

 MyPackageResource IMG_UNKNOWN = new MyPackageResource(EditPage.class, "questionmark.gif");
 
where the static resource references image 'questionmark.gif' from the the package that EditPage is in to get a package resource.

Access to resources can be granted or denied via a IPackageResourceGuard. Please see IResourceSettings.getPackageResourceGuard() as well.

Author:
Jonathan Locke, Eelco Hillenius, Juergen Donnerstag, Matej Knopp
See Also:
Serialized Form

Nested Class Summary
static class PackageResource.PackageResourceBlockedException
          Exception thrown when the creation of a package resource is not allowed.
 
Nested classes/interfaces inherited from class org.apache.wicket.request.resource.AbstractResource
AbstractResource.ResourceResponse, AbstractResource.WriteCallback
 
Nested classes/interfaces inherited from interface org.apache.wicket.request.resource.IResource
IResource.Attributes
 
Field Summary
 
Fields inherited from class org.apache.wicket.request.resource.AbstractResource
INTERNAL_HEADERS
 
Constructor Summary
protected PackageResource(Class<?> scope, String name, Locale locale, String style, String variation)
          Hidden constructor.
 
Method Summary
protected  boolean accept(Class<?> scope, String path)
          Checks whether access is granted for this resource.
 boolean equals(Object obj)
           
static boolean exists(Class<?> scope, String path, Locale locale, String style, String variation)
          Checks whether a resource for a given set of criteria exists.
static boolean exists(ResourceReference.Key key)
          Checks whether a resource for a given set of criteria exists.
 IResourceStream getCacheableResourceStream()
          be aware that method takes the current wicket session's locale and style into account when locating the stream.
 Serializable getCacheKey()
          get unique caching key for the resource stream produced by IStaticCacheableResource.getCacheableResourceStream()
 boolean getCompress()
           
 IResourceStream getResourceStream()
          locate resource stream for current resource
 Class<?> getScope()
          Gets the scoping class, used for class loading and to determine the package.
 String getStyle()
          Gets the style.
 String getTextEncoding()
          get text encoding (intented for character-based resources)
 int hashCode()
           
 boolean isCachingEnabled()
          controls whether caching of the resource is enabled or disabled
protected  AbstractResource.ResourceResponse newResourceResponse(IResource.Attributes attributes)
          creates a new resource response based on the request attributes
protected  byte[] processResponse(IResource.Attributes attributes, byte[] original)
          Gives a chance to modify the resource going to be written in the response
 void setCachingEnabled(boolean enabled)
           
 void setCompress(boolean compress)
           
 void setTextEncoding(String textEncoding)
          set text encoding (intented for character-based resources)
 String toString()
           
 
Methods inherited from class org.apache.wicket.request.resource.AbstractResource
configureCache, flushResponseAfterHeaders, getCachingStrategy, respond, setResponseHeaders
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.wicket.request.resource.IResource
respond
 

Constructor Detail

PackageResource

protected PackageResource(Class<?> scope,
                          String name,
                          Locale locale,
                          String style,
                          String variation)
Hidden constructor.

Parameters:
scope - This argument will be used to get the class loader for loading the package resource, and to determine what package it is in
name - The relative path to the resource
locale - The locale of the resource
style - The style of the resource
variation - The component's variation (of the style)
Method Detail

isCachingEnabled

public boolean isCachingEnabled()
Description copied from interface: IStaticCacheableResource
controls whether caching of the resource is enabled or disabled

Specified by:
isCachingEnabled in interface IStaticCacheableResource
Returns:
@{code true} if caching is enabled

setCachingEnabled

public void setCachingEnabled(boolean enabled)

getTextEncoding

public String getTextEncoding()
get text encoding (intented for character-based resources)

Returns:
custom encoding or null to use default

setTextEncoding

public void setTextEncoding(String textEncoding)
set text encoding (intented for character-based resources)

Parameters:
textEncoding - custom encoding or null to use default

getCacheKey

public Serializable getCacheKey()
Description copied from interface: IStaticCacheableResource
get unique caching key for the resource stream produced by IStaticCacheableResource.getCacheableResourceStream()

Specified by:
getCacheKey in interface IStaticCacheableResource
Returns:
serializable key with properly supports #equals(Object) and #hashCode()

getScope

public final Class<?> getScope()
Gets the scoping class, used for class loading and to determine the package.

Returns:
the scoping class

getStyle

public final String getStyle()
Gets the style.

Returns:
the style

newResourceResponse

protected AbstractResource.ResourceResponse newResourceResponse(IResource.Attributes attributes)
creates a new resource response based on the request attributes

Specified by:
newResourceResponse in class AbstractResource
Parameters:
attributes - current request attributes from client
Returns:
resource response for answering request

processResponse

protected byte[] processResponse(IResource.Attributes attributes,
                                 byte[] original)
Gives a chance to modify the resource going to be written in the response

Parameters:
attributes - current request attributes from client
original - the original response
Returns:
the processed response

getCacheableResourceStream

public IResourceStream getCacheableResourceStream()
be aware that method takes the current wicket session's locale and style into account when locating the stream.

Specified by:
getCacheableResourceStream in interface IStaticCacheableResource
Returns:
resource stream
See Also:
IStaticCacheableResource.getCacheableResourceStream(), getResourceStream()

getResourceStream

public IResourceStream getResourceStream()
locate resource stream for current resource

Returns:
resource stream or null if not found

getCompress

public boolean getCompress()
Returns:
whether ITextResourceCompressor can be used to compress the resource.

setCompress

public void setCompress(boolean compress)
Parameters:
compress - A flag indicating whether the resource should be compressed.

accept

protected boolean accept(Class<?> scope,
                         String path)
Checks whether access is granted for this resource. By default IPackageResourceGuard is used to check the permissions but the resource itself can also make the check.

Parameters:
scope - resource scope
path - resource path
Returns:
true if resource access is granted

exists

public static boolean exists(ResourceReference.Key key)
Checks whether a resource for a given set of criteria exists.

Parameters:
key - The key that contains all attributes about the requested resource
Returns:
true if there is a package resource with the given attributes

exists

public static boolean exists(Class<?> scope,
                             String path,
                             Locale locale,
                             String style,
                             String variation)
Checks whether a resource for a given set of criteria exists.

Parameters:
scope - This argument will be used to get the class loader for loading the package resource, and to determine what package it is in. Typically this is the class in which you call this method
path - The path to the resource
locale - The locale of the resource
style - The style of the resource (see Session)
variation - The component's variation (of the style)
Returns:
true if a resource could be loaded, false otherwise

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


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