org.clapper.util.io
Class MultipleRegexFilenameFilter

java.lang.Object
  extended by org.clapper.util.io.MultipleRegexFilenameFilter
All Implemented Interfaces:
java.io.FilenameFilter

public class MultipleRegexFilenameFilter
extends java.lang.Object
implements java.io.FilenameFilter

MultipleRegexFilenameFilter implements a java.io.FilenameFilter that matches file names and path names using one or more regular expressions. A MultipleRegexFilenameFilter contains two sets of regular expressions, an accept set and a reject set. To be accepted, a file name must not match any of the patterns in the reject set, and it must match at least one of the patterns in the accept set. If the reject set is empty, then no explicit rejections are done. However, if the accept set is empty, then all files are assumed to be accepted. (i.e., It's as if the accept set contained a single "^.*$" pattern.)

A MultipleRegexFilenameFilter can be configured to operate on just the simple file name, or on the file's path.

MultipleRegexFilenameFilter uses the java.util.regex regular expression classes, so it requires JDK 1.4 or newer.

Version:
$Revision: 6735 $
Author:
Copyright © 2004-2007 Brian M. Clapper
See Also:
CombinationFilenameFilter, CombinationFileFilter

Nested Class Summary
static class MultipleRegexFilenameFilter.MatchType
          Match types
 
Constructor Summary
MultipleRegexFilenameFilter(MultipleRegexFilenameFilter.MatchType matchType)
          Construct a new MultipleRegexFilenameFilter.
 
Method Summary
 boolean accept(java.io.File dir, java.lang.String name)
          Determine whether a file is to be accepted or not, based on the regular expressions in the reject and accept lists.
 void addAcceptPattern(java.lang.String pattern)
          Add an "accept" pattern to this filter.
 void addRejectPattern(java.lang.String pattern)
          Add an "accept" pattern to this filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipleRegexFilenameFilter

public MultipleRegexFilenameFilter(MultipleRegexFilenameFilter.MatchType matchType)
Construct a new MultipleRegexFilenameFilter.

Parameters:
matchType - MatchType.FILENAME to match just the filename, MatchType.PATH to match the path
Method Detail

addAcceptPattern

public void addAcceptPattern(java.lang.String pattern)
                      throws java.util.regex.PatternSyntaxException
Add an "accept" pattern to this filter. For a file to be accepted:

Parameters:
pattern - the regular expression to add
Throws:
java.util.regex.PatternSyntaxException - bad regular expression
See Also:
addRejectPattern(java.lang.String)

addRejectPattern

public void addRejectPattern(java.lang.String pattern)
                      throws java.util.regex.PatternSyntaxException
Add an "accept" pattern to this filter. For a file to be accepted:

Parameters:
pattern - the regular expression to add
Throws:
java.util.regex.PatternSyntaxException - bad regular expression
See Also:
addAcceptPattern(java.lang.String)

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Determine whether a file is to be accepted or not, based on the regular expressions in the reject and accept lists.

Specified by:
accept in interface java.io.FilenameFilter
Parameters:
dir - The directory containing the file. Ignored if the match type is MatchType.FILENAME. Used to build the path to match when the match type is MatchType.PATH
name - the file name
Returns:
true if the file matches, false if it doesn't


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.