org.enhydra.xml.xmlc.servlet
Class ServletResourceLoaderImpl

java.lang.Object
  |
  +--org.enhydra.xml.xmlc.deferredparsing.ResourceLoaderImpl
        |
        +--org.enhydra.xml.xmlc.servlet.ServletResourceLoaderImpl
All Implemented Interfaces:
ResourceLoader

public class ServletResourceLoaderImpl
extends ResourceLoaderImpl

A resource loader implementation that provides the capability of loading resources from the ServletContext.

Since:
2.3.2
Author:
Jacob Kjome

Field Summary
protected  javax.servlet.ServletContext fServletContext
           
 
Fields inherited from class org.enhydra.xml.xmlc.deferredparsing.ResourceLoaderImpl
fFactory
 
Constructor Summary
ServletResourceLoaderImpl(XMLCDeferredParsingFactory factory, javax.servlet.ServletContext servletContext)
           
 
Method Summary
protected  URL getPathURLFromServletContext(String candidatePath)
           
protected  URL getPathURLFromServletContext(String[] candidatePaths)
          Iterates over candidatePaths looking up each path from the servlet context.
 URL getResource(String[] candidatePaths)
          First looks up candidatePaths according to super#getResource(String[]).
 
Methods inherited from class org.enhydra.xml.xmlc.deferredparsing.ResourceLoaderImpl
getPathURLFromClasspath, getPathURLFromResourceDir, getPathURLFromResourceDirOrClasspath
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fServletContext

protected final javax.servlet.ServletContext fServletContext
Constructor Detail

ServletResourceLoaderImpl

public ServletResourceLoaderImpl(XMLCDeferredParsingFactory factory,
                                 javax.servlet.ServletContext servletContext)
Parameters:
factory - the XMLC deferred parsing factory
servletContext - the servlet context
Method Detail

getResource

public URL getResource(String[] candidatePaths)
First looks up candidatePaths according to super#getResource(String[]). If not found, the servlet context is used to look up each candidate path until one is found. If none is found, null is returned.

By performing servlet context lookup last, as a fallback, there should be no noticeable difference in performance for users serving resources from the traditional resource dir and classpath locations. And resources may be served from a mix of locations.

Paths are expected to be relative, i.e., no leading slash, with directory/package names separated by forward slashes regardless of operating system platform.

Overrides:
getResource in class ResourceLoaderImpl
Parameters:
candidatePaths - an array of candidate paths from which to load a resource in order of preference
Returns:
a URL corresponding to one of the candidatePaths or null if not found
See Also:
DocumentLoaderImpl#getResource(String[]), getPathURLFromServletContext(String[])

getPathURLFromServletContext

protected URL getPathURLFromServletContext(String[] candidatePaths)
Iterates over candidatePaths looking up each path from the servlet context.

Prior to servlet context resource lookup, each candidate path is prefixed by a forward slash ensuring it is properly formatted. Even so if a MalformedURLException still occurs, it is squashed and treated merely as a candidate path which was not found.

Parameters:
candidatePaths - an array of candidate paths from which to load a resource in order of preference
Returns:
a URL corresponding to one of the candidatePaths or null if not found
See Also:
getPathURLFromServletContext(String)

getPathURLFromServletContext

protected URL getPathURLFromServletContext(String candidatePath)
                                    throws MalformedURLException
Parameters:
candidatePath - a candidate path from which to load a resource (with a leading slash)
Returns:
a URL corresponding the candidatePath or null if not found
Throws:
MalformedURLException - if the path is not given in the correct form (with a leading slash)
NullPointerException - if the constructor provided servletContext is null


Copyright © 1999-2007 enhydra.org (Mark Diekhans, David Li, Richard Kunze, Jacob Kjome). All Rights reserved.