Package org.teamapps.ux.resource
Class ResourceProviderServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.teamapps.ux.resource.ResourceProviderServlet
- All Implemented Interfaces:
java.io.Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class ResourceProviderServlet
extends javax.servlet.http.HttpServlet
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description ResourceProviderServlet(ResourceProvider resourceProvider) -
Method Summary
Modifier and Type Method Description protected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voiddoHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)static java.lang.StringencodeURI(java.lang.String string)URI-encode the given string using UTF-8.static java.lang.StringencodeURL(java.lang.String string)URL-encode the given string using UTF-8.protected java.lang.StringgetAttachmentName(javax.servlet.http.HttpServletRequest request, java.io.File file)Returns the file name to be used inContent-Dispositionheader.protected voidhandleNotFound(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Handles the case when the file is not found.static voidsetCacheHeaders(javax.servlet.http.HttpServletResponse response, long expires)Set the cache headers.static voidsetNoCacheHeaders(javax.servlet.http.HttpServletResponse response)Set the no-cache headers.Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
Constructor Details
-
Method Details
-
doHead
protected void doHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException- Overrides:
doHeadin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionjava.io.IOException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionjava.io.IOException
-
handleNotFound
protected void handleNotFound(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOExceptionHandles the case when the file is not found.The default implementation sends a HTTP 404 error.
- Parameters:
request- The involved HTTP servlet request.response- The involved HTTP servlet response.- Throws:
java.io.IOException- When something fails at I/O level.
-
getAttachmentName
protected java.lang.String getAttachmentName(javax.servlet.http.HttpServletRequest request, java.io.File file)Returns the file name to be used inContent-Dispositionheader. This does not need to be URL-encoded as this will be taken care of.The default implementation returns
File.getName().- Parameters:
request- The involved HTTP servlet request.file- The involved file.- Returns:
- The file name to be used in
Content-Dispositionheader.
-
encodeURL
public static java.lang.String encodeURL(java.lang.String string)URL-encode the given string using UTF-8.- Parameters:
string- The string to be URL-encoded using UTF-8.- Returns:
- The given string, URL-encoded using UTF-8, or
nullifnullwas given. - Throws:
java.lang.UnsupportedOperationException- When this platform does not support UTF-8.
-
encodeURI
public static java.lang.String encodeURI(java.lang.String string)URI-encode the given string using UTF-8. URIs (paths and filenames) have different encoding rules as compared to URL query string parameters.URLEncoderis actually only for www (HTML) form based query string parameter values (as used when a webbrowser submits a HTML form). URI encoding has a lot in common with URL encoding, but the space has to be %20 and some chars doesn't necessarily need to be encoded.- Parameters:
string- The string to be URI-encoded using UTF-8.- Returns:
- The given string, URI-encoded using UTF-8, or
nullifnullwas given. - Throws:
java.lang.UnsupportedOperationException- When this platform does not support UTF-8.
-
setCacheHeaders
public static void setCacheHeaders(javax.servlet.http.HttpServletResponse response, long expires)Set the cache headers. If the
expiresargument is larger than 0 seconds, then the following headers will be set:Cache-Control: public,max-age=[expiration time in seconds],must-revalidateExpires: [expiration date of now plus expiration time in seconds]
Else the method will delegate to
setNoCacheHeaders(HttpServletResponse).- Parameters:
response- The HTTP servlet response to set the headers on.expires- The expire time in seconds (not milliseconds!).
-
setNoCacheHeaders
public static void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response)Set the no-cache headers. The following headers will be set:
Cache-Control: no-cache,no-store,must-revalidateExpires: [expiration date of 0]Pragma: no-cache
- Parameters:
response- The HTTP servlet response to set the headers on.
-