Class FileListGenerator


  • public class FileListGenerator
    extends Object
    Class that can generate a list of files from a supplied directory and optionally, a specified filter. The resulting files and directories are stored in a FileList.
    Version:
    $Revision $
    Author:
    mcayanan
    • Constructor Detail

      • FileListGenerator

        public FileListGenerator()
        Default constructor
    • Method Detail

      • setFilters

        public void setFilters​(List regexp,
                               List noFiles,
                               List noDirs)
        Sets all possible filters when looking in a directory.
        Parameters:
        regexp - File patterns to include when finding files in a directory
        noFiles - File patterns to ignore when finding files in a directory
        noDirs - Directory patterns to ignore when finding sub-directories
      • visitTarget

        public FileList visitTarget​(String target,
                                    boolean getSubDirs)
                             throws IOException,
                                    BadLocationException
        Allows one to pass in a file or URL. Directories will be visited if the target is a directory. The resulting list is stored in a FileList object.
        Parameters:
        getSubDirs - 'true' to look for sub-directories, 'false' to just search for files when given a directory as input
        Returns:
        A FileList object that contains the files and sub-directories
        Throws:
        BadLocationException
        IOException
      • visitDir

        public FileList visitDir​(File dir,
                                 boolean getSubDirs)
                          throws IOException
        Gets a list of files under a given directory. Filters must be set via setFileFilters prior to calling this method in order to look for specific files and filter out un-wanted files and sub-drirectories.
        Parameters:
        dir - the name of the directory
        getSubDirs - 'true' to get a list of sub-directories
        Returns:
        A FileList object containing the files and sub-directories found
        Throws:
        IOException
      • crawl

        public FileList crawl​(URL url,
                              boolean getSubDirURLs)
                       throws IOException,
                              BadLocationException
        Crawls a directory URL, looking for files and sub-directories. Files found in a URL are assumed to end with a ".xxx". Filters must be set via the setFileFilters method prior to crawling in order to look for files and filter out un-wanted files and directories.
        Parameters:
        url - The URL to crawl
        getSubDirURLs - Set to 'true' to retrieve sub-directory URLs, 'false' otherwise
        Returns:
        A FileList object containing the files and sub-directories that were found.
        Throws:
        IOException
        BadLocationException
      • getFileURLNames

        public List getFileURLNames​(URL url,
                                    Set links)
                             throws MalformedURLException
        Finds links to files. This assumes that a file must end in a ".xxx", otherwise it will not be retrieved.
        Parameters:
        url - The location
        links - The Set of files and directories found inside the URL
        Returns:
        a list of file URLs
        Throws:
        MalformedURLException
      • getSubDirURLNames

        public List getSubDirURLNames​(URL url,
                                      Set links)
                               throws MalformedURLException
        Finds links to sub-directory URLs
        Parameters:
        url - The location
        links - The Set of files and directories found inside the URL
        Returns:
        a list of sub directory URLs
        Throws:
        MalformedURLException
      • isLinkFile

        public boolean isLinkFile​(String link)
        Determines if a hyperlink is a file. The rule is that if the name ends with a ".xxx", then it is a file. Otherwise, false is returned.
        Parameters:
        link - The hyperlink name to examine
        Returns:
        'true' if hyperlink contains a 3 character file extension, 'false' otherwise
      • isLinkSubDir

        public boolean isLinkSubDir​(URL url,
                                    String link)
        Determines if a hyperlink is a sub-directory.
        Parameters:
        url - The location
        link - The hyperlink name to examine
        Returns:
        'true' if hyperlink is a sub-directory, 'false' otherwise