KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > uni_hamburg > eggink > autojar > OSFilter


1 package de.uni_hamburg.eggink.autojar;
2
3 /* This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License
5  * as published by the Free Software Foundation; either version 2
6  * of the License, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16  *
17  * Bernd.Eggink@rrz.uni-hamburg.de
18  */

19
20 import java.io.*;
21 import java.util.*;
22
23 /** File filter for names with wildcards
24  *
25  * @author Bernd Eggink, RRZ Uni Hamburg (Bernd.Eggink@rrz.uni-hamburg.de)
26  *
27  */

28
29 public class OSFilter
30     implements FilenameFilter
31 {
32     private String JavaDoc expr;
33     private ArrayList excludes;
34
35     //----------------------------------------------------------------------
36

37     /** Contructor
38      *
39      * @param expr File path containing wildcards
40      */

41
42     public OSFilter(String JavaDoc expr)
43     {
44         this.expr = expr;
45     }
46
47     //----------------------------------------------------------------------
48

49     public void setExcludes(ArrayList excludes)
50     {
51         this.excludes = excludes;
52     }
53     
54     //----------------------------------------------------------------------
55

56     public boolean accept(File dir, String JavaDoc path)
57     {
58         boolean ok = Utils.patternMatches(expr, path);
59
60         if (! ok)
61             return false;
62
63         if (excludes != null)
64             for (Iterator it = excludes.iterator(); it.hasNext(); )
65                 if (Utils.patternMatches((String JavaDoc)it.next(), path))
66                     return false;
67
68         return true;
69                     
70 // if (expr == null)
71
// return true;
72
//
73
// int iExpr = 0,
74
// iPath = 0,
75
// lenExpression = expr.length(),
76
// lenPath = path.length();
77
// boolean ok = false;
78
//
79
//loop:
80
// while (iExpr < lenExpression)
81
// {
82
// char charExpr = expr.charAt(iExpr);
83
//
84
// switch (charExpr)
85
// {
86
// case '?':
87
// {
88
// // any character
89
//
90
// if (iPath >= lenPath)
91
// break loop;
92
//
93
// ++iExpr;
94
// ++iPath;
95
// break;
96
// }
97
//
98
// case '*':
99
// {
100
// // character sequence
101
//
102
// int nqu = 0;
103
//
104
// // find normal chars in expr after '*', count '?'s
105
//
106
// while (++iExpr < lenExpression)
107
// {
108
// char c = expr.charAt(iExpr);
109
//
110
// if (c == '?')
111
// ++nqu;
112
// else if (c != '*')
113
// break;
114
// }
115
//
116
// if (iExpr >= lenExpression)
117
// {
118
// // at end, no normal chars after *, just check '?'s
119
//
120
// ok = lenPath - iPath >= nqu;
121
// break loop;
122
// }
123
// else
124
// {
125
// // extract normal part
126
//
127
// int jex = iExpr;
128
//
129
// while (++jex < lenExpression)
130
// {
131
// char c = expr.charAt(jex);
132
//
133
// if (c == '*' || c == '?')
134
// break;
135
// }
136
//
137
// String normal = expr.substring(iExpr, jex);
138
// int ifound = path.indexOf(normal, iPath);
139
//
140
// if (ifound < 0 || ifound - iPath < nqu)
141
// {
142
// // not found in path, or too early
143
//
144
// break loop;
145
// }
146
//
147
// // adjust indices
148
//
149
// iPath = ifound + normal.length();
150
// iExpr = jex;
151
//
152
// break;
153
// }
154
// }
155
//
156
// default:
157
// {
158
// // normal char
159
//
160
// if (iPath >= lenPath || charExpr != path.charAt(iPath))
161
// break loop;
162
//
163
// ++iExpr;
164
// ++iPath;
165
// }
166
// }
167
// }
168
//
169
// if (! ok)
170
// ok = iPath == lenPath;
171
//
172
// return ok;
173
}
174     
175 }
176
177
Popular Tags