Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: rcs/utils/SimpleFileFilter.java


1   package rcs.utils;
2   
3   import java.io.*;
4   import java.util.*;
5   
6   /*
7    *
8    * SimpleFileFilter
9    *
10   */
11  public class SimpleFileFilter implements FilenameFilter
12  {
13    public String pattern;
14    public static boolean debug_on = false;
15  
16    public SimpleFileFilter(String _pattern)
17    {
18      pattern = _pattern;
19    }
20  
21    static public boolean CheckPatternMatch(String word, String pat)
22    {
23      String orig_word = word;
24      StringTokenizer patTokens = new StringTokenizer(pat,"*");
25      if(!pat.startsWith("*") && patTokens.hasMoreTokens())
26      {
27        String start = patTokens.nextToken();
28        if(!word.startsWith(start))
29        {
30          return false;
31        }
32        word=word.substring(start.length());
33      }
34      String token = null;
35      int token_index = -1;
36      while(patTokens.hasMoreTokens())
37      {
38         token = patTokens.nextToken();
39         token_index = word.indexOf(token);
40         if(token_index < 0)
41         {
42           return false;
43         }
44         word = word.substring(token_index+token.length());
45      }
46      if(!pat.endsWith("*") && token != null)
47      {
48        if(!orig_word.endsWith(token))
49        {
50          return false;
51        }
52      }
53      return true;
54    }
55  
56      // Every class implementing FilenameFilter must have
57    // this function.
58    public boolean accept(File  dir, String  name)
59    {
60      boolean retval = CheckPatternMatch(name,pattern);
61      if(debug_on)
62        {
63          System.out.println("SimpleFilenameFilter.accept: "+name+" matches "+pattern+": "+retval);
64        }
65      return retval;
66    }
67  }
68