Package com.logicaldoc.web.util
Class ServletUtil
java.lang.Object
com.logicaldoc.web.util.ServletUtil
Some helper utilities to download/upload a document and its resources. The
 downloaded document is also added to the recent files of the user.
- Author:
- Sebastian Stein
- 
Method SummaryModifier and TypeMethodDescriptionstatic SessioncheckEvenOneMenu(jakarta.servlet.http.HttpServletRequest request, long... menuIds) Checks if at least one of the given menus is accessible by the user in the current sessionstatic SessioncheckMenu(jakarta.servlet.http.HttpServletRequest request, long menuId) static voiddownloadDocument(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sid, long docId, String fileVersion, String fileName, User user) Sends the specified document to the response object; the client will receive it as a downloadstatic voiddownloadDocument(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sid, long docId, String fileVersion, String fileName, String suffix, User user) Sends the specified document to the response object; the client will receive it as a downloadstatic voiddownloadDocumentText(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, long docId, User user) Sends the specified document's indexed text to the response object; the client will receive it as a downloadstatic voiddownloadFile(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, File file, String fileName) Sends the specified file to the response object; the client will receive it as a download Sends the specified file to the response object; the client will receive it as a downloadstatic voiddownloadPluginResource(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sid, String pluginName, String resourcePath, String fileName) Downloads a plugin resourcestatic StringgetSelfURL(jakarta.servlet.http.HttpServletRequest request) Returns the URL of the current context + current view + querystatic StringgetSelfURLhost(jakarta.servlet.http.HttpServletRequest request) Returns the protocol + the current host + the port (if different than common ports).static UsergetSessionUser(jakarta.servlet.http.HttpServletRequest request) static UsergetSessionUser(String sid) static voidstatic voidsetContentDisposition(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String filename) Sets the correct Content-Disposition header into the responsestatic voiduploadDocumentResource(jakarta.servlet.http.HttpServletRequest request, long docId, String suffix, String fileVersion, String docVersion) Uploads a document's related resource.static SessionvalidateSession(jakarta.servlet.http.HttpServletRequest request) static SessionvalidateSession(String sid) Throws a runtime exception id the given session is invalid
- 
Method Details- 
validateSessionpublic static Session validateSession(jakarta.servlet.http.HttpServletRequest request) throws InvalidSessionException - Throws:
- InvalidSessionException
 
- 
validateSessionThrows a runtime exception id the given session is invalid- Parameters:
- sid- identifier of the session
- Returns:
- the session
- Throws:
- InvalidSessionException- the session does not exist or is expired
 
- 
getSessionUserpublic static User getSessionUser(jakarta.servlet.http.HttpServletRequest request) throws InvalidSessionException - Throws:
- InvalidSessionException
 
- 
getSessionUser- Throws:
- InvalidSessionException
 
- 
checkMenupublic static Session checkMenu(jakarta.servlet.http.HttpServletRequest request, long menuId) throws jakarta.servlet.ServletException, InvalidSessionException - Throws:
- jakarta.servlet.ServletException
- InvalidSessionException
 
- 
checkEvenOneMenupublic static Session checkEvenOneMenu(jakarta.servlet.http.HttpServletRequest request, long... menuIds) throws jakarta.servlet.ServletException, InvalidSessionException Checks if at least one of the given menus is accessible by the user in the current session- Parameters:
- request- the HTTP request
- menuIds- identifiers of the menus
- Returns:
- if at least one of the menus is accessible
- Throws:
- jakarta.servlet.ServletException- error in the servlet container
- InvalidSessionException- the session is not valid
 
- 
downloadPluginResourcepublic static void downloadPluginResource(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sid, String pluginName, String resourcePath, String fileName) throws IOException, InvalidSessionException Downloads a plugin resource- Parameters:
- request- the HTTP request
- response- server's response
- sid- identifier of the session
- pluginName- name of the plug-in
- resourcePath- Relative path of the plug-in's resource
- fileName- Optional file name to give to the downloaded content
- Throws:
- IOException- generic I/O error
- InvalidSessionException- the session is not valid
 
- 
downloadDocumentpublic static void downloadDocument(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sid, long docId, String fileVersion, String fileName, String suffix, User user) throws IOException, jakarta.servlet.ServletException, PersistenceException Sends the specified document to the response object; the client will receive it as a download- Parameters:
- request- the current request
- response- the document is written to this object
- sid- Session identifier, if not provided the request parameter is inspected
- docId- Id of the document
- fileVersion- name of the file version; if null the latest version will be returned
- fileName- name of the file
- suffix- suffix of the linked document's resource
- user- current user
- Throws:
- jakarta.servlet.ServletException- error in the servlet container
- IOException- generic I/O error
- PersistenceException- error at data layer
 
- 
downloadFilepublic static void downloadFile(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, File file, String fileName) throws IOException Sends the specified file to the response object; the client will receive it as a download Sends the specified file to the response object; the client will receive it as a download- Parameters:
- request- the current request
- response- the file is written to this object
- file- file to serve
- fileName- client file name
- Throws:
- IOException- generic I/O error
 
- 
setContentDispositionpublic static void setContentDisposition(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String filename) throws UnsupportedEncodingException Sets the correct Content-Disposition header into the response- Parameters:
- request- the HTTP request
- response- the server's response
- filename- name of the file
- Throws:
- UnsupportedEncodingException- error trying to encode the response
 
- 
downloadDocumentTextpublic static void downloadDocumentText(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, long docId, User user) throws IOException, PersistenceException Sends the specified document's indexed text to the response object; the client will receive it as a download- Parameters:
- request- the current request
- response- the document is written to this object
- docId- identifier of the document
- user- current user
- Throws:
- IOException- generic I/O error
- PersistenceException- error at database level
 
- 
downloadDocumentpublic static void downloadDocument(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sid, long docId, String fileVersion, String fileName, User user) throws IOException, NumberFormatException, jakarta.servlet.ServletException, PersistenceException Sends the specified document to the response object; the client will receive it as a download- Parameters:
- request- the current request
- response- the document is written to this object
- sid- identifier of the session
- docId- Id of the document
- fileVersion- name of the file version; if null the latest version will be returned
- fileName- name of the file
- user- current user
- Throws:
- IOException- generic I/O exception retrieving the document's file
- jakarta.servlet.ServletException- error in the servlet container
- NumberFormatException- error if docId is not a number
- PersistenceException- error at data layer
 
- 
uploadDocumentResourcepublic static void uploadDocumentResource(jakarta.servlet.http.HttpServletRequest request, long docId, String suffix, String fileVersion, String docVersion) throws PersistenceException, IOException Uploads a document's related resource. The resource will be stored in the folder where the document's files reside using the following pattern: fileVersion-suffix If no version is specified, the current one is used instead- Parameters:
- request- the current request
- docId- Id of the document
- suffix- Suffix of the document
- fileVersion- id of the file version; if null the latest version will returned
- docVersion- id of the doc version; if null the latest version will returned
- Throws:
- PersistenceException- Error in the data layer
- IOException- I/O error during the upload
 
- 
sendError
- 
getSelfURLhostReturns the protocol + the current host + the port (if different than common ports).- Parameters:
- request- HttpServletRequest object to be processed
- Returns:
- the HOST URL
 
- 
getSelfURLReturns the URL of the current context + current view + query- Parameters:
- request- HttpServletRequest object to be processed
- Returns:
- current context + current view + query
 
 
-