org.pf.file
Class ExtendedFileFilter

java.lang.Object
  extended by org.pf.file.ExtendedFileFilter
All Implemented Interfaces:
FilenameFilter

public class ExtendedFileFilter
extends Object
implements FilenameFilter

This filter implements the standard pattern matching on UNIX and Windows platforms. It supports the wildcards '*' and '?' on file names.
It allows to set more than one pattern. Apart from that it allows control over inclusion/exclusion of directories independently from name patterns.

Version:
1.1
Author:
Manfred Duchrow

Field Summary
protected static int DIR_CHECK_NAME
           
protected static int DIR_EXCLUDE
           
protected static int DIR_INCLUDE
           
 
Constructor Summary
ExtendedFileFilter()
          Initialize the new instance with default values.
 
Method Summary
 boolean accept(File dir, String name)
          Tests if a specified file should be included in a file list.
 void addPattern(String pattern)
          Adds a pattern.
 void addPattern(String pattern, boolean ignoreCase)
          Adds a pattern.
 void addPattern(String pattern, boolean ignoreCase, char digitWildcard)
          Adds a pattern.
 void addPattern(String pattern, char digitWildcard)
          Adds a pattern.
 void alwaysExcludeDirectories()
          Sets the filter to never accept directories.
 void alwaysIncludeDirectories()
          Sets the filter to always accept directories, even if they don't match a given pattern.
protected  boolean checkAgainstPatterns(String name)
           
 void checkNameOfDirectories()
          Sets the filter to only accept directories that match a defined pattern.
protected  int getDirHandling()
           
protected  List getStringPatterns()
           
 boolean mustExcludeDirectories()
          Returns true if the filter never accepts directories.
 boolean mustIncludeDirectories()
          Returns true if the filter always accepts directories, even if they don't match a given pattern.
protected  void setDirHandling(int newValue)
           
protected  void setStringPatterns(List newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIR_CHECK_NAME

protected static final int DIR_CHECK_NAME
See Also:
Constant Field Values

DIR_INCLUDE

protected static final int DIR_INCLUDE
See Also:
Constant Field Values

DIR_EXCLUDE

protected static final int DIR_EXCLUDE
See Also:
Constant Field Values
Constructor Detail

ExtendedFileFilter

public ExtendedFileFilter()
Initialize the new instance with default values.

Method Detail

getStringPatterns

protected List getStringPatterns()

setStringPatterns

protected void setStringPatterns(List newValue)

getDirHandling

protected int getDirHandling()

setDirHandling

protected void setDirHandling(int newValue)

addPattern

public void addPattern(String pattern)
Adds a pattern. All filenames match this pattern are acceptable.
Case sensitivity is switched on !

Parameters:
pattern - The pattern string containing optional wildcards ( '*', '?' )

addPattern

public void addPattern(String pattern,
                       char digitWildcard)
Adds a pattern. All filenames match this pattern are acceptable.
Case sensitivity is switched on ! The second parameter specifies a character that will be recognized in the pattern as a placeholder for a single digit character.

A patterb "XX-####.log" with a digitWildcard set to '#' wil match to "XX-2000.log" and "XX-7376.log" but not to "XX-C363.log" and "XX-dddd.log".

Parameters:
pattern - The pattern string containing optional wildcards ( '*', '?' )
digitWildcard - The character that will be treated as wildcard for digits ('0'-'9')

addPattern

public void addPattern(String pattern,
                       boolean ignoreCase)
Adds a pattern. All filenames match this pattern are acceptable.

Parameters:
pattern - The pattern string containing optional wildcards ( '*', '?' )
ignoreCase - If true, all character comparisons are ignoring uppercase/lowercase

addPattern

public void addPattern(String pattern,
                       boolean ignoreCase,
                       char digitWildcard)
Adds a pattern. All filenames that match this pattern are acceptable. Additionally to the standard wildcards '*' and '?' a wildcard for single digit characters ('0' - '9') can be specified here.

Parameters:
pattern - The pattern string containing optional wildcards ( '*', '?' )
ignoreCase - If true, all character comparisons are ignoring uppercase/lowercase
digitWildcard - The character that will be treated as wildcard for digits ('0'-'9')

checkNameOfDirectories

public void checkNameOfDirectories()
Sets the filter to only accept directories that match a defined pattern.


alwaysIncludeDirectories

public void alwaysIncludeDirectories()
Sets the filter to always accept directories, even if they don't match a given pattern.


alwaysExcludeDirectories

public void alwaysExcludeDirectories()
Sets the filter to never accept directories.


accept

public boolean accept(File dir,
                      String name)
Tests if a specified file should be included in a file list.

Specified by:
accept in interface FilenameFilter
Parameters:
dir - the directory in which the file was found.
name - the name of the file.
Returns:
true if and only if the name should be included in the file list, false otherwise.

checkAgainstPatterns

protected boolean checkAgainstPatterns(String name)

mustIncludeDirectories

public boolean mustIncludeDirectories()
Returns true if the filter always accepts directories, even if they don't match a given pattern.


mustExcludeDirectories

public boolean mustExcludeDirectories()
Returns true if the filter never accepts directories.