Class FileUploadUtil


  • public class FileUploadUtil
    extends Object
    Utility class for file uploading.
    Author:
    ehugonnet
    • Field Detail

      • DEFAULT_ENCODING

        public static final String DEFAULT_ENCODING
    • Method Detail

      • isRequestMultipart

        public static boolean isRequestMultipart​(javax.servlet.http.HttpServletRequest request)
      • parseRequest

        public static List<org.apache.commons.fileupload.FileItem> parseRequest​(javax.servlet.http.HttpServletRequest request)
        Parses the multipart stream in the specified request to fetch the file items. This method shouldn't be used directly; instead use the HttpRequest instance.
        Parameters:
        request - the HTTP servlet request.
        Returns:
        a list of file items encoded into the multipart stream of the request.
        Throws:
        org.silverpeas.kernel.SilverpeasRuntimeException - if an error occurs while fetching the file items.
      • getParameter

        public static String getParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                          String parameterName,
                                          String defaultValue,
                                          String encoding)
        Get the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
        Parameters:
        items - the items resulting from parsing the request.
        parameterName - name of the parameter.
        defaultValue - the value to be returned if the parameter is not found.
        encoding - the request encoding.
        Returns:
        the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
      • getParameterValues

        public static List<String> getParameterValues​(List<org.apache.commons.fileupload.FileItem> items,
                                                      String parameterName,
                                                      String encoding)
      • getParameter

        public static String getParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                          String parameterName,
                                          String defaultValue)
        Get the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
        Parameters:
        items - the items resulting from parsing the request.
        parameterName - the name of the parameter.
        defaultValue - the value to be returned if the parameter is not found.
        Returns:
        the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
      • getParameter

        public static String getParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                          String parameterName)
        Get the parameter value from the list of FileItems. Returns null if the parameter is not found.
        Parameters:
        items - the items resulting from parsing the request.
        parameterName - the name of the parameter.
        Returns:
        the parameter value from the list of FileItems. Returns null if the parameter is not found.
      • getOldParameter

        public static String getOldParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                             String parameterName)
      • getOldParameter

        public static String getOldParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                             String parameterName,
                                             String defaultValue)
      • getFile

        public static org.apache.commons.fileupload.FileItem getFile​(List<org.apache.commons.fileupload.FileItem> items,
                                                                     String parameterName)
      • getFile

        public static org.apache.commons.fileupload.FileItem getFile​(List<org.apache.commons.fileupload.FileItem> items)
      • getFile

        public static org.apache.commons.fileupload.FileItem getFile​(javax.servlet.http.HttpServletRequest request)
      • getFileName

        public static String getFileName​(org.apache.commons.fileupload.FileItem file)
      • saveToFile

        public static void saveToFile​(File file,
                                      org.apache.commons.fileupload.FileItem item)
                               throws IOException
        Throws:
        IOException