Jakarta ORO

org.apache.oro.io
Class RegexFilenameFilter

java.lang.Object
  extended byorg.apache.oro.io.RegexFilenameFilter
All Implemented Interfaces:
java.io.FileFilter, java.io.FilenameFilter
Direct Known Subclasses:
AwkFilenameFilter, GlobFilenameFilter, Perl5FilenameFilter

public class RegexFilenameFilter
extends java.lang.Object
implements java.io.FilenameFilter, java.io.FileFilter

RegexFilenameFilter is the base class for a set of FilenameFilter implementations that filter based on a regular expression. It is also a generic filter implementation that can use any regular expression engine represented by a PatternMatchingEngine.

Since:
1.0
Version:
2.1-dev-1
See Also:
Perl5FilenameFilter, AwkFilenameFilter, GlobFilenameFilter

Constructor Summary
protected RegexFilenameFilter(PatternCache cache, PatternMatcher matcher)
           
protected RegexFilenameFilter(PatternCache cache, PatternMatcher matcher, java.lang.String regex)
           
protected RegexFilenameFilter(PatternCache cache, PatternMatcher matcher, java.lang.String regex, int options)
           
  RegexFilenameFilter(PatternMatchingEngine engine)
          Creates a new RegexFilenameFilter using the supplied PatternMatchingEngine.
  RegexFilenameFilter(java.lang.String engineKey)
          Creates a new RegexFilenameFilter using the supplied engine key to create a PatternMatchingEngine using the PatternMatchingEngineFactory class.
 
Method Summary
 boolean accept(java.io.File pathname)
          Filters a filename.
 boolean accept(java.io.File dir, java.lang.String filename)
          Filters a filename.
 void setFilterExpression(java.lang.String regex)
          Set the regular expression on which to filter.
 void setFilterExpression(java.lang.String regex, int options)
          Set the regular expression on which to filter along with any special options to use when compiling the expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexFilenameFilter

protected RegexFilenameFilter(PatternCache cache,
                              PatternMatcher matcher,
                              java.lang.String regex)

RegexFilenameFilter

protected RegexFilenameFilter(PatternCache cache,
                              PatternMatcher matcher,
                              java.lang.String regex,
                              int options)

RegexFilenameFilter

protected RegexFilenameFilter(PatternCache cache,
                              PatternMatcher matcher)

RegexFilenameFilter

public RegexFilenameFilter(PatternMatchingEngine engine)
Creates a new RegexFilenameFilter using the supplied PatternMatchingEngine.

Parameters:
engine - The PatternMatchingEngine to use for pattern matching.

RegexFilenameFilter

public RegexFilenameFilter(java.lang.String engineKey)
                    throws java.lang.IllegalArgumentException
Creates a new RegexFilenameFilter using the supplied engine key to create a PatternMatchingEngine using the PatternMatchingEngineFactory class.

Parameters:
engineKey - One of the PatternMatchingEngineFactory engine keys.
Throws:
java.lang.IllegalArgumentException
Method Detail

setFilterExpression

public void setFilterExpression(java.lang.String regex)
                         throws MalformedCachePatternException
Set the regular expression on which to filter.

Parameters:
regex - The regular expression on which to filter.
Throws:
MalformedCachePatternException - If there is an error in compiling the regular expression. This need not be caught if you are using a hard-coded expression that you know is correct. But for robustness and reliability you should catch this exception for dynamically entered expressions determined at runtime.

setFilterExpression

public void setFilterExpression(java.lang.String regex,
                                int options)
                         throws MalformedCachePatternException
Set the regular expression on which to filter along with any special options to use when compiling the expression.

Parameters:
regex - The regular expression on which to filter.
options - A set of compilation options specific to the regular expression grammar being used.
Throws:
MalformedCachePatternException - If there is an error in compiling the regular expression. This need not be caught if you are using a hard-coded expression that you know is correct. But for robustness and reliability you should catch this exception for dynamically entered expressions determined at runtime.

accept

public boolean accept(java.io.File dir,
                      java.lang.String filename)
Filters a filename. Tests if the filename EXACTLY matches the pattern contained by the filter. The directory argument is not examined. Conforms to the java.io.FilenameFilter interface.

Specified by:
accept in interface java.io.FilenameFilter
Parameters:
dir - The directory containing the file.
filename - The name of the file.
Returns:
True if the filename EXACTLY matches the pattern, false if not.

accept

public boolean accept(java.io.File pathname)
Filters a filename. Tests if the filename EXACTLY matches the pattern contained by the filter. The filename is defined as pathname.getName(). Conforms to the java.io.FileFilter interface.

Specified by:
accept in interface java.io.FileFilter
Parameters:
pathname - The file pathname.
Returns:
True if the filename EXACTLY matches the pattern, false if not.

Jakarta ORO

Copyright ? 2000-2004 The Apache Software Foundation. All Rights Reserved.