1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing.filters; |
12 | |
|
13 | |
import org.mule.umo.UMOFilter; |
14 | |
import org.mule.umo.UMOMessage; |
15 | |
|
16 | |
import java.util.regex.Pattern; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class RegExFilter implements UMOFilter, ObjectFilter |
24 | |
{ |
25 | |
private Pattern pattern; |
26 | |
|
27 | |
public RegExFilter() |
28 | |
{ |
29 | 0 | super(); |
30 | 0 | } |
31 | |
|
32 | |
public RegExFilter(String pattern) |
33 | 0 | { |
34 | 0 | this.pattern = Pattern.compile(pattern); |
35 | 0 | } |
36 | |
|
37 | |
public boolean accept(UMOMessage message) |
38 | |
{ |
39 | 0 | return accept(message.getPayload()); |
40 | |
} |
41 | |
|
42 | |
public boolean accept(Object object) |
43 | |
{ |
44 | 0 | if (object == null) |
45 | |
{ |
46 | 0 | return false; |
47 | |
} |
48 | |
|
49 | 0 | return (pattern != null ? pattern.matcher(object.toString()).find() : false); |
50 | |
} |
51 | |
|
52 | |
public String getPattern() |
53 | |
{ |
54 | 0 | return (pattern == null ? null : pattern.pattern()); |
55 | |
} |
56 | |
|
57 | |
public void setPattern(String pattern) |
58 | |
{ |
59 | 0 | this.pattern = (pattern != null ? Pattern.compile(pattern) : null); |
60 | 0 | } |
61 | |
|
62 | |
} |