01: package net.matuschek.spider;
02:
03: /*********************************************
04: Copyright (c) 2001 by Daniel Matuschek
05: *********************************************/
06:
07: import org.apache.regexp.RESyntaxException;
08: import org.apache.regexp.RE;
09:
10: /**
11: * Simple class that defines a rule based on a regular expression
12: * It consists of a pattern and a action (allow or deny)
13: *
14: * @author Daniel Matuschek
15: * @version $Id $
16: */
17: public class RegExpRule {
18:
19: public RegExpRule() {
20: }
21:
22: /**
23: * Gets the value of allow
24: * @return true, if this rule allows something, false if it denies
25: * something
26: */
27: public boolean getAllow() {
28: return allow;
29: }
30:
31: /**
32: * Sets the value of allow
33: * @param allow true, if this rule allows something, false if it denies
34: * something
35: */
36: public void setAllow(boolean allow) {
37: this .allow = allow;
38: }
39:
40: /**
41: * Gets the value of processAllowed
42: * @return true, if this rule allows processing, false if it denies it
43: */
44: public boolean getProcessAllowed() {
45: return processAllowed && allow;
46: }
47:
48: /**
49: * Sets the value of processAllowed
50: * @param processAllowed true, if this rule allows processing, false if it
51: * denies it
52: */
53: public void setProcessAllowed(boolean processAllowed) {
54: this .processAllowed = processAllowed;
55: }
56:
57: /**
58: * Gets the regexp pattern
59: * @return a regular expression that this rule matches
60: */
61: public String getPattern() {
62: return pattern;
63: }
64:
65: /**
66: * Sets the regexp pattern
67: * @param pattern a regular expression that this rule matches
68: */
69: public void setPattern(String pattern) throws RESyntaxException {
70: this .expression = new RE(pattern);
71: this .pattern = pattern;
72: }
73:
74: /**
75: * Does this rule match the given string ?
76: * @param s a String
77: * @return true if the regular expression matches the argument,
78: * false otherwise
79: */
80: public boolean match(String s) {
81: return expression.match(s);
82: }
83:
84: private boolean allow = true;
85: private boolean processAllowed = true;
86: private String pattern = "";
87: private RE expression = new RE();
88:
89: } // RegExpRule
|