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:
java.io.Serializable, IClusterable, IStaticCacheableResource, IResource
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(java.lang.Class<?> scope, java.lang.String name, java.util.Locale locale, java.lang.String style, java.lang.String variation)
          Hidden constructor.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
static boolean exists(java.lang.Class<?> scope, java.lang.String path, java.util.Locale locale, java.lang.String style, java.lang.String variation)
          Gets whether a resource for a given set of criteria exists.
 IResourceStream getCacheableResourceStream()
          get static resource stream which will be unique to the related caching key IStaticCacheableResource.getCacheKey()
 java.io.Serializable getCacheKey()
          get unique caching key for the resource stream produced by IStaticCacheableResource.getCacheableResourceStream()
protected  IResourceStream getResourceStream()
          locate resource stream for current resource
 java.lang.Class<?> getScope()
          Gets the scoping class, used for class loading and to determine the package.
 java.lang.String getStyle()
          Gets the style.
 int hashCode()
           
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
 java.lang.String toString()
           
 
Methods inherited from class org.apache.wicket.request.resource.AbstractResource
configureCache, 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(java.lang.Class<?> scope,
                          java.lang.String name,
                          java.util.Locale locale,
                          java.lang.String style,
                          java.lang.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

getCacheableResourceStream

public IResourceStream getCacheableResourceStream()
Description copied from interface: IStaticCacheableResource
get static resource stream which will be unique to the related caching key IStaticCacheableResource.getCacheKey()

Specified by:
getCacheableResourceStream in interface IStaticCacheableResource
Returns:
stream or null if no stream could be found

getCacheKey

public java.io.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 java.lang.Class<?> getScope()
Gets the scoping class, used for class loading and to determine the package.

Returns:
the scoping class

getStyle

public final java.lang.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

getResourceStream

protected IResourceStream getResourceStream()
locate resource stream for current resource

Returns:
resource stream or null if not found

exists

public static boolean exists(java.lang.Class<?> scope,
                             java.lang.String path,
                             java.util.Locale locale,
                             java.lang.String style,
                             java.lang.String variation)
Gets 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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object


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