javax.faces.application
Class ResourceHandler

java.lang.Object
  extended by javax.faces.application.ResourceHandler
Direct Known Subclasses:
ResourceHandlerWrapper

public abstract class ResourceHandler
extends java.lang.Object

ResourceHandler is the run-time API by which UIComponent and Renderer instances can reference Resource instances. An implementation of this class must be thread-safe.

Packaging Resources

Encoding Resources

Decoding Resources

Since:
2.0

Field Summary
static java.lang.String LOCALE_PREFIX
          

The name of a key within the application message bundle named by the return from Application.getMessageBundle() whose value is the locale prefix used to find a packaged resource to return from createResource(java.lang.String) (or one of its variants).

static java.lang.String RESOURCE_EXCLUDES_DEFAULT_VALUE
          

The default value for the RESOURCE_EXCLUDES_PARAM_NAME init param.

static java.lang.String RESOURCE_EXCLUDES_PARAM_NAME
          

The ServletContext init parameter consulted by the handleResourceRequest(javax.faces.context.FacesContext) to tell which kinds of resources must never be served up in response to a resource request.

static java.lang.String RESOURCE_IDENTIFIER
          

Resource.getRequestPath() returns the value of this constant as the prefix of the URI.

 
Constructor Summary
ResourceHandler()
           
 
Method Summary
abstract  Resource createResource(java.lang.String resourceName)
          

Create an instance of Resource given the argument resourceName.

abstract  Resource createResource(java.lang.String resourceName, java.lang.String libraryName)
          

Create an instance of Resource with a resourceName given by the value of the argument resourceName that is a member of the library named by the argument libraryName.

abstract  Resource createResource(java.lang.String resourceName, java.lang.String libraryName, java.lang.String contentType)
          

Create an instance of Resource with a resourceName given by the value of the argument resourceName that is a member of the library named by the argument libraryName that claims to have the content-type given by the argument content-type.

abstract  java.lang.String getRendererTypeForResourceName(java.lang.String resourceName)
          

Return the renderer-type for a Renderer that is capable of rendering this resource.

abstract  void handleResourceRequest(FacesContext context)
          

This method specifies the contract for satisfying resource requests.

abstract  boolean isResourceRequest(FacesContext context)
          

Return true if the current request is a resource request.

abstract  boolean libraryExists(java.lang.String libraryName)
          

Return true if the resource library named by the argument libraryName can be found.

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

Field Detail

RESOURCE_IDENTIFIER

public static final java.lang.String RESOURCE_IDENTIFIER

Resource.getRequestPath() returns the value of this constant as the prefix of the URI. handleResourceRequest(javax.faces.context.FacesContext) looks for the value of this constant within the request URI to determine if the request is a resource request or a view request.

See Also:
Constant Field Values

LOCALE_PREFIX

public static final java.lang.String LOCALE_PREFIX

The name of a key within the application message bundle named by the return from Application.getMessageBundle() whose value is the locale prefix used to find a packaged resource to return from createResource(java.lang.String) (or one of its variants).

See Also:
Constant Field Values

RESOURCE_EXCLUDES_PARAM_NAME

public static final java.lang.String RESOURCE_EXCLUDES_PARAM_NAME

The ServletContext init parameter consulted by the handleResourceRequest(javax.faces.context.FacesContext) to tell which kinds of resources must never be served up in response to a resource request. The value of this parameter is a single space separated list of file extensions, including the leading '.' character (without the quotes). If not specified, the default value given in the value of the RESOURCE_EXCLUDES_DEFAULT_VALUE constant is used. If manually specified, the given value entirely overrides the default one and does not supplement it.

See Also:
Constant Field Values

RESOURCE_EXCLUDES_DEFAULT_VALUE

public static final java.lang.String RESOURCE_EXCLUDES_DEFAULT_VALUE

The default value for the RESOURCE_EXCLUDES_PARAM_NAME init param.

See Also:
Constant Field Values
Constructor Detail

ResourceHandler

public ResourceHandler()
Method Detail

createResource

public abstract Resource createResource(java.lang.String resourceName)

Create an instance of Resource given the argument resourceName. The content-type of the resource is derived by passing the resourceName to ExternalContext.getMimeType(java.lang.String)

The algorithm specified in section JSF.2.6.1.4 of the spec prose document linked in the overview summary must be executed to create the Resource

Parameters:
resourceName - the name of the resource.
Returns:
a newly created Resource instance, suitable for use in encoding or decoding the named resource.
Throws:
java.lang.NullPointerException - if resourceName is null.

createResource

public abstract Resource createResource(java.lang.String resourceName,
                                        java.lang.String libraryName)

Create an instance of Resource with a resourceName given by the value of the argument resourceName that is a member of the library named by the argument libraryName. The content-type of the resource is derived by passing the resourceName to ExternalContext.getMimeType(java.lang.String).

The algorithm specified in section JSF.2.6.1.4 of the spec prose document linked in the overview summary must be executed to create the Resource

Parameters:
resourceName - the name of the resource.
libraryName - the name of the library in which this resource resides, may be null. May not include relative paths, such as "../".
Returns:
a newly created Resource instance, suitable for use in encoding or decoding the named resource.
Throws:
NullPointerException - if resourceName is null

createResource

public abstract Resource createResource(java.lang.String resourceName,
                                        java.lang.String libraryName,
                                        java.lang.String contentType)

Create an instance of Resource with a resourceName given by the value of the argument resourceName that is a member of the library named by the argument libraryName that claims to have the content-type given by the argument content-type.

The algorithm specified in section JSF.2.6.1.4 of the spec prose document linked in the overview summary must be executed to create the Resource

Parameters:
resourceName - the name of the resource.
libraryName - the name of the library in which this resource resides, may be null. May not include relative paths, such as "../".
contentType - the mime content that this Resource instance will return from Resource.getContentType(). If the value is null, The content-type of the resource is derived by passing the resourceName to ExternalContext.getMimeType(java.lang.String)

Returns:
a newly created Resource instance, suitable for use in encoding or decoding the named resource.
Throws:
NullPointerException - if resourceName is null.

libraryExists

public abstract boolean libraryExists(java.lang.String libraryName)

Return true if the resource library named by the argument libraryName can be found.

Since:
2.0

handleResourceRequest

public abstract void handleResourceRequest(FacesContext context)
                                    throws java.io.IOException

This method specifies the contract for satisfying resource requests. This method is called from FacesServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) after that method determines the current request is a resource request by calling isResourceRequest(javax.faces.context.FacesContext). Thus, handleResourceRequest may 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 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 RESOURCE_EXCLUDES_PARAM_NAME init parameter, HttpServletRequest.SC_NOT_FOUND must be passed to HttpServletResponse.setStatus(), then handleResourceRequest must immediately return.

  • Extract the resourceName from the resourceIdentifier by taking the substring of resourceIdentifier that starts at RESOURCE_IDENTIFIER.length() + 1 and goes to the end of resourceIdentifier. If no resourceName can be extracted, HttpServletRequest.SC_NOT_FOUND must be passed to HttpServletResponse.setStatus(), then handleResourceRequest must 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 createResource(String, String) to create the Resource. If only resourceName is present, call createResource(String) to create the Resource. If the Resource cannot be successfully created, HttpServletRequest.SC_NOT_FOUND must be passed to HttpServletResponse.setStatus(), then handleResourceRequest must immediately return.

  • Call Resource.userAgentNeedsUpdate(javax.faces.context.FacesContext). If this method returns false, HttpServletRequest.SC_NOT_MODIFIED must be passed to HttpServletResponse.setStatus(), then handleResourceRequest must immediately return.

  • Pass the result of Resource.getContentType() to HttpServletResponse.setContentType.

  • Call Resource.getResponseHeaders(). For each entry in this Map, call HttpServletResponse.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 IOException is thrown during any of the previous steps, log a descriptive, localized message, including the resourceName and libraryName (if present). Then, HttpServletRequest.SC_NOT_FOUND must be passed to HttpServletResponse.setStatus(), then handleResourceRequest must immediately return.

  • In all cases in this method, any streams, channels, sockets, or any other IO resources must be closed before this method returns.

Parameters:
context - the FacesContext for this request
Throws:
java.io.IOException

isResourceRequest

public abstract boolean isResourceRequest(FacesContext context)

Return true if the current request is a resource request. This method is called by FacesServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) to determine if this request is a view request or a resource request.

Parameters:
context - the FacesContext for this request
Returns:
true if the current request is a resource request, false otherwise.

getRendererTypeForResourceName

public abstract java.lang.String getRendererTypeForResourceName(java.lang.String resourceName)

Return the renderer-type for a Renderer that is capable of rendering this resource. The default implementation must return values according to the following table. If no renderer-type can be determined, null must be returned.

example resource name renderer-type
mycomponent.js javax.faces.resource.Script
mystyle.css javax.faces.resource.Stylesheet



Copyright 2002-2010 Oracle America Inc, Inc. All Rights Reserved.