org.mortbay.http

Class ResourceCache

Implemented Interfaces:
LifeCycle, Serializable

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

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

Nested Class Summary

class
ResourceCache.ResourceMetaData
MetaData associated with a context Resource.

Field Summary

protected Map
_cache
protected int
_cacheSize
protected org.mortbay.http.ResourceCache.CachedMetaData
_leastRecentlyUsed
protected org.mortbay.http.ResourceCache.CachedMetaData
_mostRecentlyUsed

Constructor Summary

ResourceCache()
Constructor.

Method Summary

void
destroy()
Destroy a context.
void
flushCache()
Resource
getBaseResource()
Get the base resource.
String
getEncodingByMimeType(String type)
Get char encoding by mime type.
Map
getEncodingMap()
Get the map of mime type to char encoding.
int
getMaxCacheSize()
int
getMaxCachedFileSize()
String
getMimeByExtension(String filename)
Get the MIME type by filename extension.
Map
getMimeMap()
Resource
getResource(String pathInContext)
Get a resource from the context.
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(Map encodingMap)
Set the map of mime type to char encoding.
void
setMaxCacheSize(int maxCacheSize)
void
setMaxCachedFileSize(int maxCachedFileSize)
void
setMimeMap(Map mimeMap)
Also sets the org.mortbay.http.mimeMap context attribute
void
setMimeMapping(String extension, String type)
Set a mime mapping
void
setResourceBase(String resourceBase)
Set the Resource Base.
void
setTypeEncoding(String mimeType, String encoding)
Set the encoding that should be used for a mimeType.
void
start()
void
stop()
Stop the context.

Field Details

_cache

protected Map _cache

_cacheSize

protected int _cacheSize

_leastRecentlyUsed

protected org.mortbay.http.ResourceCache.CachedMetaData _leastRecentlyUsed

_mostRecentlyUsed

protected org.mortbay.http.ResourceCache.CachedMetaData _mostRecentlyUsed

Constructor Details

ResourceCache

public ResourceCache()
Constructor.

Method Details

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.

getMaxCacheSize

public int getMaxCacheSize()

getMaxCachedFileSize

public int getMaxCachedFileSize()

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)
            throws 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

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()
Specified by:
isStarted in interface LifeCycle

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.

setMaxCacheSize

public void setMaxCacheSize(int maxCacheSize)

setMaxCachedFileSize

public void setMaxCachedFileSize(int maxCachedFileSize)

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()
            throws Exception
Specified by:
start in interface LifeCycle

stop

public void stop()
            throws InterruptedException
Stop the context.
Specified by:
stop in interface LifeCycle

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