Package com.logicaldoc.web.util
Class ServletUtil
- java.lang.Object
-
- com.logicaldoc.web.util.ServletUtil
-
public class ServletUtil extends Object
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
-
-
Constructor Summary
Constructors Constructor Description ServletUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Session
checkEvenOneMenu(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 Session
checkMenu(javax.servlet.http.HttpServletRequest request, long menuId)
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)
Sends the specified document to the response object; the client will receive it as a downloadstatic void
downloadDocument(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 void
downloadDocumentText(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 void
downloadFile(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 void
downloadPluginResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, String pluginName, String resourcePath, String fileName)
Downloads a plugin resourcestatic void
setContentDisposition(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String filename)
Sets the correct Content-Disposition header into the responsestatic void
uploadDocumentResource(javax.servlet.http.HttpServletRequest request, String docId, String suffix, String fileVersion, String docVersion)
Uploads a document's related resource.static Session
validateSession(javax.servlet.http.HttpServletRequest request)
-
-
-
Method Detail
-
validateSession
public static Session validateSession(javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
- Throws:
javax.servlet.ServletException
-
checkMenu
public static Session checkMenu(javax.servlet.http.HttpServletRequest request, long menuId) throws javax.servlet.ServletException
- Throws:
javax.servlet.ServletException
-
checkEvenOneMenu
public static Session checkEvenOneMenu(javax.servlet.http.HttpServletRequest request, long... menuIds) throws javax.servlet.ServletException
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 container
-
downloadPluginResource
public static void downloadPluginResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, String pluginName, String resourcePath, String fileName) throws FileNotFoundException, IOException, javax.servlet.ServletException, 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:
FileNotFoundException
- cannot find the plugin dirIOException
- generic I/O errorjavax.servlet.ServletException
- error in the servlet containerInvalidSessionException
- the session is unexisting or 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 FileNotFoundException, IOException, javax.servlet.ServletException
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 containerFileNotFoundException
- resource's file not foundIOException
- generic I/O error
-
downloadFile
public static void downloadFile(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, File file, String fileName) throws FileNotFoundException, IOException, javax.servlet.ServletException
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:
FileNotFoundException
- cannot find the file to downloadIOException
- generic I/O errorjavax.servlet.ServletException
- error in the servlet container
-
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 FileNotFoundException, IOException
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:
FileNotFoundException
- cannot find the file to downloadIOException
- generic I/O error
-
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 FileNotFoundException, IOException, NumberFormatException, javax.servlet.ServletException
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:
FileNotFoundException
- the document's file cannot be foundIOException
- generic I/O exception retrieving the document's filejavax.servlet.ServletException
- error in the servlet containerNumberFormatException
- error if docId is not a number
-
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
-
-