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
  • Method Summary

    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 session
    static 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 download
    static 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 download
    static 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 download
    static 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 download
    static void
    downloadPluginResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid, String pluginName, String resourcePath, String fileName)
    Downloads a plugin resource
    static String
    getSelfURL(javax.servlet.http.HttpServletRequest request)
    Returns the URL of the current context + current view + query
    static String
    getSelfURLhost(javax.servlet.http.HttpServletRequest request)
    Returns the protocol + the current host + the port (if different than common ports).
    static User
     
    static User
    getSessionUser(javax.servlet.http.HttpServletRequest request)
     
    static void
    sendError(javax.servlet.http.HttpServletResponse response, String message)
     
    static void
    setContentDisposition(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String filename)
    Sets the correct Content-Disposition header into the response
    static void
    uploadDocumentResource(javax.servlet.http.HttpServletRequest request, String docId, String suffix, String fileVersion, String docVersion)
    Uploads a document's related resource.
    static Session
    Throws a runtime exception id the given session is invalid
    static Session
    validateSession(javax.servlet.http.HttpServletRequest request)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • validateSession

      public static Session validateSession(javax.servlet.http.HttpServletRequest request) throws InvalidSessionException
      Throws:
      InvalidSessionException
    • validateSession

      public static Session validateSession(String sid) throws InvalidSessionException
      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

      public static User getSessionUser(String sid) throws InvalidSessionException
      Throws:
      InvalidSessionException
    • checkMenu

      public static Session checkMenu(javax.servlet.http.HttpServletRequest request, long menuId) throws javax.servlet.ServletException, InvalidSessionException
      Throws:
      javax.servlet.ServletException
      InvalidSessionException
    • 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 request
      menuIds - identifiers of the menus
      Returns:
      if at least one of the menus is accessible
      Throws:
      javax.servlet.ServletException - error in the servlet container
      InvalidSessionException - 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 request
      response - server's response
      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
      sid - identifier of the session
      Throws:
      IOException - generic I/O error
      InvalidSessionException - 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 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:
      javax.servlet.ServletException - error in the servlet container
      IOException - generic I/O error
      PersistenceException - 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 request
      response - the file is written to this object
      file - file to serve
      fileName - 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 request
      response - the server's response
      filename - 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 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
    • 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 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
      javax.servlet.ServletException - error in the servlet container
      NumberFormatException - error if docId is not a number
      PersistenceException - 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 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:
      Exception - a generic error
    • sendError

      public static void sendError(javax.servlet.http.HttpServletResponse response, String message)
    • getSelfURLhost

      public static String getSelfURLhost(javax.servlet.http.HttpServletRequest request)
      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

      public static String getSelfURL(javax.servlet.http.HttpServletRequest request)
      Returns the URL of the current context + current view + query
      Parameters:
      request - HttpServletRequest object to be processed
      Returns:
      current context + current view + query