org.apache.myfaces.renderkit.html.util
Class MyFacesResourceLoader

java.lang.Object
  extended by org.apache.myfaces.renderkit.html.util.MyFacesResourceLoader
All Implemented Interfaces:
ResourceLoader

public class MyFacesResourceLoader
extends Object
implements ResourceLoader

A ResourceLoader capable of fetching resources from the classpath, but only for classes under package org.apache.myfaces.custom.

The URI is expected to contain two pieces of information: the tomahawk class the resource is associated with, and a relative path from that class to the resource.

Version:
$Revision$ $Date$
Author:
Mathias Broekelmann (latest modification by $Author$)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.myfaces.renderkit.html.util.ResourceLoader
ResourceLoader.ClosedSocketException
 
Field Summary
protected static org.apache.commons.logging.Log log
           
 
Constructor Summary
MyFacesResourceLoader()
           
 
Method Summary
protected  void defineCaching(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String resource, long lastModified)
          Output http headers telling the browser (and possibly intermediate caches) how to cache this data.
protected  void defineContentHeaders(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String resource, int contentLength, String contentEncoding)
          Output http headers indicating the mime-type of the content being served.
protected  Class loadComponentClass(String componentClass)
           
 void serveResource(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String resourceUri)
          Given a URI of form "{partial.class.name}/{resourceName}", locate the specified file within the current classpath and write it to the response object.
protected  void validateCustomComponent(Class myfacesCustomComponent)
           
protected  void writeResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, InputStream in)
          Copy the content of the specified input stream to the servlet response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
Constructor Detail

MyFacesResourceLoader

public MyFacesResourceLoader()
Method Detail

serveResource

public void serveResource(javax.servlet.ServletContext context,
                          javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          String resourceUri)
                   throws IOException
Given a URI of form "{partial.class.name}/{resourceName}", locate the specified file within the current classpath and write it to the response object.

The partial class name has "org.apache.myfaces.custom." prepended to it to form the fully qualified classname. This class object is loaded, and Class.getResourceAsStream is called on it, passing a uri of "resource/" + {resourceName}.

The data written to the response stream includes http headers which define the mime content-type; this is deduced from the filename suffix of the resource.

Specified by:
serveResource in interface ResourceLoader
Parameters:
context - TODO
request - the request
response - the response to write the resource content to
resourceUri - contains the uri part after the uri which is used to identify the resource loader
Throws:
IOException
See Also:
ResourceLoader.serveResource(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)

writeResource

protected void writeResource(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             InputStream in)
                      throws IOException
Copy the content of the specified input stream to the servlet response.

Throws:
IOException

defineCaching

protected void defineCaching(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             String resource,
                             long lastModified)
Output http headers telling the browser (and possibly intermediate caches) how to cache this data.

The expiry time in this header info is set to 7 days. This is not a problem as the overall URI contains a "cache key" that changes whenever the webapp is redeployed (see AddResource.getCacheKey), meaning that all browsers will effectively reload files on webapp redeploy.


defineContentHeaders

protected void defineContentHeaders(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response,
                                    String resource,
                                    int contentLength,
                                    String contentEncoding)
Output http headers indicating the mime-type of the content being served. The mime-type output is determined by the resource filename suffix.


loadComponentClass

protected Class loadComponentClass(String componentClass)
                            throws ClassNotFoundException
Throws:
ClassNotFoundException

validateCustomComponent

protected void validateCustomComponent(Class myfacesCustomComponent)


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.