org.xmlhammer.gui.util
Class WildcardFileFilter

java.lang.Object
  extended by org.apache.commons.io.filefilter.AbstractFileFilter
      extended by org.xmlhammer.gui.util.WildcardFileFilter
All Implemented Interfaces:
java.io.FileFilter, java.io.FilenameFilter, org.apache.commons.io.filefilter.IOFileFilter

public class WildcardFileFilter
extends org.apache.commons.io.filefilter.AbstractFileFilter

Filters files using supplied wildcard(s).

See org.apache.commons.io.find.FilenameUtils.wildcardMatch() for wildcard matching rules

e.g.

 File dir = new File(".");
 FileFilter fileFilter = new WildcardFilter("*test*.java~*~");
 File[] files = dir.listFiles(fileFilter);
 for (int i = 0; i < files.length; i++) {
   System.out.println(files[i]);
 }
 

Since:
Commons IO 1.1
Version:
$Revision: 1.4 $ $Date: 2006/09/06 17:48:19 $
Author:
Jason Anderson

Constructor Summary
WildcardFileFilter(java.util.List<java.lang.String> patterns)
          Construct a new wildcard filter for a list of wildcards
WildcardFileFilter(java.lang.String pattern)
          Construct a new wildcard filter for a single wildcard
WildcardFileFilter(java.lang.String[] pattern)
          Construct a new wildcard filter for an array of wildcards
 
Method Summary
 boolean accept(java.io.File file)
          Checks to see if the filename matches one of the wildcards.
 boolean accept(java.io.File dir, java.lang.String name)
          Checks to see if the filename matches one of the wildcards.
(package private) static java.lang.String[] splitOnTokens(java.lang.String text)
           
static boolean wildcardMatch(java.lang.String filename, java.lang.String wildcardMatcher)
          Checks a filename to see if it matches the specified wildcard matcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WildcardFileFilter

public WildcardFileFilter(java.lang.String pattern)
Construct a new wildcard filter for a single wildcard

Parameters:
wildcard - wildcard to match
Throws:
java.lang.IllegalArgumentException - if the pattern is null

WildcardFileFilter

public WildcardFileFilter(java.lang.String[] pattern)
Construct a new wildcard filter for an array of wildcards

Parameters:
wildcards - wildcards to match
Throws:
java.lang.IllegalArgumentException - if the pattern array is null

WildcardFileFilter

public WildcardFileFilter(java.util.List<java.lang.String> patterns)
Construct a new wildcard filter for a list of wildcards

Parameters:
wildcards - list of wildcards to match
Throws:
java.lang.IllegalArgumentException - if the pattern list is null
java.lang.ClassCastException - if the list does not contain Strings
Method Detail

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Checks to see if the filename matches one of the wildcards.

Specified by:
accept in interface java.io.FilenameFilter
Specified by:
accept in interface org.apache.commons.io.filefilter.IOFileFilter
Overrides:
accept in class org.apache.commons.io.filefilter.AbstractFileFilter
Parameters:
dir - the file directory
name - the filename
Returns:
true if the filename matches one of the wildcards

accept

public boolean accept(java.io.File file)
Checks to see if the filename matches one of the wildcards.

Specified by:
accept in interface java.io.FileFilter
Specified by:
accept in interface org.apache.commons.io.filefilter.IOFileFilter
Overrides:
accept in class org.apache.commons.io.filefilter.AbstractFileFilter
Parameters:
file - the file to check
Returns:
true if the filename matches one of the wildcards

wildcardMatch

public static boolean wildcardMatch(java.lang.String filename,
                                    java.lang.String wildcardMatcher)
Checks a filename to see if it matches the specified wildcard matcher.

The wildcard matcher uses the characters '?' and '*' to represent a single or multiple wildcard characters. This is the same as often found on Dos/Unix command lines. The extension check is case sensitive on Unix and case insensitive on Windows.

 wildcardMatch("c.txt", "*.txt")      --> true
 wildcardMatch("c.txt", "*.jpg")      --> false
 wildcardMatch("a/b/c.txt", "a/b/*")  --> true
 wildcardMatch("c.txt", "*.???")      --> true
 wildcardMatch("c.txt", "*.????")     --> false
 

Parameters:
filename - the filename to match on
wildcardMatcher - the wildcard string to match against
Returns:
true if the filename matches the wilcard string

splitOnTokens

static java.lang.String[] splitOnTokens(java.lang.String text)


Copyright 2005-2005-2008 Edwin Dankert. All Rights Reserved.