Class FileUploadUtils


  • public class FileUploadUtils
    extends Object
    Utilities for FileUpload components.
    • Method Detail

      • getValidFilename

        public static String getValidFilename​(String filename)
      • isSystemWindows

        public static boolean isSystemWindows()
      • convertJavaScriptRegex

        protected static String convertJavaScriptRegex​(String jsRegex)
        Converts a JavaScript regular expression like '/(\.|\/)(gif|jpe?g|png)$/i' to the Java usable format '(\\.|\\/)(gif|jpe?g|png)$'
        Parameters:
        jsRegex - the client side JavaScript regex
        Returns:
        the Java converted version of the regex
      • tryValidateFile

        public static void tryValidateFile​(javax.faces.context.FacesContext context,
                                           FileUpload fileUpload,
                                           UploadedFile uploadedFile)
                                    throws javax.faces.validator.ValidatorException
        Throws:
        javax.faces.validator.ValidatorException
      • tryValidateFiles

        public static void tryValidateFiles​(javax.faces.context.FacesContext context,
                                            FileUpload fileUpload,
                                            List<UploadedFile> files)
      • checkPathTraversal

        public static String checkPathTraversal​(String relativePath)
        OWASP prevent directory path traversal of "../../image.png".
        Parameters:
        relativePath - the relative path to check for path traversal
        Returns:
        the relative path
        Throws:
        javax.faces.FacesException - if any error is detected
        See Also:
        https://owasp.org/www-community/attacks/Path_Traversal
      • listChunks

        public static List<Path> listChunks​(Path path)
      • listChunks

        public static <T extends javax.servlet.http.HttpServletRequest> List<Path> listChunks​(T request)
      • getFileUploadChunkDecoder

        public static <T extends javax.servlet.http.HttpServletRequest> FileUploadChunkDecoder<T> getFileUploadChunkDecoder​(T request)
      • getChunkDir

        public static <T extends javax.servlet.http.HttpServletRequest> Path getChunkDir​(T request)