Class ResourceImpl

All Implemented Interfaces:
Externalizable, Serializable

public class ResourceImpl extends Resource implements Externalizable
Default implementation of Resource. The ResourceImpl instance itself has the same lifespan as the request, however, the ResourceInfo instances that back this object are cached by the ResourceManager to reduce the time spent scanning for resources.
See Also:
  • Constructor Details

    • ResourceImpl

      public ResourceImpl()
      Necessary for serialization.
    • ResourceImpl

      public ResourceImpl(ResourceInfo resourceInfo, String contentType, long initialTime, long maxAge)
      Creates a new instance of ResourceBase
      Parameters:
      resourceInfo - the resource info
      contentType - the resource content type
      initialTime - the resource initial time
      maxAge - the resource max age
  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from class: Resource

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

      Specified by:
      getInputStream in class Resource
      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.

      Throws:
      IOException - if the current request is not a resource request.
      See Also:
    • getURL

      public URL getURL()
      Description copied from class: Resource

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

      Specified by:
      getURL in class Resource
      Returns:
      Return an actual URL instance that refers to this resource instance.
      See Also:
    • getResponseHeaders

      public Map<String,String> getResponseHeaders()

      Implementation note. Any values added to getResponseHeaders() will only be visible across multiple calls to this method when servicing a resource request (i.e. ResourceHandler.isResourceRequest(jakarta.faces.context.FacesContext) returns true). If we're not servicing a resource request, an empty Map will be returned and the values added are effectively thrown away.

      Specified by:
      getResponseHeaders in class Resource
      Returns:
      a mutable Map<String, String> of headers that will be included with the response.
      See Also:
    • getRequestPath

      public String getRequestPath()
      Description copied from class: Resource

      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.

      Specified by:
      getRequestPath in class Resource
      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.
      See Also:
    • userAgentNeedsUpdate

      public boolean userAgentNeedsUpdate(FacesContext context)
      Description copied from class: Resource

      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.

      Specified by:
      userAgentNeedsUpdate in class Resource
      Parameters:
      context - the Faces context.
      Returns:
      true or false depending on whether or not the user-agent needs an update of this resource.
      See Also:
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException