Package org.opencms.main
Class CmsStaticResourceHandler
java.lang.Object
org.opencms.main.CmsStaticResourceHandler
- All Implemented Interfaces:
I_CmsRequestHandler
Handles the requests for static resources located in the classpath.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanallowServePrecompressedResource(javax.servlet.http.HttpServletRequest request, String url) Returns whether this servlet should attempt to serve a precompressed version of the given static resource.protected intgetCacheTime(String filename) Calculates the cache lifetime for the given filename in seconds.String[]Returns the handler name.static StringgetStaticResourceContext(String opencmsContext, String opencmsVersion) Returns the context for static resources served from the class path, e.g.static URLgetStaticResourceURL(String resourcePath) Returns the URL to a static resource.voidhandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String name) Handles an OpenCms request.static booleanisStaticResourceUri(String path) Returns if the given URI points to a static resource.static booleanisStaticResourceUri(URI uri) Returns if the given URI points to a static resource.static StringRemoves the static resource path prefix.protected voidsetResponseHeaders(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String filename, URL resourceURL) Sets the response headers.protected voidwriteStaticResourceResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, URL resourceUrl) Writes the contents of the given resourceUrl in the response.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opencms.main.I_CmsRequestHandler
getConfiguration, initParameters
-
Field Details
-
HANDLER_NAME
The handler name.- See Also:
-
STATIC_RESOURCE_PREFIX
The static resource prefix '/handleStatic'.- See Also:
-
-
Constructor Details
-
CmsStaticResourceHandler
public CmsStaticResourceHandler()
-
-
Method Details
-
getStaticResourceContext
Returns the context for static resources served from the class path, e.g. "/opencms/handleStatic/v5976v".- Parameters:
opencmsContext- the OpenCms contextopencmsVersion- the OpenCms version- Returns:
- the static resource context
-
getStaticResourceURL
Returns the URL to a static resource.- Parameters:
resourcePath- the static resource path- Returns:
- the resource URL
-
isStaticResourceUri
Returns if the given URI points to a static resource.- Parameters:
path- the path to test- Returns:
truein case the given URI points to a static resource
-
isStaticResourceUri
Returns if the given URI points to a static resource.- Parameters:
uri- the URI to test- Returns:
truein case the given URI points to a static resource
-
removeStaticResourcePrefix
Removes the static resource path prefix.- Parameters:
path- the path- Returns:
- the modified path
-
getHandlerNames
Description copied from interface:I_CmsRequestHandlerReturns the handler name.- Specified by:
getHandlerNamesin interfaceI_CmsRequestHandler- Returns:
- the handler name
- See Also:
-
handle
public void handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String name) throws IOException Description copied from interface:I_CmsRequestHandlerHandles an OpenCms request.- Specified by:
handlein interfaceI_CmsRequestHandler- Parameters:
request- the current requestresponse- the current responsename- the handler name to invoke- Throws:
IOException- in case an error occurs- See Also:
-
allowServePrecompressedResource
protected boolean allowServePrecompressedResource(javax.servlet.http.HttpServletRequest request, String url) Returns whether this servlet should attempt to serve a precompressed version of the given static resource. If this method returns true, the suffix.gzis 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.
- Parameters:
request- the request for the resourceurl- the URL of the requested resource- Returns:
- true if the servlet should attempt to serve a precompressed version of the resource, false otherwise
-
getCacheTime
Calculates the cache lifetime for the given filename in seconds. By default filenames containing ".nocache." return 0, filenames containing ".cache." return one year, all other return the value defined in the web.xml using resourceCacheTime (defaults to 1 hour).- Parameters:
filename- the file name- Returns:
- cache lifetime for the given filename in seconds
-
setResponseHeaders
protected void setResponseHeaders(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String filename, URL resourceURL) Sets the response headers.- Parameters:
request- the requestresponse- the responsefilename- the file nameresourceURL- the resource URL
-
writeStaticResourceResponse
protected void writeStaticResourceResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, URL resourceUrl) throws IOException Writes the contents of the given resourceUrl in the response. Can be overridden to add/modify response headers and similar.- Parameters:
request- the request for the resourceresponse- the responseresourceUrl- the url to send- Throws:
IOException- in case writing the response fails
-