org.mortbay.http
Class ResourceCache

java.lang.Object
  extended byorg.mortbay.http.ResourceCache
All Implemented Interfaces:
LifeCycle, java.io.Serializable

public class ResourceCache
extends java.lang.Object
implements LifeCycle, java.io.Serializable

Version:
$Id: ResourceCache.java,v 1.12 2005/08/13 00:01:24 gregwilkins Exp $
Author:
Greg Wilkins
See Also:
Serialized Form

Nested Class Summary
 class ResourceCache.ResourceMetaData
          MetaData associated with a context Resource.
 
Constructor Summary
ResourceCache()
          Constructor.
 
Method Summary
 void destroy()
          Destroy a context.
 void flushCache()
           
 Resource getBaseResource()
          Get the base resource.
 java.lang.String getEncodingByMimeType(java.lang.String type)
          Get char encoding by mime type.
 java.util.Map getEncodingMap()
          Get the map of mime type to char encoding.
 int getMaxCachedFileSize()
           
 int getMaxCacheSize()
           
 java.lang.String getMimeByExtension(java.lang.String filename)
          Get the MIME type by filename extension.
 java.util.Map getMimeMap()
           
 Resource getResource(java.lang.String pathInContext)
          Get a resource from the context.
 java.lang.String getResourceBase()
          Set the Resource Base.
 ResourceCache.ResourceMetaData getResourceMetaData(Resource resource)
          Get Resource MetaData.
 boolean isStarted()
           
 void setBaseResource(Resource base)
          Set the base resource.
 void setEncodingMap(java.util.Map encodingMap)
          Set the map of mime type to char encoding.
 void setMaxCachedFileSize(int maxCachedFileSize)
           
 void setMaxCacheSize(int maxCacheSize)
           
 void setMimeMap(java.util.Map mimeMap)
          Also sets the org.mortbay.http.mimeMap context attribute
 void setMimeMapping(java.lang.String extension, java.lang.String type)
          Set a mime mapping
 void setResourceBase(java.lang.String resourceBase)
          Set the Resource Base.
 void setTypeEncoding(java.lang.String mimeType, java.lang.String encoding)
          Set the encoding that should be used for a mimeType.
 void start()
          Start the LifeCycle.
 void stop()
          Stop the context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceCache

public ResourceCache()
Constructor.

Method Detail

getResourceBase

public java.lang.String getResourceBase()
Set the Resource Base. The base resource is the Resource to use as a relative base for all context resources. The ResourceBase attribute is a string version of the baseResource. If a relative file is passed, it is converted to a file URL based on the current working directory.

Returns:
The file or URL to use as the base for all resources within the context.

setResourceBase

public void setResourceBase(java.lang.String resourceBase)
Set the Resource Base. The base resource is the Resource to use as a relative base for all context resources. The ResourceBase attribute is a string version of the baseResource. If a relative file is passed, it is converted to a file URL based on the current working directory.

Parameters:
resourceBase - A URL prefix or directory name.

getBaseResource

public Resource getBaseResource()
Get the base resource. The base resource is the Resource to use as a relative base for all context resources. The ResourceBase attribute is a string version of the baseResource.

Returns:
The resourceBase as a Resource instance

setBaseResource

public void setBaseResource(Resource base)
Set the base resource. The base resource is the Resource to use as a relative base for all context resources. The ResourceBase attribute is a string version of the baseResource.

Parameters:
base - The resourceBase as a Resource instance

getMaxCachedFileSize

public int getMaxCachedFileSize()

setMaxCachedFileSize

public void setMaxCachedFileSize(int maxCachedFileSize)

getMaxCacheSize

public int getMaxCacheSize()

setMaxCacheSize

public void setMaxCacheSize(int maxCacheSize)

flushCache

public void flushCache()

getResource

public Resource getResource(java.lang.String pathInContext)
                     throws java.io.IOException
Get a resource from the context. Cached Resources are returned if the resource fits within the LRU cache. Directories may have CachedResources returned, but the caller must use the CachedResource.setCachedData method to set the formatted directory content.

Parameters:
pathInContext -
Returns:
Resource
Throws:
java.io.IOException

getMimeMap

public java.util.Map getMimeMap()

setMimeMap

public void setMimeMap(java.util.Map mimeMap)
Also sets the org.mortbay.http.mimeMap context attribute

Parameters:
mimeMap -

getMimeByExtension

public java.lang.String getMimeByExtension(java.lang.String filename)
Get the MIME type by filename extension.

Parameters:
filename - A file name
Returns:
MIME type matching the longest dot extension of the file name.

setMimeMapping

public void setMimeMapping(java.lang.String extension,
                           java.lang.String type)
Set a mime mapping

Parameters:
extension -
type -

getEncodingMap

public java.util.Map getEncodingMap()
Get the map of mime type to char encoding.

Returns:
Map of mime type to character encodings.

setEncodingMap

public void setEncodingMap(java.util.Map encodingMap)
Set the map of mime type to char encoding. Also sets the org.mortbay.http.encodingMap context attribute

Parameters:
encodingMap - Map of mime type to character encodings.

getEncodingByMimeType

public java.lang.String getEncodingByMimeType(java.lang.String type)
Get char encoding by mime type.

Parameters:
type - A mime type.
Returns:
The prefered character encoding for that type if known.

setTypeEncoding

public void setTypeEncoding(java.lang.String mimeType,
                            java.lang.String encoding)
Set the encoding that should be used for a mimeType.

Parameters:
mimeType -
encoding -

start

public void start()
           throws java.lang.Exception
Description copied from interface: LifeCycle
Start the LifeCycle.

Specified by:
start in interface LifeCycle
Throws:
java.lang.Exception - An arbitrary exception may be thrown.

isStarted

public boolean isStarted()
Specified by:
isStarted in interface LifeCycle
Returns:
True if the LifeCycle has been started.

stop

public void stop()
          throws java.lang.InterruptedException
Stop the context.

Specified by:
stop in interface LifeCycle
Throws:
java.lang.InterruptedException - Stopping a lifecycle is rarely atomic and may be interrupted by another thread. If this happens InterruptedException is throw and the component will be in an indeterminant state and should probably be discarded.

destroy

public void destroy()
Destroy a context. Destroy a context and remove it from the HttpServer. The HttpContext must be stopped before it can be destroyed.


getResourceMetaData

public ResourceCache.ResourceMetaData getResourceMetaData(Resource resource)
Get Resource MetaData.

Parameters:
resource -
Returns:
Meta data for the resource.


Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.