com.sun.faces.application.resource
public abstract class ResourceHelper extends java.lang.Object
Implementations of this class contain the knowledge for finding and serving web application resources.
Modifier and Type | Class and Description |
---|---|
private static class |
ResourceHelper.ELEvaluatingInputStream |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
COMPRESSED_CONTENT_FILENAME
Arbitrary file name to write the compressed bits to.
|
private static java.lang.String[] |
EL_CONTENT_TYPES |
private static java.util.regex.Pattern |
LIBRARY_VERSION_PATTERN
This pattern represents a version for a library.
|
private static java.util.logging.Logger |
LOGGER |
private static java.util.regex.Pattern |
RESOURCE_VERSION_PATTERN
This pattern represents a version for a resource.
|
Constructor and Description |
---|
ResourceHelper() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
clientAcceptsCompression(javax.faces.context.FacesContext ctx)
This method attempt to verify that the user agent can accept a gzip
encoded response by interrogating the
Accept-Encoding
requester header. |
protected boolean |
compressContent(ResourceInfo info)
Utility method to compress the content of the original resource
to the temporary directory specified by
ResourceInfo.getCompressedPath() . |
abstract LibraryInfo |
findLibrary(java.lang.String libraryName,
java.lang.String localePrefix,
javax.faces.context.FacesContext ctx)
Search for the specified library/localPrefix combination in an
implementation dependent manner.
|
abstract ResourceInfo |
findResource(LibraryInfo library,
java.lang.String resourceName,
java.lang.String localePrefix,
boolean compressable,
javax.faces.context.FacesContext ctx)
Search for the specified resource based in the library/localePrefix/resourceName
combination in an implementation dependent manner.
|
abstract java.lang.String |
getBaseResourcePath() |
java.io.InputStream |
getInputStream(ResourceInfo resource,
javax.faces.context.FacesContext ctx)
If the resource is compressable, return an InputStream to read the
compressed content, otherwise, call
getNonCompressedInputStream(ResourceInfo, javax.faces.context.FacesContext)
to return the content of the original resource. |
long |
getLastModified(ResourceInfo resource,
javax.faces.context.FacesContext ctx)
The default implementation of this method will call through to
getURL(ResourceInfo, javax.faces.context.FacesContext)
and leverage the URL to obtain the date information of the resource and
return the value of URLConnection.getLastModified() |
protected abstract java.io.InputStream |
getNonCompressedInputStream(ResourceInfo info,
javax.faces.context.FacesContext ctx)
If a
ResourceInfo is not compressable, getInputStream(ResourceInfo, javax.faces.context.FacesContext)
will call this method to return a stream to the actual resource. |
abstract java.net.URL |
getURL(ResourceInfo resource,
javax.faces.context.FacesContext ctx) |
protected VersionInfo |
getVersion(java.util.Collection<java.lang.String> resourcePaths,
boolean isResource)
Given a collection of path names:
|
private VersionInfo |
getVersion(java.lang.String pathElement,
boolean isResource) |
protected ResourceInfo |
handleCompression(ResourceInfo resource)
Utility method to peform the necessary actions to compress content.
|
private ResourceInfo |
rebuildAsNonCompressed(ResourceInfo resource) |
protected boolean |
resourceSupportsEL(java.lang.String resourceName,
javax.faces.context.FacesContext ctx) |
private static final java.util.logging.Logger LOGGER
private static final java.util.regex.Pattern LIBRARY_VERSION_PATTERN
private static final java.util.regex.Pattern RESOURCE_VERSION_PATTERN
private static final java.lang.String COMPRESSED_CONTENT_FILENAME
private static final java.lang.String[] EL_CONTENT_TYPES
public abstract java.lang.String getBaseResourcePath()
public java.io.InputStream getInputStream(ResourceInfo resource, javax.faces.context.FacesContext ctx) throws java.io.IOException
If the resource is compressable, return an InputStream to read the
compressed content, otherwise, call getNonCompressedInputStream(ResourceInfo, javax.faces.context.FacesContext)
to return the content of the original resource.
Implementation Note: If any exception occurs trying to return a stream to the compressed content, log the exception, and instead try to return a stream to the original content.
resource
- the resource to obtain an InputStream toctx
- the FacesContext
for the current requestInputStream
to the resource, or
null
if no resource is foundjava.io.IOException
- if an error occurs obtaining the streampublic abstract java.net.URL getURL(ResourceInfo resource, javax.faces.context.FacesContext ctx)
resource
- the resource to obtain a URL reference toctx
- the FacesContext
for the current requestnull
if no resource is foundpublic abstract LibraryInfo findLibrary(java.lang.String libraryName, java.lang.String localePrefix, javax.faces.context.FacesContext ctx)
libraryName
- the name of the librarylocalePrefix
- the logicial identifier for a locale specific library.
if no localePrefix is configured, pass null
ctx
- the FacesContext
for the current requestLibraryInfo
if a matching library based off the inputs
can be found, otherwise returns null
public abstract ResourceInfo findResource(LibraryInfo library, java.lang.String resourceName, java.lang.String localePrefix, boolean compressable, javax.faces.context.FacesContext ctx)
Search for the specified resource based in the library/localePrefix/resourceName combination in an implementation dependent manner.
If the resource is found, and is compressable, call handleCompression(ResourceInfo)
to compress the content.
library
- the library this resource should be a part of. If the
the resource that is being searched for isn't part of a library, then
pass null
resourceName
- the name of the resource that is being searched forlocalePrefix
- the logicial identifier for a locale specific library.
if no localePrefix is configured, pass null
compressable
- true
if the resource can be compressedctx
- the FacesContext
for the current requestResourceInfo
if a matching resource based off the inputs
can be found, otherwise returns null
public long getLastModified(ResourceInfo resource, javax.faces.context.FacesContext ctx)
The default implementation of this method will call through to
getURL(ResourceInfo, javax.faces.context.FacesContext)
and leverage the URL to obtain the date information of the resource and
return the value of URLConnection.getLastModified()
resource
- the resource in questionctx
- the FacesContext
for the current request0
if the date cannot be determinedprotected abstract java.io.InputStream getNonCompressedInputStream(ResourceInfo info, javax.faces.context.FacesContext ctx) throws java.io.IOException
ResourceInfo
is not compressable, getInputStream(ResourceInfo, javax.faces.context.FacesContext)
will call this method to return a stream to the actual resource.info
- the resource to obtain an InputStream toctx
- the FacesContext
for the current requestjava.io.IOException
- if an error occurs obtaining the streamprotected VersionInfo getVersion(java.util.Collection<java.lang.String> resourcePaths, boolean isResource)
Given a collection of path names:
1.1, scripts, images, 1.2
this method will pick out the directories that represent a library or resource version and return the latest version found, if any.
resourcePaths
- a collection of paths (consisting of single path
elements)isResource
- true
if the version being looked up
is for a reource, otherwise, pass false
if the version
is a library versionnull
protected boolean compressContent(ResourceInfo info) throws java.io.IOException
ResourceInfo.getCompressedPath()
.info
- the resource to be compressedtrue
if compression succeeded and the compressed
result is smaller than the original content, otherwise false
java.io.IOException
- if any error occur reading/writingprotected boolean clientAcceptsCompression(javax.faces.context.FacesContext ctx)
This method attempt to verify that the user agent can accept a gzip
encoded response by interrogating the Accept-Encoding
requester header. If it is determined safe to send a gzip encoded
response, send the Content-Encoding
header with a value
of gzip
.
See Parameters:ctx
- the FacesContext
for the current requesttrue
if compressed content can be sent to the client,
otherwise false
protected ResourceInfo handleCompression(ResourceInfo resource)
Utility method to peform the necessary actions to compress content.
Implmentation Note: If an exception occurs while compressing the content,
log the IOException and rebuilt the ResourceInfo
as non-compressable.
resource
- the resource to compressionprotected boolean resourceSupportsEL(java.lang.String resourceName, javax.faces.context.FacesContext ctx)
private ResourceInfo rebuildAsNonCompressed(ResourceInfo resource)
private VersionInfo getVersion(java.lang.String pathElement, boolean isResource)
pathElement
- the path element to verifyisResource
- true
if the version being looked up
is for a reource, otherwise, pass false
if the version
is a library versiontrue
if this path element represents a version
(i.e. matches LIBRARY_VERSION_PATTERN
), otherwise
returns false
Copyright © 2002-2010 Oracle America, Inc. All Rights Reserved.