public class PackageResource extends AbstractResource implements IStaticCacheableResource
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.Modifier and Type | Class and Description |
---|---|
static class |
PackageResource.PackageResourceBlockedException
Exception thrown when the creation of a package resource is not allowed.
|
AbstractResource.ContentRangeType, AbstractResource.ResourceResponse, AbstractResource.WriteCallback
IResource.Attributes
CONTENT_DISPOSITION_HEADER_NAME, CONTENT_RANGE_ENDBYTE, CONTENT_RANGE_STARTBYTE, INTERNAL_HEADERS
Modifier | Constructor and Description |
---|---|
protected |
PackageResource(Class<?> scope,
String name,
Locale locale,
String style,
String variation)
Hidden constructor.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
accept(String path)
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 compressor
|
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.
|
Serializable |
getCacheKey()
get unique caching key for the resource stream produced by
IStaticCacheableResource.getResourceStream() |
boolean |
getCompress() |
protected ITextResourceCompressor |
getCompressor()
Gets the
IJavaScriptCompressor to be used. |
String |
getName() |
protected Charset |
getProcessingEncoding() |
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()
Returns true if the caching for this resource is enabled
|
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
|
PackageResource |
readBuffered(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 enabled
|
void |
setCompress(boolean compress) |
void |
setTextEncoding(String textEncoding)
set text encoding (intented for character-based resources)
|
String |
toString() |
configureCache, getCachingStrategy, respond, setRequestMetaData, setRequestRangeMetaData, setResponseContentRangeHeaderFields, setResponseHeaders
protected PackageResource(Class<?> scope, String name, Locale locale, String style, String variation)
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)public boolean isCachingEnabled()
isCachingEnabled
in interface IStaticCacheableResource
public void setCachingEnabled(boolean enabled)
enabled
- if the cacheing should be enabledpublic String getTextEncoding()
null
to use defaultpublic void setTextEncoding(String textEncoding)
textEncoding
- custom encoding or null
to use defaultpublic Serializable getCacheKey()
IStaticCacheableResource
IStaticCacheableResource.getResourceStream()
getCacheKey
in interface IStaticCacheableResource
#equals(Object)
and
#hashCode()
public final Class<?> getScope()
public final String getName()
public final String getStyle()
protected AbstractResource.ResourceResponse newResourceResponse(IResource.Attributes attributes)
newResourceResponse
in class AbstractResource
attributes
- current request attributes from clientprotected byte[] processResponse(IResource.Attributes attributes, byte[] original)
attributes
- current request attributes from clientoriginal
- the original responseprotected byte[] compressResponse(IResource.Attributes attributes, byte[] original)
attributes
- * current request attributes from client
* @param original
* the original response
* @return the compressed responseprotected Charset getProcessingEncoding()
protected ITextResourceCompressor getCompressor()
IJavaScriptCompressor
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.null
.public IResourceStream getResourceStream()
getResourceStream
in interface IStaticCacheableResource
null
if not foundpublic boolean getCompress()
ITextResourceCompressor
can be used to
compress the resource.public void setCompress(boolean compress)
compress
- A flag indicating whether the resource should be compressed.protected boolean accept(String path)
path
- resource pathtrue if resource access is granted
public static boolean exists(ResourceReference.Key key)
key
- The key that contains all attributes about the requested resourcetrue
if there is a package resource with the given attributespublic static boolean exists(Class<?> scope, String path, Locale locale, String style, String variation)
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 (see Session
)variation
- The component's variation (of the style)true
if a resource could be loaded, false
otherwisepublic PackageResource readBuffered(boolean readBuffered)
IJavaScriptCompressor
, ICssCompressor
, IScopeAwareTextResourceProcessor
)readBuffered
- if the package resource should be read bufferedCopyright © 2006–2022 Apache Software Foundation. All rights reserved.