KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > io > findfile > RegExpFindFile


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.io.findfile;
4
5 import java.io.File JavaDoc;
6 import java.util.regex.Pattern JavaDoc;
7
8 /**
9  * Simple {@link FindFile} that matches file names with regular expression pattern.
10  * @see jodd.io.findfile.WildcardFindFile
11  */

12 public class RegExpFindFile extends FindFile {
13
14     private Pattern JavaDoc regexpPattern;
15
16     public RegExpFindFile(String JavaDoc pattern) {
17         regexpPattern = Pattern.compile(pattern);
18     }
19
20     public RegExpFindFile(String JavaDoc searchPath, String JavaDoc pattern) {
21         regexpPattern = Pattern.compile(pattern);
22         searchPath(searchPath);
23     }
24
25     public RegExpFindFile(File JavaDoc searchPath, String JavaDoc pattern) {
26         regexpPattern = Pattern.compile(pattern);
27         searchPath(searchPath);
28     }
29
30     public RegExpFindFile(String JavaDoc[] searchPath, String JavaDoc pattern) {
31         regexpPattern = Pattern.compile(pattern);
32         searchPath(searchPath);
33     }
34
35     protected boolean onFileEntry(File JavaDoc currentFile) {
36         return regexpPattern.matcher(currentFile.getName()).matches();
37     }
38 }
39
Popular Tags