javax.faces.application
Class Resource

java.lang.Object
  extended by javax.faces.application.Resource
Direct Known Subclasses:
ResourceWrapper

public abstract class Resource
extends Object

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 Summary
static 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.

 
Constructor Summary
Resource()
           
 
Method Summary
 String getContentType()
          

Return the MIME content-type for this resource.

abstract  InputStream getInputStream()
          

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

 String getLibraryName()
          

Return the libraryName for this resource.

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.

 String getResourceName()
          

Return the resourceName for this resource.

abstract  Map<String,String> getResponseHeaders()
          

Returns a mutable Map<String, String> whose entries will be sent as response headers during ResourceHandler.handleResourceRequest(javax.faces.context.FacesContext).

abstract  URL getURL()
          

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

 void setContentType(String contentType)
          

Set the MIME content-type for this resource.

 void setLibraryName(String libraryName)
          

Set the libraryName for this resource.

 void setResourceName(String resourceName)
          

Set the resourceName for this resource.

 String toString()
          

Call through to getRequestPath() and return the result.

abstract  boolean userAgentNeedsUpdate(FacesContext context)
          

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

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMPONENT_RESOURCE_KEY

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.

See Also:
Constant Field Values
Constructor Detail

Resource

public Resource()
Method Detail

getContentType

public String getContentType()

Return the MIME content-type for this resource.

Returns:
the MIME content-type for this resource.

setContentType

public void setContentType(String contentType)

Set 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 null as a parameter.

getLibraryName

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:
Return the libraryName for this resource. May be null.

setLibraryName

public void setLibraryName(String libraryName)

Set the libraryName for this resource.

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

getResourceName

public String getResourceName()

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

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

setResourceName

public void setResourceName(String resourceName)

Set the resourceName for this resource.

Parameters:
resourceName - a non-null String.
Throws:
NullPointerException - if argument resourceName is null.

getInputStream

public abstract InputStream getInputStream()
                                    throws IOException

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

Returns:
an InputStream containing the bytes of the resource.

Throws:
IOException - if the current request is not a resource request.

getResponseHeaders

public abstract Map<String,String> getResponseHeaders()

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

getRequestPath

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.

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.

getURL

public abstract URL getURL()

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

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

toString

public String toString()

Call through to getRequestPath() and return the result.

Overrides:
toString in class Object
Returns:
Call through to getRequestPath() and return the result.

userAgentNeedsUpdate

public abstract boolean userAgentNeedsUpdate(FacesContext context)

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

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


Copyright © 2002-2009 Sun Microsystems, Inc. All Rights Reserved.