org.mortbay.http

Class ResourceCache

public class ResourceCache extends Object implements LifeCycle, Serializable

Version: $Id: ResourceCache.java,v 1.13 2006/04/04 22:28:02 gregwilkins Exp $

Author: Greg Wilkins

Nested Class Summary
classResourceCache.ResourceMetaData
MetaData associated with a context Resource.
Field Summary
protected Map_cache
protected int_cacheSize
protected ResourceCache.CachedMetaData_leastRecentlyUsed
protected ResourceCache.CachedMetaData_mostRecentlyUsed
Constructor Summary
ResourceCache()
Constructor.
Method Summary
voiddestroy()
Destroy a context.
voidflushCache()
ResourcegetBaseResource()
Get the base resource.
StringgetEncodingByMimeType(String type)
Get char encoding by mime type.
MapgetEncodingMap()
Get the map of mime type to char encoding.
intgetMaxCachedFileSize()
intgetMaxCacheSize()
StringgetMimeByExtension(String filename)
Get the MIME type by filename extension.
MapgetMimeMap()
ResourcegetResource(String pathInContext)
Get a resource from the context.
StringgetResourceBase()
Set the Resource Base.
ResourceCache.ResourceMetaDatagetResourceMetaData(Resource resource)
Get Resource MetaData.
booleanisStarted()
voidsetBaseResource(Resource base)
Set the base resource.
voidsetEncodingMap(Map encodingMap)
Set the map of mime type to char encoding.
voidsetMaxCachedFileSize(int maxCachedFileSize)
voidsetMaxCacheSize(int maxCacheSize)
voidsetMimeMap(Map mimeMap)
Also sets the org.mortbay.http.mimeMap context attribute
voidsetMimeMapping(String extension, String type)
Set a mime mapping
voidsetResourceBase(String resourceBase)
Set the Resource Base.
voidsetTypeEncoding(String mimeType, String encoding)
Set the encoding that should be used for a mimeType.
voidstart()
voidstop()
Stop the context.

Field Detail

_cache

protected transient Map _cache

_cacheSize

protected transient int _cacheSize

_leastRecentlyUsed

protected transient ResourceCache.CachedMetaData _leastRecentlyUsed

_mostRecentlyUsed

protected transient ResourceCache.CachedMetaData _mostRecentlyUsed

Constructor Detail

ResourceCache

public ResourceCache()
Constructor.

Method Detail

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.

flushCache

public void flushCache()

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

getEncodingByMimeType

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

Parameters: type A mime type.

Returns: The prefered character encoding for that type if known.

getEncodingMap

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

Returns: Map of mime type to character encodings.

getMaxCachedFileSize

public int getMaxCachedFileSize()

getMaxCacheSize

public int getMaxCacheSize()

getMimeByExtension

public String getMimeByExtension(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.

getMimeMap

public Map getMimeMap()

getResource

public Resource getResource(String pathInContext)
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: IOException

getResourceBase

public 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.

getResourceMetaData

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

Parameters: resource

Returns: Meta data for the resource.

isStarted

public boolean isStarted()

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

setEncodingMap

public void setEncodingMap(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.

setMaxCachedFileSize

public void setMaxCachedFileSize(int maxCachedFileSize)

setMaxCacheSize

public void setMaxCacheSize(int maxCacheSize)

setMimeMap

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

Parameters: mimeMap

setMimeMapping

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

Parameters: extension type

setResourceBase

public void setResourceBase(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.

setTypeEncoding

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

Parameters: mimeType encoding

start

public void start()

stop

public void stop()
Stop the context.
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.