KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > matuschek > spider > RegExpRule


1 package net.matuschek.spider;
2
3 /*********************************************
4     Copyright (c) 2001 by Daniel Matuschek
5 *********************************************/

6
7 import org.apache.regexp.RESyntaxException;
8 import org.apache.regexp.RE;
9
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   /**
33    * Sets the value of allow
34    * @param allow true, if this rule allows something, false if it denies
35    * something
36    */

37   public void setAllow(boolean allow) {
38     this.allow = allow;
39   }
40
41
42   /**
43    * Gets the value of processAllowed
44    * @return true, if this rule allows processing, false if it denies it
45    */

46   public boolean getProcessAllowed() {
47     return processAllowed && allow;
48   }
49
50
51   /**
52    * Sets the value of processAllowed
53    * @param processAllowed true, if this rule allows processing, false if it
54    * denies it
55    */

56   public void setProcessAllowed(boolean processAllowed) {
57     this.processAllowed = processAllowed;
58   }
59   
60   /**
61    * Gets the regexp pattern
62    * @return a regular expression that this rule matches
63    */

64   public String JavaDoc getPattern() {
65     return pattern;
66   }
67
68
69   /**
70    * Sets the regexp pattern
71    * @param pattern a regular expression that this rule matches
72    */

73   public void setPattern(String JavaDoc pattern)
74     throws RESyntaxException
75   {
76     this.expression = new RE(pattern);
77     this.pattern = pattern;
78   }
79
80   /**
81    * Does this rule match the given string ?
82    * @param s a String
83    * @return true if the regular expression matches the argument,
84    * false otherwise
85    */

86   public boolean match(String JavaDoc s) {
87     return expression.match(s);
88   }
89
90   private boolean allow=true;
91   private boolean processAllowed=true;
92   private String JavaDoc pattern="";
93   private RE expression=new RE();
94   
95 } // RegExpRule
96
Popular Tags