org.apache.catalina.resources
Class JarResources

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

public final class JarResources
extends ResourcesBase

Implementation of the Resources that decompresses and renders entries from a JAR file that is located either locally or remotely. Valid syntax for the docBase property corresponds to the syntax supported by the java.net.JarURLConnection class, and is illustrated by the following examples:

In all cases, the docBase you specify must begin with jar:. If your docBase value does not end with "!/", this will be added for you.

IMPLEMENTATION NOTE: It is assumed that the underlying JAR file itself will not be modified without restarting this web application (or at least this Resources implementation). Therefore, the set of directory and resource entries is pre-loaded into our resource cache. The actual data associated with these resources is not cached until it is requested the first time (and passes the "cacheable" test).

Version:
$Revision: 1.2 $ $Date: 2000/10/21 14:40:27 $
Author:
Craig R. McClanahan

Field Summary
protected  java.net.JarURLConnection conn
          The URLConnection to our JAR file.
protected static java.lang.String info
          The descriptive information string for this implementation.
protected  java.util.jar.JarFile jarFile
          The JarFile object associated with our document base.
 
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
JarResources()
           
 
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.
 void stop()
          Shut down this component.
 
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, 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

conn

protected java.net.JarURLConnection conn
The URLConnection to our JAR file.

info

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

jarFile

protected java.util.jar.JarFile jarFile
The JarFile object associated with our document base.
Constructor Detail

JarResources

public JarResources()
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 the underlying JAR file will not be modified without restarting our associated Context, so it is sufficient to return the last modified timestamp from our cached resource bean.

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).
Overrides:
getResourceCreated in class ResourcesBase
Parameters:
path - The path to the desired resource

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

stop

public void stop()
          throws LifecycleException
Shut down this component.
Overrides:
stop in class ResourcesBase
Throws:
LifecycleException - if a major problem occurs


Copyright © 2000 Apache Software Foundation. All Rights Reserved.