org.apache.myfaces.trinidad.resource
Class ResourceLoader

java.lang.Object
  extended by org.apache.myfaces.trinidad.resource.ResourceLoader
Direct Known Subclasses:
CachingResourceLoader, ClassLoaderResourceLoader, DirectoryResourceLoader, DynamicResourceLoader, ProxyResourceLoader, RegexResourceLoader, ServletContextResourceLoader

public class ResourceLoader
extends Object

Base class for resource loaders. Resource loaders can lookup resources as URLs from arbitrary locations, including JAR files.


Constructor Summary
protected ResourceLoader()
          Constructs a new root resource loader.
protected ResourceLoader(ResourceLoader parent)
          Constructs a new resource loader with specified parent resource loader.
 
Method Summary
protected  URL findResource(String name)
          Finds the resource with the given name.
static String getContentType(ResourceLoader loader, URLConnection conn)
          Called by the ResourceServlet to get the content type for the given connection.
protected  String getContentType(URLConnection conn)
          Returns the content type of this URL connection.
static ResourceLoader getNullResourceLoader()
          Returns the shared resource loader that always returns null.
protected  ResourceLoader getParent()
          Returns the parent resource loader, or null if this is a root resource loader.
 URL getResource(String name)
          Finds the resource with the given name.
 boolean isCachable()
          Returns whether a resource is cachable.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceLoader

protected ResourceLoader(ResourceLoader parent)
Constructs a new resource loader with specified parent resource loader.

Parameters:
parent - the parent resource loader

ResourceLoader

protected ResourceLoader()
Constructs a new root resource loader.

Method Detail

getNullResourceLoader

public static ResourceLoader getNullResourceLoader()
Returns the shared resource loader that always returns null.

Returns:
null for any resource path

getResource

public URL getResource(String name)
                throws IOException
Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a '/'-separated path name that identifies the resource.

This method will first search the this resource loader for the resource. That failing, this method will invoke findResource(String) to on the parent resource loader to find the resource.

Parameters:
name - the resource name
Returns:
A URL object for reading the resource, or null if the resource could not be found or the invoker doesn't have adequate privileges to get the resource.
Throws:
IOException

isCachable

public boolean isCachable()
Returns whether a resource is cachable.

Returns:

toString

public String toString()
Overrides:
toString in class Object

findResource

protected URL findResource(String name)
                    throws IOException
Finds the resource with the given name. Resource loader implementations should override this method to specify where to find resources.

Parameters:
name - The resource name
Returns:
A URL object for reading the resource, or null if the resource could not be found
Throws:
IOException

getContentType

public static String getContentType(ResourceLoader loader,
                                    URLConnection conn)
Called by the ResourceServlet to get the content type for the given connection.

Parameters:
loader - the loader that provided the URL for the URL connection
conn - the URL connection
Returns:
the content type for this URL connection

getContentType

protected String getContentType(URLConnection conn)
Returns the content type of this URL connection.

Returns:
the content type

getParent

protected ResourceLoader getParent()
Returns the parent resource loader, or null if this is a root resource loader.

Returns:
the parent resource loader


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