- Direct Known Subclasses:
 ClasspathResourceHelper,FaceletWebappResourceHelper,WebappResourceHelper
- Since:
 - 2.0
 
- 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprotected booleanThis method attempt to verify that the user agent can accept a gzip encoded response by interrogating theAccept-Encodingrequester header.protected booleanUtility method to compress the content of the original resource to the temporary directory specified byClientResourceInfo.getCompressedPath().abstract LibraryInfofindLibrary(String libraryName, String localePrefix, String contract, FacesContext ctx) Search for the specified library/localPrefix combination in an implementation dependent manner.abstract ResourceInfofindResource(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.abstract Stringprotected StringgetBasePath(String contract) abstract StringgetInputStream(ResourceInfo toStream, FacesContext ctx) If the resource is compressable, return an InputStream to read the compressed content, otherwise, callgetNonCompressedInputStream(ResourceInfo, jakarta.faces.context.FacesContext)to return the content of the original resource.longgetLastModified(ResourceInfo resource, FacesContext ctx) The default implementation of this method will call through togetURL(ResourceInfo, jakarta.faces.context.FacesContext)and leverage the URL to obtain the date information of the resource and return the value ofURLConnection.getLastModified()getLocalizedPaths(String path, FacesContext ctx) protected abstract InputStreamgetNonCompressedInputStream(ResourceInfo info, FacesContext ctx) If aResourceInfois not compressable,getInputStream(ResourceInfo, jakarta.faces.context.FacesContext)will call this method to return a stream to the actual resource.abstract URLgetURL(ResourceInfo resource, FacesContext ctx) protected VersionInfogetVersion(Collection<String> resourcePaths, boolean isResource) Given a collection of path names:protected ClientResourceInfohandleCompression(ClientResourceInfo resource) Utility method to peform the necessary actions to compress content.protected booleanresourceSupportsEL(String resourceName, String libraryName, FacesContext ctx) protected String 
- 
Constructor Details
- 
ResourceHelper
public ResourceHelper() 
 - 
 - 
Method Details
- 
getBaseResourcePath
- Returns:
 - the base path in which resources will be stored
 
 - 
getBaseContractsPath
 - 
getBasePath
 - 
getInputStream
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- the resource to obtain an InputStream toctx- theFacesContextfor the current request- Returns:
 - an 
InputStreamto the resource, ornullif no resource is found - Throws:
 IOException- if an error occurs obtaining the stream
 - 
getURL
- Parameters:
 resource- the resource to obtain a URL reference toctx- theFacesContextfor the current request- Returns:
 - a URL to the specified resource, otherwise 
nullif no resource is found 
 - 
findLibrary
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- the name of the librarylocalePrefix- the logicial identifier for a locale specific library. if no localePrefix is configured, passnullcontract- the name of the contractctx- theFacesContextfor the current request @return aLibraryInfoif a matching library based off the inputs can be found, otherwise returnsnull- Returns:
 - library info
 
 - 
findResource
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- 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 passnullresourceName- the name of the resource that is being searched forlocalePrefix- the logicial identifier for a locale specific library. if no localePrefix is configured, passnullcompressable-trueif the resource can be compressedctx- theFacesContextfor the current request- Returns:
 - a 
ResourceInfoif a matching resource based off the inputs can be found, otherwise returnsnull 
 - 
getLastModified
The default implementation of this method will call through to
getURL(ResourceInfo, jakarta.faces.context.FacesContext)and leverage the URL to obtain the date information of the resource and return the value ofURLConnection.getLastModified()- Parameters:
 resource- the resource in questionctx- theFacesContextfor the current request- Returns:
 - the date of the resource in milliseconds (since epoch), or 
0if the date cannot be determined 
 - 
getNonCompressedInputStream
protected abstract InputStream getNonCompressedInputStream(ResourceInfo info, FacesContext ctx) throws IOException If aResourceInfois not compressable,getInputStream(ResourceInfo, jakarta.faces.context.FacesContext)will call this method to return a stream to the actual resource.- Parameters:
 info- the resource to obtain an InputStream toctx- theFacesContextfor the current request- Returns:
 - an InputStream to the resource
 - Throws:
 IOException- if an error occurs obtaining the stream
 - 
getVersion
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- a collection of paths (consisting of single path elements)isResource-trueif the version being looked up is for a reource, otherwise, passfalseif the version is a library version- Returns:
 - the latest version or if no version can be detected, otherwise this method returns 
null 
 - 
compressContent
Utility method to compress the content of the original resource to the temporary directory specified byClientResourceInfo.getCompressedPath().- Parameters:
 info- the resource to be compressed- Returns:
 trueif compression succeeded and the compressed result is smaller than the original content, otherwisefalse- Throws:
 IOException- if any error occur reading/writing
 - 
clientAcceptsCompression
This method attempt to verify that the user agent can accept a gzip encoded response by interrogating the
Accept-Encodingrequester header. If it is determined safe to send a gzip encoded response, send theContent-Encodingheader with a value ofgzip.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
HttpServletResponseas this method will only be called when handling a resource request. Resource serving is outside of the Faces and Portlet lifecycle.- Parameters:
 ctx- theFacesContextfor the current request- Returns:
 trueif compressed content can be sent to the client, otherwisefalse
 - 
handleCompression
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
ResourceInfoas non-compressable.- Parameters:
 resource- the resource to compression- 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.
 
 - 
resourceSupportsEL
 - 
trimLeadingSlash
 - 
getLocalizedPaths
 
 -