FileDocCategorySizeDatePackage
ExtendedFileFilter.javaAPI DocAzureus 3.0.3.48733Fri Mar 12 11:00:20 GMT 2004org.pf.file

ExtendedFileFilter

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.
author
Manfred Duchrow
version
1.1

Fields Summary
protected static final int
DIR_CHECK_NAME
protected static final int
DIR_INCLUDE
protected static final int
DIR_EXCLUDE
private List
stringPatterns
private int
dirHandling
Constructors Summary
public ExtendedFileFilter()
Initialize the new instance with default values.

  
Methods Summary
public booleanaccept(java.io.File dir, java.lang.String name)
Tests if a specified file should be included in a file list.

param
dir the directory in which the file was found.
param
name the name of the file.
return
true if and only if the name should be included in the file list, false otherwise.

		
		File fileOrDir		= null ;
		
		fileOrDir = new File( dir, name ) ;
		if ( fileOrDir.isDirectory() )
		{
			if ( this.mustIncludeDirectories() )
				return true ;
			if ( this.mustExcludeDirectories() )
				return false ;
		}
		
		return ( this.checkAgainstPatterns( name ) ) ;
	
public voidaddPattern(java.lang.String pattern)
Adds a pattern. All filenames match this pattern are acceptable.
Case sensitivity is switched on !

param
pattern The pattern string containing optional wildcards ( '*', '?' )

		StringPattern stringPattern		= null ;
		
		stringPattern = new StringPattern( pattern, false ) ;
		this.getStringPatterns().add( stringPattern ) ;
	
public voidaddPattern(java.lang.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".

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

		StringPattern stringPattern		= null ;
		
		stringPattern = new StringPattern( pattern, false, digitWildcard ) ;
		this.getStringPatterns().add( stringPattern ) ;
	
public voidaddPattern(java.lang.String pattern, boolean ignoreCase)
Adds a pattern. All filenames match this pattern are acceptable.

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

		StringPattern stringPattern		= null ;
		
		stringPattern = new StringPattern( pattern, ignoreCase ) ;
		this.getStringPatterns().add( stringPattern ) ;
	
public voidaddPattern(java.lang.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.

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

		StringPattern stringPattern		= null ;
		
		stringPattern = new StringPattern( pattern, ignoreCase, digitWildcard ) ;
		this.getStringPatterns().add( stringPattern ) ;
	
public voidalwaysExcludeDirectories()
Sets the filter to never accept directories.

		this.setDirHandling( DIR_EXCLUDE ) ;
	
public voidalwaysIncludeDirectories()
Sets the filter to always accept directories, even if they don't match a given pattern.

		this.setDirHandling( DIR_INCLUDE ) ;
	
protected booleancheckAgainstPatterns(java.lang.String name)

		Iterator iterator			= null ;
		StringPattern pattern	= null ;
		
		iterator = this.getStringPatterns().iterator() ;
		while ( iterator.hasNext() )
		{
			pattern = (StringPattern)iterator.next() ;
			if ( pattern.matches( name ) )
				return true ;
		} // while
		
		return false ; // No pattern matched
	
public voidcheckNameOfDirectories()
Sets the filter to only accept directories that match a defined pattern.

		this.setDirHandling( DIR_CHECK_NAME ) ;
	
protected intgetDirHandling()

      return dirHandling ; 
protected java.util.ListgetStringPatterns()

      return stringPatterns ; 
public booleanmustExcludeDirectories()
Returns true if the filter never accepts directories.

		return ( this.getDirHandling() == DIR_EXCLUDE ) ;
	
public booleanmustIncludeDirectories()
Returns true if the filter always accepts directories, even if they don't match a given pattern.

		return ( this.getDirHandling() == DIR_INCLUDE ) ;
	
protected voidsetDirHandling(int newValue)

 dirHandling = newValue ; 
protected voidsetStringPatterns(java.util.List newValue)

 stringPatterns = newValue ;