source: trunk/org.etsi.common/src/org/etsi/common/WildcardFilter.java @ 7

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 
1package org.etsi.common;
2
3import java.io.File;
4import java.io.FileFilter;
5import java.util.regex.Matcher;
6import java.util.regex.Pattern;
7
8public 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.