Last change
on this file since 7 was
7,
checked in by phdmakk, 14 years ago
|
|
-
Property svn:mime-type set to
text/plain
|
File size:
860 bytes
|
Line | |
---|
1 | package org.etsi.common; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.FileFilter; |
---|
5 | import java.util.regex.Matcher; |
---|
6 | import java.util.regex.Pattern; |
---|
7 | |
---|
8 | public class WildcardFilter implements FileFilter { |
---|
9 | |
---|
10 | private String wildcardRegExp = ""; |
---|
11 | |
---|
12 | public WildcardFilter(File wildcardFile){ |
---|
13 | String wildcardRegExp = wildcardFile.getName(); |
---|
14 | wildcardRegExp = wildcardRegExp.replaceAll("\\.", "\\\\."); |
---|
15 | wildcardRegExp = wildcardRegExp.replaceAll("\\?", "."); |
---|
16 | wildcardRegExp = wildcardRegExp.replaceAll("\\*", ".*"); |
---|
17 | this.wildcardRegExp = wildcardRegExp; |
---|
18 | } |
---|
19 | |
---|
20 | @Override |
---|
21 | public boolean accept(File file) { |
---|
22 | if (file.isFile() || file.isDirectory()){ |
---|
23 | Pattern wildcardPattern = Pattern.compile(this.wildcardRegExp); |
---|
24 | Matcher wildcardMatcher = wildcardPattern.matcher(file.getName()); |
---|
25 | if (wildcardMatcher.matches()) { |
---|
26 | return true; |
---|
27 | } |
---|
28 | } |
---|
29 | return false; |
---|
30 | } |
---|
31 | |
---|
32 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.