com.arsdigita.util
Class ResourceManager

java.lang.Object
  extended bycom.arsdigita.util.ResourceManager

public class ResourceManager
extends Object

Wrapper for getResourceAsStream, so we can get file-based resources with paths relative to the webapp root without needing a ServletContext object.


Field Summary
static String versionId
           
 
Method Summary
static ResourceManager getInstance()
          implements singleton pattern
 long getLastModified(String path)
          Returns the last-modified time for the file on disk.
 File getResourceAsFile(String url)
          Returns a new File object that refers to the URL argument.
 InputStream getResourceAsStream(String url)
          Returns a new InputStream object reading the URL argument.
 String getResourcePath(String url)
          Gets the full path to a resource.
 javax.servlet.ServletContext getServletContext()
          returns the ServletContext that this ResourceManager uses
 File getWebappRoot()
           
 void setServletContext(javax.servlet.ServletContext sctx)
          Configures this ResourceManager to use the specified servlet context.
 void setWebappRoot(File f)
          Configures this ResourceManager to use the specified webapp root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Method Detail

getInstance

public static ResourceManager getInstance()
implements singleton pattern

Returns:
the instance

getResourceAsStream

public InputStream getResourceAsStream(String url)
Returns a new InputStream object reading the URL argument. Behaves similarly to ServletContext.getResourceAsStream(), reading pathnames relative to the webapp root.

Parameters:
url - a URL interpreted as a pathname relative to the webapp root
Returns:
a new input stream reading the named file, or null if not found
Throws:
IllegalStateException - if class is not configured prior to use.

getResourcePath

public String getResourcePath(String url)
Gets the full path to a resource. Kinda hacky way of making sure that XML file loading works. Many Initializers load XML files from WEB-INF, and had done so by calling ServletContext.getRealPath(). Problem is, under test, there is no ServletContext. Swithcing to ResourceManager.getResourceAsStream works so long as there is no DTD. Calling this method gets the correct path, and lets the parser properly load the file. Will probably remove when TestServletContext is always available.

Parameters:
url -
Returns:
Full path

getResourceAsFile

public File getResourceAsFile(String url)
Returns a new File object that refers to the URL argument. Behaves similarly to getResourceAsStream(), reading pathnames relative to the webapp root, except we return a File object.

Parameters:
url - a URL interpreted as a pathname relative to the webapp root
Returns:
a File object referring to the named resource, or null if not found
Throws:
IllegalStateException - if class is not configured prior to use.

setWebappRoot

public void setWebappRoot(File f)
Configures this ResourceManager to use the specified webapp root.

Parameters:
f - the webapp root directory

setServletContext

public void setServletContext(javax.servlet.ServletContext sctx)
Configures this ResourceManager to use the specified servlet context.

Parameters:
sctx - the servlet context.

getServletContext

public javax.servlet.ServletContext getServletContext()
returns the ServletContext that this ResourceManager uses

Returns:
the servlet context

getWebappRoot

public File getWebappRoot()
Returns:
the webapp root for this ResourceManager.

getLastModified

public long getLastModified(String path)
Returns the last-modified time for the file on disk.

Returns:
the last-modified time for the file on disk. Returns 0L if this isn't available (within a WAR file, for example), the file isn't found, or there's an I/O error. This is consistent with File.lastModified.
Throws:
IllegalStateException - if class is not configured prior to use.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC