Class PackageResource
java.lang.Object
org.apache.wicket.request.resource.AbstractResource
org.apache.wicket.request.resource.PackageResource
- All Implemented Interfaces:
Serializable
,IStaticCacheableResource
,IResource
,IClusterable
- Direct Known Subclasses:
CssPackageResource
,JavaScriptPackageResource
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
ResourceSettings.getPackageResourceGuard()
as well.- Author:
- Jonathan Locke, Eelco Hillenius, Juergen Donnerstag, Matej Knopp, Tobias Soloschenko
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
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.ContentRangeType, 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
CONTENT_DISPOSITION_HEADER_NAME, CONTENT_RANGE_ENDBYTE, CONTENT_RANGE_STARTBYTE, INTERNAL_HEADERS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Checks whether access is granted for this resource.protected byte[]
compressResponse
(IResource.Attributes attributes, byte[] original) Compresses the response if its is eligible and there is a configured compressorboolean
static boolean
Checks whether a resource for a given set of criteria exists.static boolean
Checks whether a resource for a given set of criteria exists.get unique caching key for the resource stream produced byIStaticCacheableResource.getResourceStream()
boolean
protected ITextResourceCompressor
Gets theIJavaScriptCompressor
to be used.final String
getName()
protected Charset
locate resource stream for current resourcefinal Class<?>
getScope()
Gets the scoping class, used for class loading and to determine the package.final String
getStyle()
Gets the style.get text encoding (intented for character-based resources)int
hashCode()
boolean
Returns true if the caching for this resource is enabledprotected AbstractResource.ResourceResponse
newResourceResponse
(IResource.Attributes attributes) creates a new resource response based on the request attributesprotected byte[]
processResponse
(IResource.Attributes attributes, byte[] original) Gives a chance to modify the resource going to be written in the responsereadBuffered
(boolean readBuffered) If the package resource should be read buffered.
WARNING - if the stream is not read buffered compressors will not work, because they require the whole content to be read into memory.
(IJavaScriptCompressor
,
ICssCompressor
,
IScopeAwareTextResourceProcessor
)void
setCachingEnabled
(boolean enabled) Sets the caching for this resource to be enabledvoid
setCompress
(boolean compress) void
setTextEncoding
(String textEncoding) set text encoding (intented for character-based resources)toString()
Methods inherited from class org.apache.wicket.request.resource.AbstractResource
configureCache, getCachingStrategy, respond, setRequestMetaData, setRequestRangeMetaData, setResponseContentRangeHeaderFields, setResponseHeaders
-
Constructor Details
-
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 inname
- The relative path to the resourcelocale
- The locale of the resourcestyle
- The style of the resourcevariation
- The component's variation (of the style)
-
-
Method Details
-
isCachingEnabled
Returns true if the caching for this resource is enabled- Specified by:
isCachingEnabled
in interfaceIStaticCacheableResource
- Returns:
- if the caching is enabled
-
setCachingEnabled
Sets the caching for this resource to be enabled- Parameters:
enabled
- if the cacheing should be enabled
-
getTextEncoding
get text encoding (intented for character-based resources)- Returns:
- custom encoding or
null
to use default
-
setTextEncoding
set text encoding (intented for character-based resources)- Parameters:
textEncoding
- custom encoding ornull
to use default
-
getCacheKey
Description copied from interface:IStaticCacheableResource
get unique caching key for the resource stream produced byIStaticCacheableResource.getResourceStream()
- Specified by:
getCacheKey
in interfaceIStaticCacheableResource
- Returns:
- serializable key which properly supports
Object.equals(Object)
andObject.hashCode()
-
getScope
Gets the scoping class, used for class loading and to determine the package.- Returns:
- the scoping class
-
getName
-
getStyle
Gets the style.- Returns:
- the style
-
newResourceResponse
creates a new resource response based on the request attributes- Specified by:
newResourceResponse
in classAbstractResource
- Parameters:
attributes
- current request attributes from client- Returns:
- resource response for answering request
-
processResponse
Gives a chance to modify the resource going to be written in the response- Parameters:
attributes
- current request attributes from clientoriginal
- the original response- Returns:
- the processed response
-
compressResponse
Compresses the response if its is eligible and there is a configured compressor- Parameters:
attributes
- * current request attributes from client * @param original * the original response * @return the compressed response
-
getProcessingEncoding
- Returns:
- The charset to use to read the resource
-
getCompressor
Gets theIJavaScriptCompressor
to be used. By default returns the configured compressor on application level, but can be overriden by the user application to provide compressor specific to the resource.- Returns:
- the configured application level JavaScript compressor. May be
null
.
-
getResourceStream
locate resource stream for current resource- Specified by:
getResourceStream
in interfaceIStaticCacheableResource
- Returns:
- resource stream or
null
if not found
-
getCompress
- Returns:
- whether
ITextResourceCompressor
can be used to compress the resource.
-
setCompress
- Parameters:
compress
- A flag indicating whether the resource should be compressed.
-
accept
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:
path
- resource path- Returns:
true
if resource access is granted
-
exists
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 methodpath
- The path to the resourcelocale
- The locale of the resourcestyle
- The style of the resource (seeSession
)variation
- The component's variation (of the style)- Returns:
true
if a resource could be loaded,false
otherwise
-
toString
-
hashCode
-
equals
-
readBuffered
If the package resource should be read buffered.
WARNING - if the stream is not read buffered compressors will not work, because they require the whole content to be read into memory.
(IJavaScriptCompressor
,
ICssCompressor
,
IScopeAwareTextResourceProcessor
)- Parameters:
readBuffered
- if the package resource should be read buffered- Returns:
- the current package resource
-