Class Resource
- Direct Known Subclasses:
- ResourceWrapper
 An instance of
 Resource is a Java object representation of the artifact that is served up in response to a resource
 request from the client. Instances of Resource are normally created and initialized via calls to
 ResourceHandler.createResource(java.lang.String). See the documentation for ResourceHandler for more information.
 
- Since:
- 2.0
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThis constant is used as the key in the component attribute map of a composite component to associate the component with itsResourceinstance.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionReturn the MIME content-type for this resource.abstract InputStreamIf the current request is a resource request, (that is,ResourceHandler.isResourceRequest(jakarta.faces.context.FacesContext)returnstrue), return anInputStreamcontaining the bytes of the resource.Return the libraryName for this resource.abstract StringReturn a path to this resource such that, when the browser resolves it against the base URI for the view that includes the resource, and issues a GET request to the resultant fully qualified URL, the bytes of the resource are returned in response.Return the resourceName for this resource.Returns a mutableMap<String, String>whose entries will be sent as response headers duringResourceHandler.handleResourceRequest(jakarta.faces.context.FacesContext).abstract URLgetURL()Return an actualURLinstance that refers to this resource instance.voidsetContentType(String contentType) Set the MIME content-type for this resource.voidsetLibraryName(String libraryName) Set the libraryName for this resource.voidsetResourceName(String resourceName) Set the resourceName for this resource.toString()Call through togetRequestPath()and return the result.abstract booleanuserAgentNeedsUpdate(FacesContext context) Returntrueif the user-agent requesting this resource needs an update.
- 
Field Details- 
COMPONENT_RESOURCE_KEYThis constant is used as the key in the component attribute map of a composite component to associate the component with its Resourceinstance. The value for this key is the actualResourceinstance.- See Also:
 
 
- 
- 
Constructor Details- 
Resourcepublic Resource()
 
- 
- 
Method Details- 
getContentTypeReturn the MIME content-type for this resource. - Returns:
- the MIME content-type for this resource.
 
- 
setContentTypeSet the MIME content-type for this resource. The default implementation performs no validation on the argument. - Parameters:
- contentType- the MIME content-type for this resource. The default implementation must accept- nullas a parameter.
 
- 
getLibraryNameReturn the libraryName for this resource. May be null. The libraryName for a resource is an optional String that indicates membership in a "resource library". All resources with the same libraryName belong to the same "resource library". The "resource library" concept allows disambiguating resources that have the same resourceName. SeeResourceHandlerfor more information.- Returns:
- Return the libraryName for this resource. May be null.
 
- 
setLibraryNameSet the libraryName for this resource. - Parameters:
- libraryName- the libraryName for this resource. The default implementation must accept- nullfor the libraryName.
 
- 
getResourceNameReturn the resourceName for this resource. Will never be null. All Resourceinstances must have a resourceName.- Returns:
- Return the resourceName for this resource. Will never be null.
 
- 
setResourceNameSet the resourceName for this resource. - Parameters:
- resourceName- a non-null String.
- Throws:
- NullPointerException- if argument- resourceNameis null.
 
- 
getInputStreamIf the current request is a resource request, (that is, ResourceHandler.isResourceRequest(jakarta.faces.context.FacesContext)returnstrue), return anInputStreamcontaining the bytes of the resource. Otherwise, throw anIOException.- Returns:
- an InputStreamcontaining the bytes of the resource.Any Jakarta Expression Language expressions present in the resource must be evaluated before serving the bytes of the resource. Note that due to browser and server caching, Jakarta Expression Language expressions in a resource file will generally only be evaluated once, when the resource is first served up. Therefore, using Jakarta Expression Language expressions that refer to per-request data is not advisable since this data can become stale. 
- Throws:
- IOException- if the current request is not a resource request.
 
- 
getResponseHeadersReturns a mutable Map<String, String>whose entries will be sent as response headers duringResourceHandler.handleResourceRequest(jakarta.faces.context.FacesContext). The entries in this map must not persist beyond the scope of a single request. Any modifications made to the map after the resource has been served will be ignored by the run-time.- Returns:
- a mutable Map<String, String>of headers that will be included with the response.
 
- 
getRequestPathReturn a path to this resource such that, when the browser resolves it against the base URI for the view that includes the resource, and issues a GET request to the resultant fully qualified URL, the bytes of the resource are returned in response. The default implementation must implement the following algorithm. For discussion, the return result from this method will be called result. - 
 Get the context-root for this web application, not ending in slash. For discussion this will be called contextRoot. 
- 
 Discover if the FacesServletis prefix (path) mapped, extension mapped, or exact mapped (as defined by Servlet.12.2.) and the value of the mapping (including the leading '.' in the case of extension mapping). For discussion, this will be facesServletMapping.If exact mapped, result must be the following if and only if the FacesServlet is mapped to the exact URL pattern ResourceHandler.RESOURCE_IDENTIFIER+getResourceName()result = contextRoot +ResourceHandler.RESOURCE_IDENTIFIER+getResourceName()If exact mapped, and the FacesServlet is not mapped to the exact URL pattern ResourceHandler.RESOURCE_IDENTIFIER+getResourceName()do the following:Retrieve the existing mappings of the FacesServlet, e.g. using ServletRegistration.getMappings(), and from those pick any prefix mapping or extension mapping. If no such mapping is found, throw anIllegalStateException. If such mapping is found remove the*character from that mapping, take that as the new facesServletMapping and continue with evaluating this mapping as specified below for if prefix mapped and for if extension mappedIf prefix mapped, result must be result = contextRoot + '/' + facesServletMapping +ResourceHandler.RESOURCE_IDENTIFIER+ '/' +getResourceName()If extension mapped, result must be result = contextRoot +ResourceHandler.RESOURCE_IDENTIFIER+getResourceName()+ facesServletMapping
- 
 Build up a string, called resourceMetaData which is an & separated string of name=value pairs suitable for inclusion in a URL query string. If getLibraryName()returns non-null,resourceMetaDatamust include "ln=" + the return fromgetLibraryName()If there is a localePrefixfor this application, as defined inResourceHandler.LOCALE_PREFIX,resourceMetaDatamust include "loc=" + thelocalePrefix.If this resource is contained in a resource library contract, resourceMetaDatamust include "con=" + the name of the resource library contract.Append "?" + resourceMetaData to result. 
- 
 Make it portlet safe by passing the result through ViewHandler.getResourceURL(jakarta.faces.context.FacesContext, java.lang.String).
 - Returns:
- the path to this resource, intended to be included in the encoded view that is sent to the browser when sending a faces response.
 
- 
 
- 
getURLReturn an actual URLinstance that refers to this resource instance.- Specified by:
- getURLin class- ViewResource
- Returns:
- Return an actual URLinstance that refers to this resource instance.
 
- 
toStringCall through to getRequestPath()and return the result.- Overrides:
- toStringin class- Object
- Returns:
- Call through to getRequestPath()and return the result.
 
- 
userAgentNeedsUpdateReturn trueif the user-agent requesting this resource needs an update. If theIf-Modified-SinceHTTP header is available for this request, its value must be consulted, as specified in Section 14.25 of IETF RFC 2616, to determine the result. Returnsfalseif the user-agent does not need an update for this resource.- Parameters:
- context- the Faces context.
- Returns:
- trueor- falsedepending on whether or not the user-agent needs an update of this resource.
 
 
-