Top Description Fields Constructors Methods
jakarta.faces.application

public abstract Class Resource

extends ViewResource
Class Inheritance
Known Direct Subclasses
jakarta.faces.application.ResourceWrapper, com.sun.faces.application.resource.ResourceImpl
Imports
java.io.IOException, .InputStream, java.net.URL, java.util.Map, jakarta.faces.context.FacesContext, jakarta.servlet.ServletRegistration

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. See the documentation for ResourceHandler for more information.

Since
2.0

Field Summary

Modifier and TypeField and Description
public static final String
COMPONENT_RESOURCE_KEY

This constant is used as the key in the component attribute map of a composite component to associate the component with its Resource instance.

private String
private String
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the MIME content-type for this resource.
getContentType
()

Return the MIME content-type for this resource.

public abstract InputStream

Returns:

an InputStream containing 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.

getInputStream
()

If the current request is a resource request, (that is, ResourceHandler#isResourceRequest returns true), return an InputStream containing the bytes of the resource.

public String

Returns:

Return the libraryName for this resource. May be null.
getLibraryName
()

Return the libraryName for this resource.

public abstract 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.
getRequestPath
()

Return 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.

public String

Returns:

Return the resourceName for this resource. Will never be null.
getResourceName
()

Return the resourceName for this resource.

public abstract Map<String, String>

Returns:

a mutable Map<String, String> of headers that will be included with the response.
getResponseHeaders
()

Returns a mutable Map<String, String> whose entries will be sent as response headers during ResourceHandler#handleResourceRequest.

public abstract URL

Returns:

Return an actual URL instance that refers to this resource instance.
getURL
()

Implements abstract jakarta.faces.application.ViewResource.getURL.

Return an actual URL instance that refers to this resource instance.

public void
setContentType(String
the MIME content-type for this resource. The default implementation must accept null as a parameter.
contentType
)

Set the MIME content-type for this resource.

public void
setLibraryName(String
the libraryName for this resource. The default implementation must accept null for the libraryName.
libraryName
)

Set the libraryName for this resource.

public void
setResourceName(String
a non-null String.
resourceName
)

Set the resourceName for this resource.

public String

Returns:

Call through to getRequestPath and return the result.
toString
()

Overrides java.lang.Object.toString.

Call through to getRequestPath and return the result.

public abstract boolean

Returns:

true or false depending on whether or not the user-agent needs an update of this resource.
userAgentNeedsUpdate
(FacesContext
the Faces context.
context
)

Return true if the user-agent requesting this resource needs an update.

Field Detail

COMPONENT_RESOURCE_KEYback to summary
public static final String COMPONENT_RESOURCE_KEY

This constant is used as the key in the component attribute map of a composite component to associate the component with its Resource instance. The value for this key is the actual Resource instance.

contentTypeback to summary
private String contentType
libraryNameback to summary
private String libraryName
resourceNameback to summary
private String resourceName

Constructor Detail

Resourceback to summary
public Resource()

Method Detail

getContentTypeback to summary
public String getContentType()

Return the MIME content-type for this resource.

Returns:String

the MIME content-type for this resource.

getInputStreamback to summary
public abstract InputStream getInputStream() throws IOException

If the current request is a resource request, (that is, ResourceHandler#isResourceRequest returns true), return an InputStream containing the bytes of the resource. Otherwise, throw an IOException.

Returns:InputStream

an InputStream containing 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.

Exceptions
IOException:
if the current request is not a resource request.
getLibraryNameback to summary
public String getLibraryName()

Return 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. See ResourceHandler for more information.

Returns:String

Return the libraryName for this resource. May be null.

getRequestPathback to summary
public abstract String getRequestPath()

Return 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 FacesServlet is 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 an IllegalStateException. 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 mapped

    If 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, resourceMetaData must include "ln=" + the return from getLibraryName

    If there is a localePrefix for this application, as defined in ResourceHandler#LOCALE_PREFIX, resourceMetaData must include "loc=" + the localePrefix.

    If this resource is contained in a resource library contract, resourceMetaData must include "con=" + the name of the resource library contract.

    Append "?" + resourceMetaData to result.

  • Make it portlet safe by passing the result through ViewHandler#getResourceURL.

Returns:String

the path to this resource, intended to be included in the encoded view that is sent to the browser when sending a faces response.

getResourceNameback to summary
public String getResourceName()

Return the resourceName for this resource. Will never be null. All Resource instances must have a resourceName.

Returns:String

Return the resourceName for this resource. Will never be null.

getResponseHeadersback to summary
public abstract Map<String, String> getResponseHeaders()

Returns a mutable Map<String, String> whose entries will be sent as response headers during ResourceHandler#handleResourceRequest. 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:Map<String, String>

a mutable Map<String, String> of headers that will be included with the response.

getURLback to summary
public abstract URL getURL()

Implements abstract jakarta.faces.application.ViewResource.getURL.

Return an actual URL instance that refers to this resource instance.

Returns:URL

Return an actual URL instance that refers to this resource instance.

Annotations
@Override
setContentTypeback to summary
public void setContentType(String contentType)

Set the MIME content-type for this resource. The default implementation performs no validation on the argument.

Parameters
contentType:String

the MIME content-type for this resource. The default implementation must accept null as a parameter.

setLibraryNameback to summary
public void setLibraryName(String libraryName)

Set the libraryName for this resource.

Parameters
libraryName:String

the libraryName for this resource. The default implementation must accept null for the libraryName.

setResourceNameback to summary
public void setResourceName(String resourceName)

Set the resourceName for this resource.

Parameters
resourceName:String

a non-null String.

Exceptions
NullPointerException:
if argument resourceName is null.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Call through to getRequestPath and return the result.

Returns:String

Call through to getRequestPath and return the result.

Annotations
@Override
userAgentNeedsUpdateback to summary
public abstract boolean userAgentNeedsUpdate(FacesContext context)

Return true if the user-agent requesting this resource needs an update. If the If-Modified-Since HTTP 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. Returns false if the user-agent does not need an update for this resource.

Parameters
context:FacesContext

the Faces context.

Returns:boolean

true or false depending on whether or not the user-agent needs an update of this resource.