gov.sandia.ccaffeine.dc.user_iface.applet
Class FileSearch

java.lang.Object
  extended by gov.sandia.ccaffeine.dc.user_iface.applet.FileSearch
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class FileSearch
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Search a folder hierarchy for filenames that end with the desired extensions. For example, if the desired filename extensions are {"txt", "text", "htm", "html"} then we will search for files whose names end with .txt, .text, .htm, or .html.

EXAMPLE:
FileSearch x = new FileSearch();
x.setFolderName("c:/myData");
x.setExtension(new String[] {"txt","text","htm","html"});
x.doStart();
String foundFilenames[] = x.getFoundFilenames();

See Also:
Serialized Form

Field Summary
protected  boolean debug
           
protected  java.lang.String[] filenameExtensions
           
protected  java.lang.String folderName
           
protected  java.lang.String[] foundFilenames
           
 
Constructor Summary
FileSearch()
          Construct a new FileSearch object.
 
Method Summary
 java.lang.Object clone()
           
 void doStart()
          Search the target folder for filenames that end with one of the target extensions.
protected  boolean filenameEndsWithOneOfTheseExtensions(java.lang.String filename, java.lang.String[] extensions)
          Return true if the filename ends with one of the extensions in the extensions[] array.
 java.lang.String getFilenameExtension(int index)
          Search for files whose names end with one of these extensions.
 java.lang.String[] getFilenameExtensions()
          Search for files whose names end with these extensions.
 java.lang.String getFolderName()
          Retrieve the name of the folder that we are going to search.
 java.lang.String[] getFoundFilenames()
          Retrieve an array that contains the names of all the files we are searching for.
static void main(java.lang.String[] args)
           
protected  java.lang.String[] searchFolderForFilenamesWithExtensions(java.lang.String folderName, java.lang.String[] extensions)
          Search the input folder (and all subfolders) for filenames with the correct extensions.
protected  java.util.Vector searchFolderForFilenamesWithExtensions(java.lang.String folderName, java.lang.String[] extensions, java.util.Vector namesOfFoundFiles)
          Search the input folder (and all subfolders) for filenames with the correct extensions.
 void setFilenameExtensions(java.lang.String[] filenameExtensions)
          Search for files whose names end with these extensions.
 void setFolderName(java.lang.String folderName)
          Set the name of the folder we are going to search.
 void setFoundFilenames(java.lang.String[] filenames)
          Set the names of all the files that we have found.
 java.lang.String toString()
          Generate some useful info on this object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

protected boolean debug

folderName

protected java.lang.String folderName

filenameExtensions

protected java.lang.String[] filenameExtensions

foundFilenames

protected java.lang.String[] foundFilenames
Constructor Detail

FileSearch

public FileSearch()
Construct a new FileSearch object. You should invoke setFilename(String), setExtensions(String[]), doStart(), and getNode() on your new FileSearch object.

Method Detail

getFoundFilenames

public java.lang.String[] getFoundFilenames()
Retrieve an array that contains the names of all the files we are searching for.

Returns:
The names of all the files we are searching for.

setFoundFilenames

public void setFoundFilenames(java.lang.String[] filenames)
Set the names of all the files that we have found.

Parameters:
filenames - The names of all the files that we have found.

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

getFilenameExtensions

public java.lang.String[] getFilenameExtensions()
Search for files whose names end with these extensions. For example, if the filnemameExtensions contains {"txt", "text", "html", htm"} then we are searching for filenames that end with either ".txt", ".text", ".html", or ".htm".

Returns:
The filename extensions that are we searching for.

getFilenameExtension

public java.lang.String getFilenameExtension(int index)
Search for files whose names end with one of these extensions. For example, if one of filnemameExtensions contains "txt" then we are searching for filenames that end with .txt. NOTE: There may or may not be other filenames that we are searching for. If getFilenameExtension(int index) returns the empty string then we are seaching for all filenames that are in the target folder.

Parameters:
index - Which filename extension do we want to return. The first filename extension has an index value of 0. The 2nd filename extension has an index value of 1. etc.
Returns:
The filename extensions that are we searching for.

setFilenameExtensions

public void setFilenameExtensions(java.lang.String[] filenameExtensions)
Search for files whose names end with these extensions. For example, if the filnemameExtensions contains {"txt", "text", "html", htm"} then we are searching for filenames that end with either ".txt", ".text", ".html", or ".htm".

Parameters:
filenameExtensions - The filename extensions that are we searching for.

getFolderName

public java.lang.String getFolderName()
Retrieve the name of the folder that we are going to search.

Returns:
The name of the folder that will be searched.

setFolderName

public void setFolderName(java.lang.String folderName)
Set the name of the folder we are going to search.

Parameters:
name - The name of the folder we are going to search.

doStart

public void doStart()
Search the target folder for filenames that end with one of the target extensions.


searchFolderForFilenamesWithExtensions

protected java.lang.String[] searchFolderForFilenamesWithExtensions(java.lang.String folderName,
                                                                    java.lang.String[] extensions)
Search the input folder (and all subfolders) for filenames with the correct extensions.

Parameters:
folderName - The name of the folder we are going to search
extensions - A list of all the extensions we are searching for. If a filename ends with one of these extensions then the name of that file will be included in the Vector of filenames that is returned.
Returns:
An array that contains the names of all the files that we have found.

searchFolderForFilenamesWithExtensions

protected java.util.Vector searchFolderForFilenamesWithExtensions(java.lang.String folderName,
                                                                  java.lang.String[] extensions,
                                                                  java.util.Vector namesOfFoundFiles)
Search the input folder (and all subfolders) for filenames with the correct extensions.

Parameters:
folderName - The name of the folder we are going to search
extensions - A list of all the extensions we are searching for. If a filename ends with one of these extensions then the name of that file will be included in the Vector of filenames that is returned.
namesOfFoundFiles - A vector that contains the names of all the files we have already found. If we find any more files with the correct filename extension, then we will add the name of that file to this vector.
Returns:
A vector that contains the names of all the files that we have found.

filenameEndsWithOneOfTheseExtensions

protected boolean filenameEndsWithOneOfTheseExtensions(java.lang.String filename,
                                                       java.lang.String[] extensions)
Return true if the filename ends with one of the extensions in the extensions[] array. If the extensions[] array is empty then return true.

Parameters:
filename -
extensions -
Returns:
True if the filename ends with one of the extensions in the extensions[] array.

toString

public java.lang.String toString()
Generate some useful info on this object.

Overrides:
toString in class java.lang.Object
Returns:
Some useful info on this object.

main

public static void main(java.lang.String[] args)