01: /*
02: * RegExFilter.java
03: *
04: * Created on 28. August 2003, 22:09
05: */
06:
07: package org.jzonic.jlo.filter;
08:
09: import gnu.regexp.RE;
10: import gnu.regexp.REMatch;
11:
12: import java.util.Map;
13:
14: /**
15: * This is a filter that uses a regular expression to find out
16: * if the given message and the expression matches.
17: *
18: * @author Andreas Mecky andreasmecky@yahoo.de
19: */
20: public class RegExFilter implements LogFilter {
21:
22: private String expression;
23:
24: public RegExFilter() {
25: }
26:
27: public boolean match(String message) {
28: if (message != null && expression != null) {
29: try {
30: RE re = new RE(expression, RE.REG_ICASE);
31: REMatch[] matches = re.getAllMatches(message);
32: if (matches.length > 0) {
33: return true;
34: }
35: } catch (Exception e) {
36: // TODO: do some error reporting
37: }
38: }
39: return false;
40: }
41:
42: public void setParameters(Map parameter) {
43: if (parameter.containsKey("expression")) {
44: expression = (String) parameter.get("expression");
45: }
46: }
47:
48: }
|