|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.catalina.resources.ResourcesBase
Convenience base class for implementations of the Resources interface. It is expected that subclasses of this class will be created for each flavor of document root to be supported.
Included in the basic support provided by this class is provisions for caching of resources according to configurable policy properties. This will be especially useful for web applications with relatively small amounts of static content (such as a 100% dynamic JSP based application with just a few images), as well as environments where accessing the underlying resources is relatively time consuming (such as a local or remote JAR file).
Field Summary | |
protected int |
checkInterval
The interval (in seconds) at which our background task should check for out-of-date cached resources, or zero for no checks. |
protected Container |
container
The Container this component is associated with (normally a Context). |
protected int |
debug
The debugging detail level for this component. |
protected java.lang.String |
docBase
The document root for this component. |
protected boolean |
expand
Should "directory" entries be expanded? |
protected static java.lang.String |
info
The descriptive information string for this implementation. |
protected LifecycleSupport |
lifecycle
The lifecycle event support for this component. |
protected int |
maxCount
The maximum number of resources to cache. |
protected long |
maxSize
The maximum size of resources to be cached. |
protected long |
minSize
The minimum size of resources to be cached. |
protected static java.lang.String |
prefix
The prefix to the log messages we will be creating. |
protected java.util.HashMap |
resourcesCache
The set of ResourceBean entries for this component, keyed by the normalized context-relative resource URL. |
protected int |
resourcesCount
The count of ResourceBean entries for which we have actually cached data. |
protected static StringManager |
sm
The string manager for this package. |
protected boolean |
started
Has this component been started? |
protected java.beans.PropertyChangeSupport |
support
The property change support for this component. |
protected java.lang.Thread |
thread
The background thread. |
protected boolean |
threadDone
The background thread completion semaphore. |
protected java.lang.String |
threadName
The name to register for the background thread. |
Fields inherited from interface org.apache.catalina.Lifecycle |
START_EVENT, STOP_EVENT |
Constructor Summary | |
ResourcesBase()
Construct a new instance of this class with default values. |
Method Summary | |
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component. |
protected boolean |
cacheable(java.lang.String name,
long size)
Should the resource specified by our parameters be cached? |
abstract boolean |
createCollection(java.lang.String path)
Create a collection at the specified path. |
abstract boolean |
deleteResource(java.lang.String path)
Delete the specified resource. |
protected java.io.File |
engineBase()
Return a File object representing the base directory for the entire servlet container (i.e. |
abstract 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() . |
int |
getCheckInterval()
Return the resource cache check interval. |
abstract java.lang.String[] |
getCollectionMembers(java.lang.String path)
Return the children of the resource at the specified path, if any. |
Container |
getContainer()
Return the Container with which this Resources has been associated. |
int |
getDebug()
Return the debugging detail level for this component. |
java.lang.String |
getDocBase()
Return the document root for this component. |
boolean |
getExpand()
Return the "expand directories" flag. |
java.lang.String |
getInfo()
Return descriptive information about this Resources implementation and the corresponding version number, in the format <description>/<version> . |
int |
getMaxCount()
Return the maximum number of resources to cache. |
long |
getMaxSize()
Return the maximum size of resources to be cached. |
java.lang.String |
getMimeType(java.lang.String file)
Return the MIME type of the specified file, or null if
the MIME type is not known. |
long |
getMinSize()
Return the minimum size of resources to be cached. |
abstract java.lang.String |
getRealPath(java.lang.String path)
Return the real path for a given virtual path. |
abstract java.net.URL |
getResource(java.lang.String path)
Return a URL to the resource that is mapped to the specified path. |
abstract java.io.InputStream |
getResourceAsStream(java.lang.String path)
Return the resource located at the named path as an InputStream object. |
abstract 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() . |
abstract 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() . |
abstract long |
getResourceModified(java.lang.String path)
Return the last modified date/time of the resource at the specified path, where path would be suitable for passing as an
argument to getResource() or
getResourceAsStream() . |
protected java.io.File |
hostBase()
Return a File object representing the base directory for the current virtual host (i.e. |
abstract boolean |
isCollection(java.lang.String path)
Return true if the resource at the specified path is a collection. |
protected void |
log(java.lang.String message)
Log a message on the Logger associated with our Container (if any) |
protected void |
log(java.lang.String message,
java.lang.Throwable throwable)
Log a message on the Logger associated with our Container (if any) |
protected java.lang.String |
normalize(java.lang.String path)
Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out. |
void |
propertyChange(java.beans.PropertyChangeEvent event)
Process property change events from our associated Context. |
void |
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component. |
void |
run()
The background thread that checks for session timeouts and shutdown. |
void |
setCheckInterval(int checkInterval)
Set the resource cache check interval. |
void |
setContainer(Container container)
Set the Container with which this Resources has been associated. |
void |
setDebug(int debug)
Set the debugging detail level for this component. |
void |
setDocBase(java.lang.String docBase)
Set the document root for this component. |
void |
setExpand(boolean expand)
Set the "expand directories" flag. |
void |
setMaxCount(int maxCount)
Set the maximum number of resources to cache. |
void |
setMaxSize(long maxSize)
Set the maximum size of resources to be cached. |
void |
setMinSize(long minSize)
Set the minimum size of resources to be cached. |
abstract boolean |
setResource(java.lang.String path,
java.io.InputStream content)
Set the content of the resource at the specified path. |
void |
start()
Prepare for the beginning of active use of the public methods of this component. |
void |
stop()
Gracefully terminate the active use of the public methods of this component. |
protected void |
threadProcess()
Scan our cached resources, looking for cases where the underlying resource has been modified since we cached it. |
protected void |
threadSleep()
Sleep for the duration specified by the checkInterval
property. |
protected void |
threadStart()
Start the background thread that will periodically check for session timeouts. |
protected void |
threadStop()
Stop the background thread that is periodically checking for session timeouts. |
protected void |
validate(java.lang.String path)
Validate the format of the specified path, which should be context relative and begin with a slash character. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.catalina.Resources |
getResourcePaths |
Field Detail |
protected int checkInterval
protected Container container
protected int debug
protected java.lang.String docBase
protected boolean expand
protected static final java.lang.String info
protected LifecycleSupport lifecycle
protected int maxCount
protected long maxSize
protected long minSize
protected static final java.lang.String prefix
protected java.util.HashMap resourcesCache
protected int resourcesCount
resourcesCache
collection.protected static final StringManager sm
protected boolean started
protected java.beans.PropertyChangeSupport support
protected java.lang.Thread thread
protected boolean threadDone
protected java.lang.String threadName
Constructor Detail |
public ResourcesBase()
Method Detail |
public int getCheckInterval()
public void setCheckInterval(int checkInterval)
checkInterval
- The new check intervalpublic Container getContainer()
getContainer
in interface Resources
public void setContainer(Container container)
setContainer
in interface Resources
container
- The associated Containerpublic int getDebug()
public void setDebug(int debug)
debug
- The new debugging detail levelpublic java.lang.String getDocBase()
public void setDocBase(java.lang.String docBase)
docBase
- The new document rootjava.lang.IllegalArgumentException
- if the specified value is not
supported by this implementationjava.lang.IllegalArgumentException
- if this would create a
malformed URLpublic boolean getExpand()
getExpand
in interface Resources
public void setExpand(boolean expand)
setExpand
in interface Resources
expand
- The new "expand directories" flagpublic java.lang.String getInfo()
<description>/<version>
.getInfo
in interface Resources
public int getMaxCount()
public void setMaxCount(int maxCount)
maxCount
- The new maximum countpublic long getMaxSize()
public void setMaxSize(long maxSize)
maxSize
- The new maximum sizepublic long getMinSize()
public void setMinSize(long minSize)
minSize
- The new minimum sizepublic void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
addPropertyChangeListener
in interface Resources
listener
- The listener to addpublic java.lang.String getMimeType(java.lang.String file)
null
if
the MIME type is not known. The MIME type is determined by the
configuration of the servlet container, and may be specified in a
web application descriptor. Common MIME types are
"text/html"
and "image/gif"
.
The default implementation consults the MIME type mappings that have been registered in our associated Context, if any.
getMimeType
in interface Resources
file
- Name of the file whose MIME type is to be determinedpublic abstract java.lang.String getRealPath(java.lang.String path)
"/index.html"
has a real path of whatever
file on the server's filesystem would be served by a request for
"/index.html"
.
The real path returned will be in a form appropriate to the computer
and operating system on which the servlet container is running,
including the proper path separators. This method returns
null
if the servlet container cannot translate the
virtual path to a real path for any reason (such as when the content
is being made available from a .war
archive).
getRealPath
in interface Resources
path
- The virtual path to be translatedpublic abstract java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException
This method allows the Container to make a resource available to
servlets from any source. Resources can be located on a local or
remote file system, in a database, or in a .war
file.
The servlet container must implement the URL handlers and
URLConnection
objects that are necessary to access
the resource.
This method returns null
if no resource is mapped to
the pathname.
Some Containers may allow writing to the URL returned by this method, using the methods of the URL class.
The resource content is returned directly, so be aware that
requesting a .jsp
page returns the JSP source code.
Use a RequestDispatcher
instead to include results
of an execution.
This method has a different purpose than
java.lang.Class.getResource()
, which looks up resources
based on a class loader. This method does not use class loaders.
getResource
in interface Resources
path
- The path to the desired resourcejava.net.MalformedURLException
- if the pathname is not given
in the correct formpublic abstract java.io.InputStream getResourceAsStream(java.lang.String path)
InputStream
object.
The data in the InputStream
can be of any type or length.
The path must be specified according to the rules given in
getResource()
. This method returns null
if no resource exists at the specified path.
Meta-information such as content length and content type that is
available via the getResource()
method is lost when
using this method.
The servlet container must implement the URL handlers and
URLConnection
objects that are necessary to access
the resource.
This method is different from
java.lang.Class.getResourceAsStream()
, which uses a
class loader. This method allows servlet containers to make a
resource available to a servlet from any location, without using
a class loader.
getResourceAsStream
in interface Resources
path
- The path to the desired resourcepublic abstract boolean exists(java.lang.String path)
path
would be suitable for passing as an argument to
getResource()
or getResourceAsStream()
.
If there is no resource at the specified location, return false.exists
in interface Resources
path
- The path to the desired resourcepublic abstract long getResourceModified(java.lang.String path)
path
would be suitable for passing as an
argument to getResource()
or
getResourceAsStream()
. If there is no resource at the
specified location, return -1.
IMPLEMENTATION NOTE: This method should bypass any cached resources and reference the underlying resource directly, because it will be used by the background thread that is checking for resources that have been modified.
getResourceModified
in interface Resources
path
- The path to the desired resourcepublic abstract long getResourceCreated(java.lang.String path)
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).getResourceCreated
in interface Resources
path
- The path to the desired resourcepublic abstract long getResourceLength(java.lang.String path)
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.getResourceLength
in interface Resources
path
- The path to the desired resourcepublic abstract boolean isCollection(java.lang.String path)
isCollection
in interface Resources
path
- The path to the desired resourcepublic abstract java.lang.String[] getCollectionMembers(java.lang.String path)
getCollectionMembers
in interface Resources
path
- The path to the desired resourcepublic abstract boolean setResource(java.lang.String path, java.io.InputStream content)
setResource
in interface Resources
path
- The path to the desired resourcecontent
- InputStream to the content to be setpublic abstract boolean createCollection(java.lang.String path)
createCollection
in interface Resources
path
- The path to the desired resourcepublic abstract boolean deleteResource(java.lang.String path)
deleteResource
in interface Resources
path
- The path to the desired resourcepublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
removePropertyChangeListener
in interface Resources
listener
- The listener to removepublic void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
event
- The property change event that has occurredpublic void addLifecycleListener(LifecycleListener listener)
addLifecycleListener
in interface Lifecycle
listener
- The listener to addpublic void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener
in interface Lifecycle
listener
- The listener to removepublic void start() throws LifecycleException
configure()
,
and before any of the public methods of the component are utilized.start
in interface Lifecycle
IllegalStateException
- if this component has already been
startedLifecycleException
- if this component detects a fatal error
that prevents this component from being usedpublic void stop() throws LifecycleException
stop
in interface Lifecycle
IllegalStateException
- if this component has not been startedLifecycleException
- if this component detects a fatal error
that needs to be reportedprotected boolean cacheable(java.lang.String name, long size)
name
- Name of the proposed resourcesize
- Size (in bytes) of the proposed resourceprotected java.io.File engineBase()
protected java.io.File hostBase()
protected void log(java.lang.String message)
message
- Message to be loggedprotected void log(java.lang.String message, java.lang.Throwable throwable)
message
- Message to be loggedthrowable
- Associated exceptionprotected java.lang.String normalize(java.lang.String path)
null
instead.path
- Path to be normalizedprotected void threadProcess()
protected void threadSleep()
checkInterval
property.protected void threadStart()
protected void threadStop()
protected void validate(java.lang.String path)
path
- Context-relative path to be validatedjava.lang.IllegalArgumentException
- if the specified path is null
or does not have a valid formatpublic void run()
run
in interface java.lang.Runnable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |