1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.file.filters;
12
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
15
16
17
18
19
20
21 public class FilenameRegexFilter extends FilenameWildcardFilter
22 {
23 protected volatile Pattern[] compiledPatterns = null;
24
25
26
27
28
29
30
31
32
33
34
35 public boolean accept(Object object)
36 {
37 if (object == null)
38 {
39 return false;
40 }
41
42 boolean foundMatch = false;
43
44 if (compiledPatterns != null)
45 {
46 for (int i = 0; i < compiledPatterns.length; i++)
47 {
48 Pattern pattern = compiledPatterns[i];
49 String string = object.toString();
50
51
52 Matcher matcher = pattern.matcher(string);
53 foundMatch = matcher.matches();
54
55 if (foundMatch)
56 {
57
58 break;
59 }
60 }
61 }
62
63 return foundMatch;
64 }
65
66
67
68
69
70
71
72 public void setCaseSensitive(boolean caseSensitive)
73 {
74 super.setCaseSensitive(caseSensitive);
75 this.setPattern(pattern);
76 }
77
78
79
80
81
82
83
84 public void setPattern(String pattern)
85 {
86 super.setPattern(pattern);
87
88 if (patterns != null)
89 {
90 compiledPatterns = new Pattern[patterns.length];
91
92 for (int i = 0; i < patterns.length; i++)
93 {
94 if (!isCaseSensitive())
95 {
96
97 compiledPatterns[i] = Pattern.compile(patterns[i], Pattern.CASE_INSENSITIVE);
98 }
99 else
100 {
101 compiledPatterns[i] = Pattern.compile(patterns[i]);
102 }
103 }
104 }
105 }
106
107 }