org.openbp.common.string.shellmatcher
Class ShellList

java.lang.Object
  extended by org.openbp.common.string.shellmatcher.ShellList

public class ShellList
extends java.lang.Object

The ShellList class can be used to generate a list of files from a UNIX-shell-compatible search pattern. The search pattern may span several directory levels (e. g. "/ usr / src / * / lib* / *.java" - the spaces in the string are there to prevent the compiler from considering this an end of comment, do not insert them in the path in real life).

Author:
Heiko Erhardt

Constructor Summary
ShellList()
          Constructor.
 
Method Summary
 void clearFiles()
          Clears the current file list.
 void expandDirectory(java.lang.String dirName, java.lang.String pattern)
          Find all matching patterns in a directory and add them to the file list.
 void expandPattern(java.lang.String pattern)
          Expands a pattern to a list of files.
 int getFileCount()
          Gets the number of elements of the current file list.
 java.lang.String[] getFiles()
          Gets the current file list.
static void splitPath(java.lang.String path, java.lang.StringBuffer dir, java.lang.StringBuffer pattern, java.lang.StringBuffer remainder)
          Splits the supplied path in directory, pattern and remainder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShellList

public ShellList()
Constructor.

Method Detail

expandPattern

public void expandPattern(java.lang.String pattern)
Expands a pattern to a list of files. The files are added to the current file list.

Parameters:
pattern - The pattern to match the file names against.
For a description of the meta characters that can be used in the pattern, see the ShellMatcher.setPattern(java.lang.String) method.

clearFiles

public void clearFiles()
Clears the current file list.


getFiles

public java.lang.String[] getFiles()
Gets the current file list.

Returns:
An array of file names or null if there were no files found

getFileCount

public int getFileCount()
Gets the number of elements of the current file list.

Returns:
The file count

expandDirectory

public void expandDirectory(java.lang.String dirName,
                            java.lang.String pattern)
Find all matching patterns in a directory and add them to the file list.

Parameters:
dirName - Path name of the directory
pattern - The pattern to match the file names against.
For a description of the meta characters that can be used in the pattern, see the ShellMatcher.setPattern(java.lang.String) method.

splitPath

public static void splitPath(java.lang.String path,
                             java.lang.StringBuffer dir,
                             java.lang.StringBuffer pattern,
                             java.lang.StringBuffer remainder)
Splits the supplied path in directory, pattern and remainder. "/usr/heiko/ * /makefile" -> dir = "/usr/heiko", pattern = "*", remainder = "makefile"
"/usr/heiko/xx/makefile" -> dir = "/usr/heiko/xx/makefile", pattern = "", remainder = ""
"/usr/heiko/xx/ *" -> dir = "/usr/heiko/xx", pattern = "*", remainder = ""
"* /makefile" -> dir = "", pattern = "*", remainder = "makefile"
"xx/ *" -> dir = "xx", pattern = "*", remainder = ""
"*" -> dir = "", pattern = "*", remainder = ""

Parameters:
path - Path name including pattern
dir - String buffer the path name (without the pattern part) is saved in
pattern - String buffer the pattern part is saved in
remainder - String buffer the remainder (after the pattern part) is saved in


Copyright © 2011. All Rights Reserved.