org.apache.catalina.resources
Class FileResources

java.lang.Object
  |
  +--org.apache.catalina.resources.ResourcesBase
        |
        +--org.apache.catalina.resources.FileResources
All Implemented Interfaces:
java.util.EventListener, Lifecycle, java.beans.PropertyChangeListener, Resources, java.lang.Runnable

public final class FileResources
extends ResourcesBase

Implementation of the Resources that operates off a document base that is a directory in the local filesystem. If the specified document base is relative, it is resolved against the application base directory for our surrounding virtual host (if any), or against the value of the "catalina.home" system property.

IMPLEMENTATION NOTE: It is assumed that new files may be added, and existing files modified, while this web application is running. Therefore, only resources (not directories) are cached, and the background thread must remove cached entries that have been modified since they were cached.

Version:
$Revision: 1.4 $ $Date: 2000/10/21 14:40:27 $
Author:
Craig R. McClanahan, Remy Maucherat

Field Summary
protected  java.io.File base
          The document base directory for this component.
protected static int BUFFER_SIZE
          The descriptive information string for this implementation.
protected static java.lang.String info
          The descriptive information string for this implementation.
 
Fields inherited from class org.apache.catalina.resources.ResourcesBase
checkInterval, container, debug, docBase, expand, lifecycle, maxCount, maxSize, minSize, prefix, resourcesCache, resourcesCount, sm, started, support, thread, threadDone, threadName
 
Fields inherited from interface org.apache.catalina.Lifecycle
START_EVENT, STOP_EVENT
 
Constructor Summary
FileResources()
           
 
Method Summary
 boolean createCollection(java.lang.String path)
          Create a collection at the specified path.
 boolean deleteResource(java.lang.String path)
          Delete the specified resource.
 boolean exists(java.lang.String path)
          Returns true if a resource exists at the specified path, where path would be suitable for passing as an argument to getResource() or getResourceAsStream().
 java.lang.String[] getCollectionMembers(java.lang.String path)
          Return the children of the resource at the specified path, if any.
 java.lang.String getRealPath(java.lang.String path)
          Return the real path for a given virtual path, or null if no such path can be identified.
 java.net.URL getResource(java.lang.String path)
          Return a URL to the resource specified by the given virtual path, or null if no such URL can be identified.
 java.io.InputStream getResourceAsStream(java.lang.String path)
          Return an InputStream to the contents of the resource specified by the given virtual path, or null if no resource exists at the specified path.
 long getResourceCreated(java.lang.String path)
          Return the creation date/time of the resource at the specified path, where path would be suitable for passing as an argument to getResource() or getResourceAsStream().
 long getResourceLength(java.lang.String path)
          Return the content length of the resource at the specified path, where path would be suitable for passing as an argument to getResource() or getResourceAsStream().
 long getResourceModified(java.lang.String path)
          Return the last modified time for the resource specified by the given virtual path, or -1 if no such resource exists (or the last modified time cannot be determined).
 java.lang.String[] getResourcePaths()
          Return the set of context-relative paths of all available resources.
 boolean isCollection(java.lang.String path)
          Return true if the resource at the specified path is a collection.
 void setDocBase(java.lang.String docBase)
          Set the document root for this component.
 boolean setResource(java.lang.String path, java.io.InputStream content)
          Set the content of the resource at the specified path.
 
Methods inherited from class org.apache.catalina.resources.ResourcesBase
addLifecycleListener, addPropertyChangeListener, cacheable, engineBase, getCheckInterval, getContainer, getDebug, getDocBase, getExpand, getInfo, getMaxCount, getMaxSize, getMimeType, getMinSize, hostBase, log, log, normalize, propertyChange, removeLifecycleListener, removePropertyChangeListener, run, setCheckInterval, setContainer, setDebug, setExpand, setMaxCount, setMaxSize, setMinSize, start, stop, threadProcess, threadSleep, threadStart, threadStop, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

protected java.io.File base
The document base directory for this component.

info

protected static final java.lang.String info
The descriptive information string for this implementation.

BUFFER_SIZE

protected static final int BUFFER_SIZE
The descriptive information string for this implementation.
Constructor Detail

FileResources

public FileResources()
Method Detail

setDocBase

public void setDocBase(java.lang.String docBase)
Set the document root for this component.
Overrides:
setDocBase in class ResourcesBase
Parameters:
docBase - The new document root
Throws:
java.lang.IllegalArgumentException - if the specified value is not supported by this implementation
java.lang.IllegalArgumentException - if this would create a malformed URL

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Return the real path for a given virtual path, or null if no such path can be identified.
Overrides:
getRealPath in class ResourcesBase
Parameters:
path - Context-relative path starting with '/'
Throws:
java.lang.IllegalArgumentException - if the path argument is null or does not start with a '/'

getResource

public java.net.URL getResource(java.lang.String path)
                         throws java.net.MalformedURLException
Return a URL to the resource specified by the given virtual path, or null if no such URL can be identified.

IMPLEMENTATION NOTE: Use of this method bypasses any caching performed by this component. To take advantage of local caching, use getResourceAsStream() instead.

Overrides:
getResource in class ResourcesBase
Parameters:
path - Context-relative path starting with '/'
Throws:
java.lang.IllegalArgumentException - if the path argument is null or does not start with a '/'
java.net.MalformedURLException - if the resulting URL does not have legal syntax

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)
Return an InputStream to the contents of the resource specified by the given virtual path, or null if no resource exists at the specified path.
Overrides:
getResourceAsStream in class ResourcesBase
Parameters:
path - Context-relative path starting with '/'
Throws:
java.lang.IllegalArgumentException - if the path argument is null or does not start with a '/'

exists

public boolean exists(java.lang.String path)
Returns true if a resource exists at the specified path, where path would be suitable for passing as an argument to getResource() or getResourceAsStream(). If there is no resource at the specified location, return false.
Overrides:
exists in class ResourcesBase
Parameters:
path - The path to the desired resource

getResourceModified

public long getResourceModified(java.lang.String path)
Return the last modified time for the resource specified by the given virtual path, or -1 if no such resource exists (or the last modified time cannot be determined).

IMPLEMENTATION NOTE: We are assuming that files may be modified while the application is running, so we bypass the cache and check the filesystem directly.

Overrides:
getResourceModified in class ResourcesBase
Parameters:
path - Context-relative path starting with '/'
Throws:
java.lang.IllegalArgumentException - if the path argument is null or does not start with a '/'

getResourcePaths

public java.lang.String[] getResourcePaths()
Return the set of context-relative paths of all available resources. Each path will begin with a "/" character.

getResourceCreated

public long getResourceCreated(java.lang.String path)
Return the creation date/time of the resource at the specified path, where path would be suitable for passing as an argument to getResource() or getResourceAsStream(). If there is no resource at the specified location, return -1. If this time is unknown, the implementation should return getResourceModified(path).

IMPLEMENTATION NOTE: The creation date of a file shouldn't change except if the file is deleted and the recreated, so this method uses the cache.

Overrides:
getResourceCreated in class ResourcesBase
Parameters:
path - Context-relative path starting with '/'
Throws:
java.lang.IllegalArgumentException - if the path argument is null or does not start with a '/'

getResourceLength

public long getResourceLength(java.lang.String path)
Return the content length of the resource at the specified path, where path would be suitable for passing as an argument to getResource() or getResourceAsStream(). If the content length of the resource can't be determined, return -1. If no content is available (when for exemple, the resource is a collection), return 0.
Overrides:
getResourceLength in class ResourcesBase
Parameters:
path - The path to the desired resource

isCollection

public boolean isCollection(java.lang.String path)
Return true if the resource at the specified path is a collection. A collection is a special type of resource which has no content but contains child resources.
Overrides:
isCollection in class ResourcesBase
Parameters:
path - The path to the desired resource

getCollectionMembers

public java.lang.String[] getCollectionMembers(java.lang.String path)
Return the children of the resource at the specified path, if any. This will return null if the resource is not a collection, or if it is a collection but has no children.
Overrides:
getCollectionMembers in class ResourcesBase
Parameters:
path - The path to the desired resource

setResource

public boolean setResource(java.lang.String path,
                           java.io.InputStream content)
Set the content of the resource at the specified path. If the resource already exists, its previous content is overwritten. If the resource doesn't exist, its immediate parent collection (according to the path given) exists, then its created, and the given content is associated with it. Return false if either the resource is a collection, or no parent collection exist.
Overrides:
setResource in class ResourcesBase
Parameters:
path - The path to the desired resource
content - InputStream to the content to be set

createCollection

public boolean createCollection(java.lang.String path)
Create a collection at the specified path. A parent collection for this collection must exist. Return false if a resource already exist at the path specified, or if the parent collection doesn't exist.
Overrides:
createCollection in class ResourcesBase
Parameters:
path - The path to the desired resource

deleteResource

public boolean deleteResource(java.lang.String path)
Delete the specified resource. Non-empty collections cannot be deleted before deleting all their member resources. Return false is deletion fails because either the resource specified doesn't exist, or the resource is a non-empty collection.
Overrides:
deleteResource in class ResourcesBase
Parameters:
path - The path to the desired resource


Copyright © 2000 Apache Software Foundation. All Rights Reserved.