View Javadoc

1   package com.insanityengine.ghia.util;
2   
3   import java.io.File;
4   
5   import java.util.regex.Pattern;
6   import java.util.regex.Matcher;
7   
8   /***
9    *
10   * <P>
11   * </P>
12   *
13   * @author BrianHammond
14   *
15   * $Header: /usr/local/cvsroot/ghia/src/java/com/insanityengine/ghia/util/NameFileFilter.java,v 1.6 2005/03/19 17:50:02 brian Exp $
16   *
17   */
18  
19  public class NameFileFilter implements FileFilter {
20  
21  	public NameFileFilter() {
22  		p = null;
23  	}
24  
25  	public void init( String val ) {
26  		int next, curr = 0;
27  
28  		String pal;
29  
30  		// escape the .
31  		pal = "";
32  		curr = 0;
33  		while ( -1 != ( next = val.indexOf( ".", curr ) ) ) {
34  			pal += val.substring( curr, next ) + "//.";
35  			curr = next + 1;
36  		}
37  		if ( curr < val.length() ) pal += val.substring( curr );
38  
39  		val = pal;
40  
41  		// expand * to .*
42  		pal = "";
43  		curr = 0;
44  		while ( -1 != ( next = val.indexOf( "*", curr ) ) ) {
45  			pal += val.substring( curr, next ) + ".*";
46  			curr = next + 1;
47  		}
48  		if ( curr < val.length() ) pal += val.substring( curr );
49  
50  		p = Pattern.compile( pal );
51  	}
52  
53  	public boolean accept( File f ) {
54  		return ( 
55  			p.matcher(
56  				f.toString().substring(
57  					f.toString().lastIndexOf( File.separator ) + 1
58  				)
59  			).matches()
60  		);
61  	}
62  
63  	public String getName() {
64  		return "NameFileFilter";
65  	}
66  
67  	//
68  
69  	private Pattern p;
70  }
71  
72  /***
73   *
74   * $Log: NameFileFilter.java,v $
75   * Revision 1.6  2005/03/19 17:50:02  brian
76   * repackaging
77   *
78   * Revision 1.5  2004/09/01 01:10:42  brian
79   * fix class level javadoc placement
80   *
81   * Revision 1.4  2004/09/01 00:11:06  brian
82   * author, log and header stuff
83   *
84   * Revision 1.3  2004/08/27 02:52:51  brian
85   * brought the expr more in line with the unix cli and less with posix... is this a good thing or a bad thing? it strives towards the principle of least astonishment
86   *
87   */
88