org.apache.wicket.markup.html
Class PackageResource

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

public class PackageResource
extends WebResource
implements IModifiable, IPackageResourceGuard

Represents a localizable static resource.

Use like eg:

 PackageResource IMG_UNKNOWN = PackageResource.get(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
See Also:
Serialized Form

Nested Class Summary
static class PackageResource.PackageResourceBlockedException
          Exception thrown when the creation of a package resource is not allowed.
 
Field Summary
static java.util.regex.Pattern EXTENSION_CSS
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static java.util.regex.Pattern EXTENSION_JS
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
 
Fields inherited from interface org.apache.wicket.IResourceListener
INTERFACE
 
Constructor Summary
protected PackageResource(java.lang.Class scope, java.lang.String path, java.util.Locale locale, java.lang.String style)
          Hidden constructor.
 
Method Summary
 boolean accept(java.lang.Class scope, java.lang.String path)
          Whether the package resource that can be reached using the provided parameters may be accessed.
static void bind(Application application, java.lang.Class scope, java.util.regex.Pattern pattern)
          Deprecated. Since Wicket 1.2.1 this method is effectively a no-op. package resources are automatically tried and bound as shared resources so that they don't have to be pre-registered anymore. Will be removed in 2.0
static void bind(Application application, java.lang.Class scope, java.util.regex.Pattern pattern, boolean recurse)
          Deprecated. Since Wicket 1.2.1 this method is effectively a no-op. package resources are automatically tried and bound as shared resources so that they don't have to be pre-registered anymore. Will be removed in 2.0
static void bind(Application application, java.lang.Class scope, java.lang.String name)
          Binds a resource to the given application object.
static void bind(Application application, java.lang.Class scope, java.lang.String name, java.util.Locale locale)
          Binds a resource to the given application object.
static void bind(Application application, java.lang.Class scope, java.lang.String name, java.util.Locale locale, java.lang.String style)
          Binds a resource to the given application object.
static boolean exists(java.lang.Class scope, java.lang.String path, java.util.Locale locale, java.lang.String style)
          Gets whether a resource for a given set of criteria exists.
static PackageResource[] get(java.lang.Class scope, java.util.regex.Pattern pattern)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static PackageResource[] get(java.lang.Class scope, java.util.regex.Pattern pattern, boolean recurse)
          Deprecated. Will be removed in 2.0; contribute resources one by one instead
static PackageResource get(java.lang.Class scope, java.lang.String path)
          Gets a non-localized resource for a given set of criteria.
static PackageResource get(java.lang.Class scope, java.lang.String path, java.util.Locale locale, java.lang.String style)
          Gets the resource for a given set of criteria.
 java.lang.String getAbsolutePath()
          Gets the absolute path of the resource.
 java.util.Locale getLocale()
          Gets the locale.
 java.lang.String getPath()
          Gets the path this resource was created with.
 IResourceStream getResourceStream()
           
 IResourceStream getResourceStream(boolean failOnError)
           
 java.lang.Class getScope()
          Gets the scoping class, used for class loading and to determine the package.
 java.lang.String getStyle()
          Gets the style.
 Time lastModifiedTime()
          Returns the last modified time of resource
protected static PackageResource newPackageResource(java.lang.Class scope, java.lang.String path, java.util.Locale locale, java.lang.String style)
          Create a new PackageResource
 
Methods inherited from class org.apache.wicket.markup.html.WebResource
configureResponse, getCacheDuration, setHeaders
 
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
 

Field Detail

EXTENSION_CSS

public static final java.util.regex.Pattern EXTENSION_CSS
Deprecated. Will be removed in 2.0; contribute resources one by one instead
common extension pattern for css files; matches all files with extension 'css'.


EXTENSION_JS

public static final java.util.regex.Pattern EXTENSION_JS
Deprecated. Will be removed in 2.0; contribute resources one by one instead
common extension pattern for javascript files; matches all files with extension 'js'.

Constructor Detail

PackageResource

protected PackageResource(java.lang.Class scope,
                          java.lang.String path,
                          java.util.Locale locale,
                          java.lang.String style)
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
path - The path to the resource
locale - The locale of the resource
style - The style of the resource
Method Detail

bind

public static void bind(Application application,
                        java.lang.Class scope,
                        java.util.regex.Pattern pattern)
Deprecated. Since Wicket 1.2.1 this method is effectively a no-op. package resources are automatically tried and bound as shared resources so that they don't have to be pre-registered anymore. Will be removed in 2.0

Binds the resources that match the provided pattern to the given application object. Will create any resources if not already in the shared resources of the application object.

Parameters:
application - The application to bind to.
scope - The scope of the resource.
pattern - A regular expression to match against the contents of the package of the provided scope class (eg ".\*\.js" will add all the files with extension "js" from that package).

bind

public static void bind(Application application,
                        java.lang.Class scope,
                        java.util.regex.Pattern pattern,
                        boolean recurse)
Deprecated. Since Wicket 1.2.1 this method is effectively a no-op. package resources are automatically tried and bound as shared resources so that they don't have to be pre-registered anymore. Will be removed in 2.0

Binds the resources that match the provided pattern to the given application object. Will create any resources if not already in the shared resources of the application object and does that recursively when the recurse parameter is true, or just for the scoped package if that parameter is false

Parameters:
application - The application to bind to.
scope - The scope of the resource.
pattern - A regular expression to match against the contents of the package of the provided scope class (eg ".\*\.js" will add all the files with extension "js" from that package).
recurse - Whether this method should recurse into sub packages

bind

public static void bind(Application application,
                        java.lang.Class scope,
                        java.lang.String name)
Binds a resource to the given application object. Will create the resource if not already in the shared resources of the application object.

Parameters:
application - The application to bind to.
scope - The scope of the resource.
name - The name of the resource (like "myfile.js")

bind

public static void bind(Application application,
                        java.lang.Class scope,
                        java.lang.String name,
                        java.util.Locale locale)
Binds a resource to the given application object. Will create the resource if not already in the shared resources of the application object.

Parameters:
application - The application to bind to.
scope - The scope of the resource.
name - The name of the resource (like "myfile.js")
locale - The locale of the resource.

bind

public static void bind(Application application,
                        java.lang.Class scope,
                        java.lang.String name,
                        java.util.Locale locale,
                        java.lang.String style)
Binds a resource to the given application object. Will create the resource if not already in the shared resources of the application object.

Parameters:
application - The application to bind to.
scope - The scope of the resource.
name - The name of the resource (like "myfile.js")
locale - The locale of the resource.
style - The style of the resource.

exists

public static boolean exists(java.lang.Class scope,
                             java.lang.String path,
                             java.util.Locale locale,
                             java.lang.String style)
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)
Returns:
true if a resource could be loaded, false otherwise

get

public static PackageResource[] get(java.lang.Class scope,
                                    java.util.regex.Pattern pattern)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Gets non-localized resources for a given set of criteria. Multiple resource can be loaded for the same criteria if they match the pattern. If no resources were found, this method returns null.

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 calling class/ the class in which you call this method
pattern - Regexp pattern to match resources
Returns:
The resources, never null but may be empty

get

public static PackageResource[] get(java.lang.Class scope,
                                    java.util.regex.Pattern pattern,
                                    boolean recurse)
Deprecated. Will be removed in 2.0; contribute resources one by one instead

Gets non-localized resources for a given set of criteria. Multiple resource can be loaded for the same criteria if they match the pattern. If no resources were found, this method returns null.

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 calling class/ the class in which you call this method
pattern - Regexp pattern to match resources
recurse - Whether this method should recurse into sub packages
Returns:
The resources, never null but may be empty

get

public static PackageResource get(java.lang.Class scope,
                                  java.lang.String path)
Gets a non-localized resource for a given set of criteria. Only one resource will be loaded for the same criteria.

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 calling class/ the class in which you call this method
path - The path to the resource
Returns:
The resource

get

public static PackageResource get(java.lang.Class scope,
                                  java.lang.String path,
                                  java.util.Locale locale,
                                  java.lang.String style)
Gets the resource for a given set of criteria. Only one resource will be loaded for the same criteria.

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)
Returns:
The resource

newPackageResource

protected static PackageResource newPackageResource(java.lang.Class scope,
                                                    java.lang.String path,
                                                    java.util.Locale locale,
                                                    java.lang.String style)
Create a new PackageResource

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)
Returns:
The resource

getAbsolutePath

public final java.lang.String getAbsolutePath()
Gets the absolute path of the resource.

Returns:
the absolute resource path

getLocale

public final java.util.Locale getLocale()
Gets the locale.

Returns:
The Locale of this package resource

getPath

public final java.lang.String getPath()
Gets the path this resource was created with.

Returns:
the path

getResourceStream

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

getResourceStream

public IResourceStream getResourceStream(boolean failOnError)
Parameters:
failOnError - throw an AbortException when resource does not exist
Returns:
Gets the resource for the component.

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

lastModifiedTime

public Time lastModifiedTime()
Returns the last modified time of resource

Specified by:
lastModifiedTime in interface IModifiable
Returns:
last modified time or null if the time can not be determined

accept

public boolean accept(java.lang.Class scope,
                      java.lang.String path)
Description copied from interface: IPackageResourceGuard
Whether the package resource that can be reached using the provided parameters may be accessed.

Specified by:
accept in interface IPackageResourceGuard
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
path - The path to the resource
Returns:
True if access is permitted, false otherwise
See Also:
IPackageResourceGuard.accept(java.lang.Class, java.lang.String)


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