org.meshcms.util
Class DirectoryParser

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.meshcms.util.DirectoryParser
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
CMSDirectoryFinder, DirectoryCleaner, DirectoryCopier, DirectoryRemover, FileSearch, FolderXTree, SiteMap, SiteSynchronizer, StaticExportCleaner, StaticExportCopier, StaticExporter, ZipArchiver

public class DirectoryParser
extends java.lang.Thread

Base class to perform operations on the contents of a directory.

Override the method preProcessDirectory, postProcessDirectory and processFile to define the actions to be taken for files and directories included in the processed directory. You can also override preProcess and postProcess to do additional operations before and after the directory parsing.

The directory to be parsed must be specified before starting by calling on of the setInitialDir methods. Then you can start the parsing by calling process or asinchronously by creating a new thread and starting it.

Please note that this class is not recursive by default. You must call setRecursive(true) before processing if you want it to process directory contents too.

Author:
Luciano Vernaschi

Field Summary
protected  java.io.File initialDir
           
protected  boolean processStartDir
           
protected  boolean recursive
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DirectoryParser()
           
 
Method Summary
 java.io.File getInitialDir()
          Returns the directory to be processed.
 boolean isProcessStartDir()
          Returns whether processDirectory will be called for the base directory too.
 boolean isRecursive()
          Returns whether directories will be processed recursively or not.
 boolean isSorted()
          Returns whether files and directories will be sorted used a FileNameComparator or not.
protected  void postProcess()
          This method is called at the end of the processing.
protected  void postProcessDirectory(java.io.File file, Path path)
           
protected  boolean preProcess()
          This method is called during the process, but before any element has been processed.
protected  boolean preProcessDirectory(java.io.File file, Path path)
           
 void process()
          Starts processing.
protected  void processFile(java.io.File file, Path path)
          This method will be called for any file found while parsing the base directory.
 void run()
          Starts processing (in a separate thread if instantiated properly).
 void setInitialDir(java.io.File dir)
          Sets the directory to be processed.
 void setInitialDir(java.lang.String dir)
          Sets the directory to be processed.
 void setProcessStartDir(boolean processStartDir)
          If true, processDirectory will be called for the base directory too (default false).
 void setRecursive(boolean recursive)
          If true, directories will be processed recursively (default false).
 void setSorted(boolean sorted)
          If true, files and directories will be sorted used a FileNameComparator.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

initialDir

protected java.io.File initialDir

recursive

protected boolean recursive

processStartDir

protected boolean processStartDir
Constructor Detail

DirectoryParser

public DirectoryParser()
Method Detail

setRecursive

public void setRecursive(boolean recursive)
If true, directories will be processed recursively (default false).

Parameters:
recursive - it the directories will be processed recursively

setProcessStartDir

public void setProcessStartDir(boolean processStartDir)
If true, processDirectory will be called for the base directory too (default false).

Parameters:
processStartDir - if to process the base directory too.
See Also:
#processDirectory

isRecursive

public boolean isRecursive()
Returns whether directories will be processed recursively or not.

See Also:
setRecursive(boolean)

isProcessStartDir

public boolean isProcessStartDir()
Returns whether processDirectory will be called for the base directory too.

See Also:
#processDirectory, setProcessStartDir(boolean)

setSorted

public void setSorted(boolean sorted)
If true, files and directories will be sorted used a FileNameComparator.

See Also:
FileNameComparator

isSorted

public boolean isSorted()
Returns whether files and directories will be sorted used a FileNameComparator or not.

See Also:
FileNameComparator, setSorted(boolean)

setInitialDir

public void setInitialDir(java.lang.String dir)
Sets the directory to be processed. An istance of File is created and setInitialDir(File) is called.

Parameters:
dir - the file path as a String

setInitialDir

public void setInitialDir(java.io.File dir)
Sets the directory to be processed.

Parameters:
dir - the directory path as a File

getInitialDir

public java.io.File getInitialDir()
Returns the directory to be processed.


run

public void run()
Starts processing (in a separate thread if instantiated properly).


process

public void process()
Starts processing.


preProcess

protected boolean preProcess()
This method is called during the process, but before any element has been processed. If it returns false, no processing will take place.

The base implementation does nothing and returns true.

Returns:
always true

postProcess

protected void postProcess()
This method is called at the end of the processing. It is called even if preProcess() returned false.

The base implementation does nothing.


preProcessDirectory

protected boolean preProcessDirectory(java.io.File file,
                                      Path path)

postProcessDirectory

protected void postProcessDirectory(java.io.File file,
                                    Path path)

processFile

protected void processFile(java.io.File file,
                           Path path)
This method will be called for any file found while parsing the base directory.

Parameters:
file - the file to be processed
path - the path of the file (relative to the base directory)