Top Description Inners Fields Constructors Methods
com.sun.faces.application.resource

public abstract Class ResourceHelper

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.faces.application.resource.WebappResourceHelper, com.sun.faces.application.resource.ClasspathResourceHelper, com.sun.faces.application.resource.FaceletWebappResourceHelper
Static Imports
jakarta.faces.application.ResourceHandler.FACES_SCRIPT_LIBRARY_NAME, .ResourceHandler.FACES_SCRIPT_RESOURCE_NAME

Implementations of this class contain the knowledge for finding and serving web application resources.
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final String
COMPRESSED_CONTENT_FILENAME

Arbitrary file name to write the compressed bits to.

private static final String[]
private static final Pattern
LIBRARY_VERSION_PATTERN

This pattern represents a version for a library.

private static final Logger
private static final Pattern
RESOURCE_VERSION_PATTERN

This pattern represents a version for a resource.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

true if compressed content can be sent to the client, otherwise false
clientAcceptsCompression
(FacesContext
the FacesContext for the current request
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

Returns:

true if compression succeeded and the compressed result is smaller than the original content, otherwise false
compressContent
(ClientResourceInfo
the resource to be compressed
info
)

Utility method to compress the content of the original resource to the temporary directory specified by com.sun.faces.application.resource.ClientResourceInfo#getCompressedPath().

public abstract LibraryInfo

Returns:

library info
findLibrary
(String
the name of the library
libraryName
,
String
the logicial identifier for a locale specific library. if no localePrefix is configured, pass null
localePrefix
,
String
the name of the contract
contract
,
FacesContext
the jakarta.faces.context.FacesContext for the current request @return a LibraryInfo if a matching library based off the inputs can be found, otherwise returns null
ctx
)

Search for the specified library/localPrefix combination in an implementation dependent manner.

public abstract ResourceInfo

Returns:

a ResourceInfo if a matching resource based off the inputs can be found, otherwise returns null
findResource
(LibraryInfo
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
library
,
String
the name of the resource that is being searched for
resourceName
,
String
the logicial identifier for a locale specific library. if no localePrefix is configured, pass null
localePrefix
,
boolean
true if the resource can be compressed
compressable
,
FacesContext
the jakarta.faces.context.FacesContext for the current request
ctx
)

Search for the specified resource based in the library/localePrefix/resourceName combination in an implementation dependent manner.

public abstract String
protected String
getBasePath(String contract)

public abstract String

Returns:

the base path in which resources will be stored
getBaseResourcePath
()

public InputStream

Returns:

an InputStream to the resource, or null if no resource is found
getInputStream
(ResourceInfo
the resource to obtain an InputStream to
toStream
,
FacesContext
the jakarta.faces.context.FacesContext for the current request
ctx
)

If the resource is compressable, return an InputStream to read the compressed content, otherwise, call getNonCompressedInputStream(ResourceInfo, jakarta.faces.context.FacesContext) to return the content of the original resource.

private InputStream
public long

Returns:

the date of the resource in milliseconds (since epoch), or 0 if the date cannot be determined
getLastModified
(ResourceInfo
the resource in question
resource
,
FacesContext
the FacesContext for the current request
ctx
)

The default implementation of this method will call through to ResourceHelper#getURL(ResourceInfo, jakarta.faces.context.FacesContext) and leverage the URL to obtain the date information of the resource and return the value of URLConnection.getLastModified()

protected List<String>
protected abstract InputStream

Returns:

an InputStream to the resource
getNonCompressedInputStream
(ResourceInfo
the resource to obtain an InputStream to
info
,
FacesContext
the FacesContext for the current request
ctx
)

If a ResourceInfo is not compressable, getInputStream(ResourceInfo, jakarta.faces.context.FacesContext) will call this method to return a stream to the actual resource.

public abstract URL

Returns:

a URL to the specified resource, otherwise null if no resource is found
getURL
(ResourceInfo
the resource to obtain a URL reference to
resource
,
FacesContext
the FacesContext for the current request
ctx
)

protected VersionInfo

Returns:

the latest version or if no version can be detected, otherwise this method returns null
getVersion
(Collection<String>
a collection of paths (consisting of single path elements)
resourcePaths
,
boolean
true if the version being looked up is for a reource, otherwise, pass false if the version is a library version
isResource
)

Given a collection of path names:

  1.1, scripts, images, 1.2
private VersionInfo

Returns:

true if this path element represents a version (i.e. matches LIBRARY_VERSION_PATTERN), otherwise returns false
getVersion
(String
the path element to verify
pathElement
,
boolean
true if the version being looked up is for a reource, otherwise, pass false if the version is a library version
isResource
)

protected ClientResourceInfo

Returns:

the ResourceInfo after compression is complete. If compression was successful, this should be the same instance. If compression was not successful, it will be a different instance than what was passed.
handleCompression
(ClientResourceInfo
the resource to compression
resource
)

Utility method to peform the necessary actions to compress content.

private ClientResourceInfo
protected boolean
resourceSupportsEL(String resourceName, String libraryName, FacesContext ctx)

protected String

Returns:

the String without a leading slash if it has one.
trimLeadingSlash
(String
input String
s
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COMPRESSED_CONTENT_FILENAMEback to summary
private static final String COMPRESSED_CONTENT_FILENAME

Arbitrary file name to write the compressed bits to.

EL_CONTENT_TYPESback to summary
private static final String[] EL_CONTENT_TYPES
LIBRARY_VERSION_PATTERNback to summary
private static final Pattern LIBRARY_VERSION_PATTERN

This pattern represents a version for a library. Examples: 1_1 1_11 1_11_1 1_11_1_2

LOGGERback to summary
private static final Logger LOGGER
RESOURCE_VERSION_PATTERNback to summary
private static final Pattern RESOURCE_VERSION_PATTERN

This pattern represents a version for a resource. Examples: 1_1.jpg 1_11.323 1_11_1.gif 1_11_1_2.txt 1_1 1_11 1_11_1 1_11_1_2 The extension is optional.

Constructor Detail

ResourceHelperback to summary
public ResourceHelper()

Method Detail

clientAcceptsCompressionback to summary
protected boolean clientAcceptsCompression(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 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616, sec. 14 for details on the accept-encoding header.

Implementation Note

It is safe to cast to a HttpServletResponse as this method will only be called when handling a resource request. Resource serving is outside of the Faces and Portlet lifecycle.

Parameters
ctx:FacesContext

the FacesContext for the current request

Returns:boolean

true if compressed content can be sent to the client, otherwise false

compressContentback to summary
protected boolean compressContent(ClientResourceInfo info) throws IOException

Utility method to compress the content of the original resource to the temporary directory specified by com.sun.faces.application.resource.ClientResourceInfo#getCompressedPath().

Parameters
info:ClientResourceInfo

the resource to be compressed

Returns:boolean

true if compression succeeded and the compressed result is smaller than the original content, otherwise false

Exceptions
IOException:
if any error occur reading/writing
findLibraryback to summary
public abstract LibraryInfo findLibrary(String libraryName, String localePrefix, String contract, FacesContext ctx)

Search for the specified library/localPrefix combination in an implementation dependent manner.

Parameters
libraryName:String

the name of the library

localePrefix:String

the logicial identifier for a locale specific library. if no localePrefix is configured, pass null

contract:String

the name of the contract

ctx:FacesContext

the jakarta.faces.context.FacesContext for the current request @return a LibraryInfo if a matching library based off the inputs can be found, otherwise returns null

Returns:LibraryInfo

library info

findResourceback to summary
public abstract ResourceInfo findResource(LibraryInfo library, String resourceName, String localePrefix, boolean compressable, 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(com.sun.faces.application.resource.ClientResourceInfo) to compress the content.

Parameters
library:LibraryInfo

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:String

the name of the resource that is being searched for

localePrefix:String

the logicial identifier for a locale specific library. if no localePrefix is configured, pass null

compressable:boolean

true if the resource can be compressed

ctx:FacesContext

the jakarta.faces.context.FacesContext for the current request

Returns:ResourceInfo

a ResourceInfo if a matching resource based off the inputs can be found, otherwise returns null

getBaseContractsPathback to summary
public abstract String getBaseContractsPath()
getBasePathback to summary
protected String getBasePath(String contract)
getBaseResourcePathback to summary
public abstract String getBaseResourcePath()
Returns:String

the base path in which resources will be stored

getInputStreamback to summary
public InputStream getInputStream(ResourceInfo toStream, FacesContext ctx) throws IOException

If the resource is compressable, return an InputStream to read the compressed content, otherwise, call getNonCompressedInputStream(ResourceInfo, jakarta.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.

Parameters
toStream:ResourceInfo

the resource to obtain an InputStream to

ctx:FacesContext

the jakarta.faces.context.FacesContext for the current request

Returns:InputStream

an InputStream to the resource, or null if no resource is found

Exceptions
IOException:
if an error occurs obtaining the stream
getInputStreamFromClientInfoback to summary
private InputStream getInputStreamFromClientInfo(ClientResourceInfo resource, FacesContext ctx) throws IOException
getLastModifiedback to summary
public long getLastModified(ResourceInfo resource, FacesContext ctx)

The default implementation of this method will call through to ResourceHelper#getURL(ResourceInfo, jakarta.faces.context.FacesContext) and leverage the URL to obtain the date information of the resource and return the value of URLConnection.getLastModified()

Parameters
resource:ResourceInfo

the resource in question

ctx:FacesContext

the FacesContext for the current request

Returns:long

the date of the resource in milliseconds (since epoch), or 0 if the date cannot be determined

getLocalizedPathsback to summary
protected List<String> getLocalizedPaths(String path, FacesContext ctx)
getNonCompressedInputStreamback to summary
protected abstract InputStream getNonCompressedInputStream(ResourceInfo info, FacesContext ctx) throws IOException

If a ResourceInfo is not compressable, getInputStream(ResourceInfo, jakarta.faces.context.FacesContext) will call this method to return a stream to the actual resource.

Parameters
info:ResourceInfo

the resource to obtain an InputStream to

ctx:FacesContext

the FacesContext for the current request

Returns:InputStream

an InputStream to the resource

Exceptions
IOException:
if an error occurs obtaining the stream
getURLback to summary
public abstract URL getURL(ResourceInfo resource, FacesContext ctx)
Parameters
resource:ResourceInfo

the resource to obtain a URL reference to

ctx:FacesContext

the FacesContext for the current request

Returns:URL

a URL to the specified resource, otherwise null if no resource is found

getVersionback to summary
protected VersionInfo getVersion(Collection<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.

Parameters
resourcePaths:Collection<String>

a collection of paths (consisting of single path elements)

isResource:boolean

true if the version being looked up is for a reource, otherwise, pass false if the version is a library version

Returns:VersionInfo

the latest version or if no version can be detected, otherwise this method returns null

getVersionback to summary
private VersionInfo getVersion(String pathElement, boolean isResource)
Parameters
pathElement:String

the path element to verify

isResource:boolean

true if the version being looked up is for a reource, otherwise, pass false if the version is a library version

Returns:VersionInfo

true if this path element represents a version (i.e. matches LIBRARY_VERSION_PATTERN), otherwise returns false

handleCompressionback to summary
protected ClientResourceInfo handleCompression(ClientResourceInfo 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.

Parameters
resource:ClientResourceInfo

the resource to compression

Returns:ClientResourceInfo

the ResourceInfo after compression is complete. If compression was successful, this should be the same instance. If compression was not successful, it will be a different instance than what was passed.

rebuildAsNonCompressedback to summary
private ClientResourceInfo rebuildAsNonCompressed(ClientResourceInfo resource)
resourceSupportsELback to summary
protected boolean resourceSupportsEL(String resourceName, String libraryName, FacesContext ctx)
trimLeadingSlashback to summary
protected String trimLeadingSlash(String s)
Parameters
s:String

input String

Returns:String

the String without a leading slash if it has one.

com.sun.faces.application.resource back to summary

private final Class ResourceHelper.ELEvaluatingInputStream

extends InputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final List<Integer>
private final FacesContext
private boolean
private boolean
private boolean
private final ClientResourceInfo
private final InputStream
private int
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

private void
private boolean
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

private void
Inherited from java.io.InputStream:
availablemarkmarkSupportednullInputStreamreadreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

bufback to summary
private final List<Integer> buf
ctxback to summary
private final FacesContext ctx
endOfStreamReachedback to summary
private boolean endOfStreamReached
expressionEvaluatedback to summary
private boolean expressionEvaluated
failedExpressionTestback to summary
private boolean failedExpressionTest
infoback to summary
private final ClientResourceInfo info
innerback to summary
private final InputStream inner
nextReadback to summary
private int nextRead
writingExpressionback to summary
private boolean writingExpression

Constructor Detail

ELEvaluatingInputStreamback to summary
public ELEvaluatingInputStream(FacesContext ctx, ClientResourceInfo info, InputStream inner)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
evaluateExpressionIntoBufferback to summary
private void evaluateExpressionIntoBuffer()
isPropertyValidback to summary
private boolean isPropertyValid(String property)
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readExpressionIntoBufferAndEvaluateIntoBufferback to summary
private void readExpressionIntoBufferAndEvaluateIntoBuffer() throws IOException