Class CachedResource
java.lang.Object
org.apache.catalina.webresources.CachedResource
- All Implemented Interfaces:
WebResource
This class is designed to wrap a 'raw' WebResource and providing caching for expensive operations. Inexpensive
operations may be passed through to the underlying resource.
-
Constructor Summary
ConstructorDescriptionCachedResource
(Cache cache, StandardRoot root, String path, long ttl, int objectMaxSizeBytes, boolean usesClassLoaderResources) -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRead()
boolean
delete()
boolean
exists()
Returns the code base for this resource.byte[]
long
long
getETag()
Return the weak ETag calculated from the content length and last modified.Obtain an InputStream based on the contents of this resource.long
getName()
protected long
Return the strong ETag if available else return the weak ETag calculated from the content length and last modified.getURL()
boolean
boolean
isFile()
boolean
Indicates if this resource is required for applications to correctly scan the file structure but that does not exist in either the main or any additionalWebResourceSet
.void
setMimeType
(String mimeType) Set the MIME type for this Resource.protected boolean
validateResource
(boolean useClassLoaderResources) protected boolean
validateResources
(boolean useClassLoaderResources)
-
Constructor Details
-
CachedResource
public CachedResource(Cache cache, StandardRoot root, String path, long ttl, int objectMaxSizeBytes, boolean usesClassLoaderResources)
-
-
Method Details
-
validateResource
protected boolean validateResource(boolean useClassLoaderResources) -
validateResources
protected boolean validateResources(boolean useClassLoaderResources) -
getNextCheck
protected long getNextCheck() -
getLastModified
public long getLastModified()- Specified by:
getLastModified
in interfaceWebResource
- Returns:
File.lastModified()
.
-
getLastModifiedHttp
- Specified by:
getLastModifiedHttp
in interfaceWebResource
- Returns:
- the last modified time of this resource in the correct format for the HTTP Last-Modified header as specified by RFC 2616.
-
exists
public boolean exists()- Specified by:
exists
in interfaceWebResource
- Returns:
File.exists()
.
-
isVirtual
public boolean isVirtual()Description copied from interface:WebResource
Indicates if this resource is required for applications to correctly scan the file structure but that does not exist in either the main or any additionalWebResourceSet
. For example, if an external directory is mapped to /WEB-INF/lib in an otherwise empty web application, /WEB-INF will be represented as a virtual resource.- Specified by:
isVirtual
in interfaceWebResource
- Returns:
true
for a virtual resource
-
isDirectory
public boolean isDirectory()- Specified by:
isDirectory
in interfaceWebResource
- Returns:
File.isDirectory()
.
-
isFile
public boolean isFile()- Specified by:
isFile
in interfaceWebResource
- Returns:
File.isFile()
.
-
delete
public boolean delete()- Specified by:
delete
in interfaceWebResource
- Returns:
File.delete()
.
-
getName
- Specified by:
getName
in interfaceWebResource
- Returns:
File.getName()
.
-
getContentLength
public long getContentLength()- Specified by:
getContentLength
in interfaceWebResource
- Returns:
File.length()
.
-
getCanonicalPath
- Specified by:
getCanonicalPath
in interfaceWebResource
- Returns:
File.getCanonicalPath()
.
-
canRead
public boolean canRead()- Specified by:
canRead
in interfaceWebResource
- Returns:
File.canRead()
.
-
getWebappPath
- Specified by:
getWebappPath
in interfaceWebResource
- Returns:
- The path of this resource relative to the web application root. If the resource is a directory, the return value will end in '/'.
-
getETag
Description copied from interface:WebResource
Return the weak ETag calculated from the content length and last modified.- Specified by:
getETag
in interfaceWebResource
- Returns:
- The ETag for this resource
-
getStrongETag
Description copied from interface:WebResource
Return the strong ETag if available else return the weak ETag calculated from the content length and last modified.- Specified by:
getStrongETag
in interfaceWebResource
- Returns:
- The ETag for this resource
-
setMimeType
Description copied from interface:WebResource
Set the MIME type for this Resource.- Specified by:
setMimeType
in interfaceWebResource
- Parameters:
mimeType
- The mime type that will be associated with the resource
-
getMimeType
- Specified by:
getMimeType
in interfaceWebResource
- Returns:
- the MIME type for this Resource.
-
getInputStream
Description copied from interface:WebResource
Obtain an InputStream based on the contents of this resource.- Specified by:
getInputStream
in interfaceWebResource
- Returns:
- An InputStream based on the contents of this resource or
null
if the resource does not exist or does not represent a file
-
getContent
public byte[] getContent()- Specified by:
getContent
in interfaceWebResource
- Returns:
- the binary content of this resource or
null
if it is not available in a byte[] because, for example, it is too big.
-
getCreation
public long getCreation()- Specified by:
getCreation
in interfaceWebResource
- Returns:
- The time the file was created. If not available, the result of
WebResource.getLastModified()
will be returned.
-
getURL
- Specified by:
getURL
in interfaceWebResource
- Returns:
- a URL to access the resource or
null
if no such URL is available or if the resource does not exist.
-
getCodeBase
Description copied from interface:WebResource
Returns the code base for this resource.The expectation is that this will be deprecated and then removed once the SecurityManager has been fully removed from the JRE and it has been confirmed that the JRE no longer depends on code base.
- Specified by:
getCodeBase
in interfaceWebResource
- Returns:
- the code base for this resource that will be used when looking up the assigned permissions for the code base in the security policy file when running under a security manager.
-
getCertificates
- Specified by:
getCertificates
in interfaceWebResource
- Returns:
- the certificates that were used to sign this resource to verify it or @null if none.
- See Also:
-
getManifest
- Specified by:
getManifest
in interfaceWebResource
- Returns:
- the manifest associated with this resource or @null if none.
- See Also:
-
getWebResourceRoot
- Specified by:
getWebResourceRoot
in interfaceWebResource
- Returns:
- a reference to the WebResourceRoot of which this WebResource is a part.
-