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.
|
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.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.
|
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 CmsStaticResourceHandler()
public static java.net.URL getStaticResourceURL(java.lang.String resourcePath)
resourcePath
- the static resource 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