ResourceHandler.-
Field Summary
Fields inherited from class jakarta.faces.application.ResourceHandler
FACES_SCRIPT_LIBRARY_NAME, FACES_SCRIPT_RESOURCE_NAME, JSF_SCRIPT_LIBRARY_NAME, JSF_SCRIPT_RESOURCE_NAME, LOCALE_PREFIX, RESOURCE_CONTRACT_XML, RESOURCE_EXCLUDES_DEFAULT_VALUE, RESOURCE_EXCLUDES_PARAM_NAME, RESOURCE_IDENTIFIER, WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME, WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateResource(String resourceName) Create an instance ofViewResourcegiven the argumentresourceName.createResource(String resourceName, String libraryName) Create an instance ofResourcewith a resourceName given by the value of the argumentresourceNamethat is a member of the library named by the argumentlibraryName.createResource(String resourceName, String libraryName, String contentType) Create an instance ofResourcewith a resourceName given by the value of the argumentresourceNamethat is a member of the library named by the argumentlibraryNamethat claims to have the content-type given by the argumentcontent-type.createResourceFromId(String resourceId) Create an instance ofResourcegiven the argumentresourceId.createViewResource(FacesContext facesContext, String resourceName) Create an instance ofResourcegiven the argumentresourceName, which may contain "/" characters.getRendererTypeForResourceName(String resourceName) Return therenderer-typefor aRendererthat is capable of rendering this resource.getViewResources(FacesContext facesContext, String path, int maxDepth, ResourceVisitOption... options) Return aStreampossibly lazily populated by walking the resource tree rooted at a given initial path.getViewResources(FacesContext facesContext, String path, ResourceVisitOption... options) Return aStreampossibly lazily populated by walking the resource tree rooted at a given initial path.voidhandleResourceRequest(FacesContext context) This method specifies the contract for satisfying resource requests.booleanisResourceRequest(FacesContext context) Returntrueif the current request is a resource request.booleanlibraryExists(String libraryName) Returntrueif the resource library named by the argumentlibraryNamecan be found.Methods inherited from class jakarta.faces.application.ResourceHandler
isResourceRendered, isResourceURL, markResourceRendered
-
Constructor Details
-
ResourceHandlerImpl
public ResourceHandlerImpl()Creates a new instance of ResourceHandlerImpl
-
-
Method Details
-
createResource
Description copied from class:ResourceHandlerCreate an instance of
ViewResourcegiven the argumentresourceName. The content-type of the resource is derived by passing the resourceName toExternalContext.getMimeType(java.lang.String)The algorithm specified in section 2.6.1.4 "Libraries of Localized and Versioned Resources" of the Jakarta Faces Specification Document must be executed to create the
Resource. New requirements were introduced in version 2.2 of the specification. For historical reasons, this method operate correctly when the argumentresourceNameis of the formlibraryName/resourceName, even whenresourceNamecontains '/' characters.- Specified by:
createResourcein classResourceHandler- Parameters:
resourceName- the name of the resource.- Returns:
- a newly created
Resourceinstance, suitable for use in encoding or decoding the named resource. - See Also:
-
createResource
Description copied from class:ResourceHandlerCreate an instance of
Resourcewith a resourceName given by the value of the argumentresourceNamethat is a member of the library named by the argumentlibraryName. The content-type of the resource is derived by passing the resourceName toExternalContext.getMimeType(java.lang.String).The algorithm specified in section 2.6.1.4 "Libraries of Localized and Versioned Resources" of the Jakarta Faces Specification Document must be executed to create the
Resource. New requirements were introduced in version 2.2 of the specification.- Specified by:
createResourcein classResourceHandler- Parameters:
resourceName- the name of the resource.libraryName- the name of the library (or contract) in which this resource resides, may benull. If there is a conflict between the name of a resource library and a resource library contract, the resource library takes precedence. May not include relative paths, such as "../".- Returns:
- a newly created
Resourceinstance, suitable for use in encoding or decoding the named resource. - See Also:
-
createResource
Description copied from class:ResourceHandlerCreate an instance of
Resourcewith a resourceName given by the value of the argumentresourceNamethat is a member of the library named by the argumentlibraryNamethat claims to have the content-type given by the argumentcontent-type.The algorithm specified in section 2.6.1.4 "Libraries of Localized and Versioned Resources" of the Jakarta Faces Specification Document must be executed to create the
Resource. New requirements were introduced in version 2.2 of the specification.- Specified by:
createResourcein classResourceHandler- Parameters:
resourceName- the name of the resource.libraryName- the name of the library in which this resource resides, may benull. May not include relative paths, such as "../".contentType- the mime content that thisResourceinstance will return fromResource.getContentType(). If the value isnull, The content-type of the resource is derived by passing the resourceName toExternalContext.getMimeType(java.lang.String)- Returns:
- a newly created
Resourceinstance, suitable for use in encoding or decoding the named resource. - See Also:
-
createViewResource
Description copied from class:ResourceHandlerCreate an instance of
Resourcegiven the argumentresourceName, which may contain "/" characters. TheViewDeclarationLanguagecalls this method when it needs to load a view from a persistent store, such as a filesystem. This method is functionality equivalent toResourceHandler.createResource(java.lang.String), but all callsites that need to load VDL views must use this method so that classes that want to decorate theResourceHandlerin order to only affect the loading of views may do so without affecting the processing of other kinds of resources, such as scripts and stylesheets. AFacesContextmust be present before calling this method. To preserve compatibility with prior revisions of the specification, a default implementation must be provided that callsResourceHandler.createResource(java.lang.String).The default implementation must look for the resource in the following places, in this order.
-
Considering resource library contracts (at the locations specified in the Jakarta Faces Specification Document section 2.7 "Resource Library Contracts").
-
Considering the web app root.
-
Considering faces flows (at the locations specified in the Jakarta Faces Specification Document section 11.3.3 "Faces Flows").
Call
FacesContext.getResourceLibraryContracts(). If the result is non-nulland not empty, for each value in the list, treat the value as the name of a resource library contract. If the argumentresoureNameexists as a resource in the resource library contract, return it. Otherwise, return the resource (not in the resource library contract), if found. Otherwise, returnnull.- Overrides:
createViewResourcein classResourceHandler- Parameters:
facesContext- theFacesContextfor this request.resourceName- the name of the resource to be interpreted as a view by theViewDeclarationLanguage.- Returns:
- a newly created
ViewResourceinstance, suitable for use by theViewDeclarationLanguage.
-
-
getViewResources
public Stream<String> getViewResources(FacesContext facesContext, String path, ResourceVisitOption... options) Description copied from class:ResourceHandlerReturn a
Streampossibly lazily populated by walking the resource tree rooted at a given initial path. The resource tree is traversed breadth-first, the elements in the stream are view resource names that would yield aViewResourcewhen passed intoResourceHandler.createViewResource(jakarta.faces.context.FacesContext, java.lang.String)as theresourceNameparameter.This method works as if invoking it were equivalent to evaluating the expression:
Put differently, it visits all levels of the resource tree.getViewResources(facesContext, start, Integer.MAX_VALUE, options)
- Overrides:
getViewResourcesin classResourceHandler- Parameters:
facesContext- TheFacesContextfor this request.path- The initial path from which to start looking for view resourcesoptions- The options to influence the traversal. SeeResourceVisitOptionfor details on those.- Returns:
- the
Streamof view resource names - See Also:
-
getViewResources
public Stream<String> getViewResources(FacesContext facesContext, String path, int maxDepth, ResourceVisitOption... options) Description copied from class:ResourceHandlerReturn a
Streampossibly lazily populated by walking the resource tree rooted at a given initial path. The resource tree is traversed breadth-first, the elements in the stream are view resource names that would yield aViewResourcewhen passed intoResourceHandler.createViewResource(jakarta.faces.context.FacesContext, java.lang.String)as theresourceNameparameter.The
maxDepthparameter is the maximum depth of directory levels to visit beyond the initial path, which is always visited. The value is relative to the root (/), not to the given initial path. E.g. givenmaxDepth=3and initial path/foo/, visiting will proceed up to/foo/bar/, where/counts as depth1,/foo/as depth2and/foo/bar/as depth3. A value lower or equal to the depth of the initial path means that only the initial path is visited. A value ofMAX_VALUEmay be used to indicate that all levels should be visited.- Overrides:
getViewResourcesin classResourceHandler- Parameters:
facesContext- TheFacesContextfor this request.path- The initial path from which to start looking for view resourcesmaxDepth- The absolute maximum depth of nested directories to visit counted from the root (/).options- The options to influence the traversal. SeeResourceVisitOptionfor details on those.- Returns:
- the
Streamof view resource names - See Also:
-
createResourceFromId
Description copied from class:ResourceHandlerCreate an instance of
Resourcegiven the argumentresourceId. The content-type of the resource is derived by passing the resourceName toExternalContext.getMimeType(java.lang.String)The resource must be identified according to the specification in section 2.6.1.3 "Resource Identifiers" of the Jakarta Faces Specification Document. New requirements were introduced in version 2.2 of the specification.
- Overrides:
createResourceFromIdin classResourceHandler- Parameters:
resourceId- the resource identifier of the resource.- Returns:
- a newly created
Resourceinstance, suitable for use in encoding or decoding the named resource. - See Also:
-
libraryExists
Description copied from class:ResourceHandlerReturn
trueif the resource library named by the argumentlibraryNamecan be found. If there is alocalePrefixfor this application, as defined inResourceHandler.LOCALE_PREFIX, first look for the library with the prefix. If no such library is found, look for the library without the prefix. This allows developers to avoid duplication of files. For example, consider the case where the developer wants to have a resource library containing a localized image resource and a non-localized script resource. By checking both locations for the existence of the library, along with other spec changes in section 2.6.1.4 "Libraries of Localized and Versioned Resources" of the Jakarta Faces Specification Document, this scenario is enabled.- Specified by:
libraryExistsin classResourceHandler- Parameters:
libraryName- the library name.- Returns:
trueif the library exists,falseotherwise.
-
isResourceRequest
Description copied from class:ResourceHandlerReturn
trueif the current request is a resource request. This method is called byFacesServlet.service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)to determine if this request is a view request or a resource request.- Specified by:
isResourceRequestin classResourceHandler- Parameters:
context- theFacesContextfor this request- Returns:
trueif the current request is a resource request,falseotherwise.- See Also:
-
getRendererTypeForResourceName
Description copied from class:ResourceHandlerReturn the
renderer-typefor aRendererthat is capable of rendering this resource. The default implementation must return values according to the following table. If norenderer-typecan be determined,nullmust be returned.resource name to renderer-type mapping example resource name renderer-type mycomponent.js jakarta.faces.resource.Scriptmystyle.css jakarta.faces.resource.Stylesheet- Specified by:
getRendererTypeForResourceNamein classResourceHandler- Parameters:
resourceName- the resource name.- Returns:
- the renderer type.
-
handleResourceRequest
Description copied from class:ResourceHandlerThis method specifies the contract for satisfying resource requests. This method is called from
FacesServlet.service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)after that method determines the current request is a resource request by callingResourceHandler.isResourceRequest(jakarta.faces.context.FacesContext). Thus,handleResourceRequestmay assume that the current request is a resource request.The default implementation must implement an algorithm semantically identical to the following algorithm.
For discussion, in all cases when a status code is to be set, this spec talks only using the Jakarta Servlet API, but it is understood that in a portlet environment the appropriate equivalent API must be used.-
If the resourceIdentifier ends with any of the extensions listed in the value of the
ResourceHandler.RESOURCE_EXCLUDES_PARAM_NAMEinit parameter,HttpServletRequest.SC_NOT_FOUNDmust be passed toHttpServletResponse.setStatus(), thenhandleResourceRequestmust immediately return. -
Extract the resourceName from the resourceIdentifier by taking the substring of resourceIdentifier that starts at
and goes to the end of resourceIdentifier. If no resourceName can be extracted,ResourceHandler.RESOURCE_IDENTIFIER.length() + 1HttpServletRequest.SC_NOT_FOUNDmust be passed toHttpServletResponse.setStatus(), thenhandleResourceRequestmust immediately return. -
Extract the libraryName from the request by looking in the request parameter map for an entry under the key "ln", without the quotes. If found, use its value as the libraryName.
-
If resourceName and libraryName are present, call
ResourceHandler.createResource(String, String)to create theResource. If only resourceName is present, callResourceHandler.createResource(String)to create theResource. If theResourcecannot be successfully created,HttpServletRequest.SC_NOT_FOUNDmust be passed toHttpServletResponse.setStatus(), thenhandleResourceRequestmust immediately return. -
Call
Resource.userAgentNeedsUpdate(jakarta.faces.context.FacesContext). If this method returns false,HttpServletRequest.SC_NOT_MODIFIEDmust be passed toHttpServletResponse.setStatus(), thenhandleResourceRequestmust immediately return. -
Pass the result of
Resource.getContentType()toHttpServletResponse.setContentType. -
Call
Resource.getResponseHeaders(). For each entry in thisMap, callHttpServletResponse.setHeader(), passing the key as the first argument and the value as the second argument. -
Call
Resource.getInputStream()and serve up the bytes of the resource to the response. -
Call
HttpServletResponse.setContentLength()passing the byte count of the resource. -
If an
IOExceptionis thrown during any of the previous steps, log a descriptive, localized message, including the resourceName and libraryName (if present). Then,HttpServletRequest.SC_NOT_FOUNDmust be passed toHttpServletResponse.setStatus(), thenhandleResourceRequestmust immediately return. -
In all cases in this method, any streams, channels, sockets, or any other IO resources must be closed before this method returns.
- Specified by:
handleResourceRequestin classResourceHandler- Parameters:
context- theFacesContextfor this request- Throws:
IOException- when an I/O error occurs.- See Also:
-
-