Package gov.nasa.pds.citool.file
Class FileListGenerator
- java.lang.Object
-
- gov.nasa.pds.citool.file.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 Summary
Constructors Constructor Description FileListGenerator()
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileList
crawl(URL url, boolean getSubDirURLs)
Crawls a directory URL, looking for files and sub-directories.List
getFileURLNames(URL url, Set links)
Finds links to files.Set
getHyperLinks(URL url)
Gets hyperlinks found in an HTML document of a URL.List
getSubDirURLNames(URL url, Set links)
Finds links to sub-directory URLsboolean
isLinkFile(String link)
Determines if a hyperlink is a file.boolean
isLinkSubDir(URL url, String link)
Determines if a hyperlink is a sub-directory.void
setFilters(List regexp, List noFiles, List noDirs)
Sets all possible filters when looking in a directory.FileList
visitDir(File dir, boolean getSubDirs)
Gets a list of files under a given directory.FileList
visitTarget(String target, boolean getSubDirs)
Allows one to pass in a file or URL.
-
-
-
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 directorynoFiles
- File patterns to ignore when finding files in a directorynoDirs
- 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 directorygetSubDirs
- '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 crawlgetSubDirURLs
- 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
-
getHyperLinks
public Set getHyperLinks(URL url) throws IOException, BadLocationException, NullPointerException
Gets hyperlinks found in an HTML document of a URL. No duplicate links will be returned.- Parameters:
url
- location- Returns:
- A Set of hyperlinks
- Throws:
IOException
BadLocationException
NullPointerException
-
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 locationlinks
- 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 locationlinks
- 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
-
-