public class CmsStaticResourceHandler extends java.lang.Object implements I_CmsRequestHandler
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
HANDLER_NAME
The handler name.
|
static java.lang.String |
STATIC_RESOURCE_PREFIX
The static resource prefix '/handleStatic'.
|
Constructor and Description |
---|
CmsStaticResourceHandler() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
allowServePrecompressedResource(javax.servlet.http.HttpServletRequest request,
java.lang.String url)
Returns whether this servlet should attempt to serve a precompressed
version of the given static resource.
|
protected int |
getCacheTime(java.lang.String filename)
Calculates the cache lifetime for the given filename in seconds.
|
java.lang.String[] |
getHandlerNames()
Returns the handler name.
|
static java.lang.String |
getStaticResourceContext(java.lang.String opencmsContext,
java.lang.String opencmsVersion)
Returns the context for static resources served from the class path, e.g.
|
static java.net.URL |
getStaticResourceURL(java.lang.String resourcePath)
Returns the URL to a static resource.
|
void |
handle(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String name)
Handles an OpenCms request.
|
static boolean |
isStaticResourceUri(java.lang.String path)
Returns if the given URI points to a static resource.
|
static boolean |
isStaticResourceUri(java.net.URI uri)
Returns if the given URI points to a static resource.
|
static java.lang.String |
removeStaticResourcePrefix(java.lang.String path)
Removes the static resource path prefix.
|
protected void |
setResponseHeaders(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String filename,
java.net.URL resourceURL)
Sets the response headers.
|
protected void |
writeStaticResourceResponse(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.net.URL resourceUrl)
Writes the contents of the given resourceUrl in the response.
|
public static final java.lang.String HANDLER_NAME
public static final java.lang.String STATIC_RESOURCE_PREFIX
public CmsStaticResourceHandler()
public static java.lang.String getStaticResourceContext(java.lang.String opencmsContext, java.lang.String opencmsVersion)
opencmsContext
- the OpenCms contextopencmsVersion
- the OpenCms versionpublic static java.net.URL getStaticResourceURL(java.lang.String resourcePath)
resourcePath
- the static resource pathpublic static boolean isStaticResourceUri(java.lang.String path)
path
- the path to testtrue
in case the given URI points to a static resourcepublic static boolean isStaticResourceUri(java.net.URI uri)
uri
- the URI to testtrue
in case the given URI points to a static resourcepublic static java.lang.String removeStaticResourcePrefix(java.lang.String path)
path
- the pathpublic java.lang.String[] getHandlerNames()
I_CmsRequestHandler
getHandlerNames
in interface I_CmsRequestHandler
I_CmsRequestHandler.getHandlerNames()
public void handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String name) throws java.io.IOException
I_CmsRequestHandler
handle
in interface I_CmsRequestHandler
request
- the current requestresponse
- the current responsename
- the handler name to invokejava.io.IOException
- in case an error occursI_CmsRequestHandler.handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
protected boolean allowServePrecompressedResource(javax.servlet.http.HttpServletRequest request, java.lang.String url)
.gz
is appended to the URL and the corresponding resource
is served if it exists. It is assumed that the compression method used is
gzip. If this method returns false or a compressed version is not found,
the original URL is used.The base implementation of this method returns true if and only if the request indicates that the client accepts gzip compressed responses and the filename extension of the requested resource is .js, .css, or .html.
request
- the request for the resourceurl
- the URL of the requested resourceprotected int getCacheTime(java.lang.String filename)
filename
- the file nameprotected void setResponseHeaders(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String filename, java.net.URL resourceURL)
request
- the requestresponse
- the responsefilename
- the file nameresourceURL
- the resource URLprotected void writeStaticResourceResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.net.URL resourceUrl) throws java.io.IOException
request
- the request for the resourceresponse
- the responseresourceUrl
- the url to sendjava.io.IOException
- in case writing the response fails