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

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

public class MyFacesResourceHandler
extends Object
implements ResourceHandler

A ResourceHandler which always generates URLs that trigger the MyfacesResourceLoader to load resources from the classpath relative to some Tomahawk class.

This is intended to support loading of Tomahawk resources only; applications which wish to use the Tomahawk AddResources framework for loading resources from elsewhere should implement their own ResourceHandler class.

Author:
Mathias Broekelmann

Constructor Summary
MyFacesResourceHandler(Class myfacesCustomComponent, String resourceName)
          Constructor.
 
Method Summary
 Class getResourceLoaderClass()
          Return a Class object which can decode the url generated by this class in the getResourceUri method and use that info to locate the resource data represented by this object.
 String getResourceUri(javax.faces.context.FacesContext context)
          Return a URL that the browser can later submit to retrieve the resource handled by this instance.
protected  void validateCustomComponent(Class myfacesCustomComponent)
          Verify that the base class for the resource lookup is in the org.apache.myfaces.custom package.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.myfaces.renderkit.html.util.ResourceHandler
equals, hashCode
 

Constructor Detail

MyFacesResourceHandler

public MyFacesResourceHandler(Class myfacesCustomComponent,
                              String resourceName)
Constructor.

Parameters:
myfacesCustomComponent - is a class that must be in package org.apache.myfaces.custom. The resource to be served will be located relative to this class in the classpath. Note that code wishing to serve resources from other locations in the classpath must write a custom ResourceHandler implementation.
resourceName - is the name of a file that can be found in dir "resource/{resourceName} relative to the location of the specified component class in the classpath. Because the resource is always relative to a class file, it must never begin with a slash.
Method Detail

getResourceLoaderClass

public Class getResourceLoaderClass()
Return a Class object which can decode the url generated by this class in the getResourceUri method and use that info to locate the resource data represented by this object.

Specified by:
getResourceLoaderClass in interface ResourceHandler
Returns:
a class which implements org.apache.myfaces.component.html.util.ResourceLoader
See Also:
ResourceHandler.getResourceLoaderClass()

validateCustomComponent

protected void validateCustomComponent(Class myfacesCustomComponent)
Verify that the base class for the resource lookup is in the org.apache.myfaces.custom package.

Parameters:
myfacesCustomComponent - is the base component for the lookup.
Throws:
IllegalArgumentException - if the class is not in the expected package.

getResourceUri

public String getResourceUri(javax.faces.context.FacesContext context)
Return a URL that the browser can later submit to retrieve the resource handled by this instance.

The emitted URL is of form:

   {partial.class.name}/{resourceName}
 
where partial.class.name is the name of the base class specified in the constructor, and resourceName is the resource specified in the constructor.

Specified by:
getResourceUri in interface ResourceHandler
See Also:
org.apache.myfaces.shared.renderkit.html.util.ResourceHandler#getResourceUri(javax.faces.context.FacesContext)


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