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:
995 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 ExtensionFilter implements FileFilter { |
---|
9 | |
---|
10 | private String extRegExp = ""; |
---|
11 | |
---|
12 | public ExtensionFilter(String extRegExp) { |
---|
13 | this.extRegExp = extRegExp; |
---|
14 | } |
---|
15 | |
---|
16 | public static String getFileExtension(String filename) { |
---|
17 | String ext = ""; |
---|
18 | new File(filename); |
---|
19 | int i = filename.lastIndexOf('.'); |
---|
20 | if (i > 0 && i < filename.length() - 1) { |
---|
21 | ext = filename.substring(i + 1).toLowerCase(); |
---|
22 | } |
---|
23 | return ext; |
---|
24 | } |
---|
25 | |
---|
26 | public static boolean checkFileExtension(File file, String regExp){ |
---|
27 | Pattern extPattern = Pattern.compile(regExp); |
---|
28 | Matcher extMatcher = extPattern.matcher(getFileExtension(file.getName())); |
---|
29 | if (extMatcher.matches()) { |
---|
30 | return true; |
---|
31 | } |
---|
32 | |
---|
33 | return false; |
---|
34 | } |
---|
35 | |
---|
36 | public boolean accept(File filename) { |
---|
37 | if (filename.isFile()) { |
---|
38 | if (checkFileExtension(filename, this.extRegExp)) { |
---|
39 | return true; |
---|
40 | } |
---|
41 | } |
---|
42 | return false; |
---|
43 | } |
---|
44 | |
---|
45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.