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 Summary
Modifier and TypeMethodDescriptionstatic SessioncheckEvenOneMenu(javax.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(javax.servlet.http.HttpServletRequest request, long menuId) static voiddownloadDocument(javax.servlet.http.HttpServletRequest request, javax.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 voiddownloadDocument(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, String docId, String fileVersion, String fileName, User user) Sends the specified document to the response object; the client will receive it as a downloadstatic voiddownloadDocumentText(javax.servlet.http.HttpServletRequest request, javax.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(javax.servlet.http.HttpServletRequest request, javax.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(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, String pluginName, String resourcePath, String fileName) Downloads a plugin resourcestatic StringgetSelfURL(javax.servlet.http.HttpServletRequest request) Returns the URL of the current context + current view + querystatic StringgetSelfURLhost(javax.servlet.http.HttpServletRequest request) Returns the protocol + the current host + the port (if different than common ports).static UsergetSessionUser(String sid) static UsergetSessionUser(javax.servlet.http.HttpServletRequest request) static voidstatic voidsetContentDisposition(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String filename) Sets the correct Content-Disposition header into the responsestatic voiduploadDocumentResource(javax.servlet.http.HttpServletRequest request, String docId, String suffix, String fileVersion, String docVersion) Uploads a document's related resource.static SessionvalidateSession(String sid) Throws a runtime exception id the given session is invalidstatic SessionvalidateSession(javax.servlet.http.HttpServletRequest request)  
- 
Method Details
- 
validateSession
public static Session validateSession(javax.servlet.http.HttpServletRequest request) throws InvalidSessionException - Throws:
 InvalidSessionException
 - 
validateSession
Throws 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
 - 
getSessionUser
public static User getSessionUser(javax.servlet.http.HttpServletRequest request) throws InvalidSessionException - Throws:
 InvalidSessionException
 - 
getSessionUser
- Throws:
 InvalidSessionException
 - 
checkMenu
public static Session checkMenu(javax.servlet.http.HttpServletRequest request, long menuId) throws javax.servlet.ServletException, InvalidSessionException - Throws:
 javax.servlet.ServletExceptionInvalidSessionException
 - 
checkEvenOneMenu
public static Session checkEvenOneMenu(javax.servlet.http.HttpServletRequest request, long... menuIds) throws javax.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 requestmenuIds- identifiers of the menus- Returns:
 - if at least one of the menus is accessible
 - Throws:
 javax.servlet.ServletException- error in the servlet containerInvalidSessionException- the session is not valid
 - 
downloadPluginResource
public static void downloadPluginResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, String pluginName, String resourcePath, String fileName) throws IOException, InvalidSessionException Downloads a plugin resource- Parameters:
 request- the HTTP requestresponse- server's responsepluginName- name of the plug-inresourcePath- Relative path of the plug-in's resourcefileName- Optional file name to give to the downloaded contentsid- identifier of the session- Throws:
 IOException- generic I/O errorInvalidSessionException- the session is not valid
 - 
downloadDocument
public static void downloadDocument(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, long docId, String fileVersion, String fileName, String suffix, User user) throws IOException, javax.servlet.ServletException, PersistenceException Sends the specified document to the response object; the client will receive it as a download- Parameters:
 request- the current requestresponse- the document is written to this objectsid- Session identifier, if not provided the request parameter is inspecteddocId- Id of the documentfileVersion- name of the file version; if null the latest version will be returnedfileName- name of the filesuffix- suffix of the linked document's resourceuser- current user- Throws:
 javax.servlet.ServletException- error in the servlet containerIOException- generic I/O errorPersistenceException- error at data layer
 - 
downloadFile
public static void downloadFile(javax.servlet.http.HttpServletRequest request, javax.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 requestresponse- the file is written to this objectfile- file to servefileName- client file name- Throws:
 IOException- generic I/O error
 - 
setContentDisposition
public static void setContentDisposition(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String filename) throws UnsupportedEncodingException Sets the correct Content-Disposition header into the response- Parameters:
 request- the HTTP requestresponse- the server's responsefilename- name of the file- Throws:
 UnsupportedEncodingException- error trying to encode the response
 - 
downloadDocumentText
public static void downloadDocumentText(javax.servlet.http.HttpServletRequest request, javax.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 requestresponse- the document is written to this objectdocId- identifier of the documentuser- current user- Throws:
 IOException- generic I/O errorPersistenceException- error at database level
 - 
downloadDocument
public static void downloadDocument(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, String docId, String fileVersion, String fileName, User user) throws IOException, NumberFormatException, javax.servlet.ServletException, PersistenceException Sends the specified document to the response object; the client will receive it as a download- Parameters:
 request- the current requestresponse- the document is written to this objectsid- identifier of the sessiondocId- Id of the documentfileVersion- name of the file version; if null the latest version will be returnedfileName- name of the fileuser- current user- Throws:
 IOException- generic I/O exception retrieving the document's filejavax.servlet.ServletException- error in the servlet containerNumberFormatException- error if docId is not a numberPersistenceException- error at data layer
 - 
uploadDocumentResource
public static void uploadDocumentResource(javax.servlet.http.HttpServletRequest request, String docId, String suffix, String fileVersion, String docVersion) throws Exception 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 requestdocId- Id of the documentsuffix- Suffix of the documentfileVersion- id of the file version; if null the latest version will returneddocVersion- id of the doc version; if null the latest version will returned- Throws:
 Exception- a generic error
 - 
sendError
 - 
getSelfURLhost
Returns the protocol + the current host + the port (if different than common ports).- Parameters:
 request- HttpServletRequest object to be processed- Returns:
 - the HOST URL
 
 - 
getSelfURL
Returns the URL of the current context + current view + query- Parameters:
 request- HttpServletRequest object to be processed- Returns:
 - current context + current view + query
 
 
 -