KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > mod > rule > BoundedDepthRule


1 package net.javacoding.jspider.mod.rule;
2
3 import net.javacoding.jspider.core.rule.impl.BaseRuleImpl;
4 import net.javacoding.jspider.core.util.config.PropertySet;
5 import net.javacoding.jspider.core.util.URLUtil;
6 import net.javacoding.jspider.core.SpiderContext;
7 import net.javacoding.jspider.core.model.DecisionInternal;
8 import net.javacoding.jspider.api.model.Decision;
9 import net.javacoding.jspider.api.model.Site;
10
11 import java.net.URL JavaDoc;
12
13 /**
14  * $Id: BoundedDepthRule.java,v 1.1 2003/04/07 15:50:58 vanrogu Exp $
15  */

16 public class BoundedDepthRule extends BaseRuleImpl {
17
18     public static final String JavaDoc MIN_DEPTH = "depth.min";
19     public static final String JavaDoc MAX_DEPTH = "depth.max";
20
21     protected int minDepth;
22     protected int maxDepth;
23
24     public BoundedDepthRule(PropertySet config) {
25         minDepth = config.getInteger(MIN_DEPTH, 0);
26         maxDepth = config.getInteger(MAX_DEPTH, 0);
27     }
28
29     public Decision apply(SpiderContext context, Site currentSite, URL JavaDoc url) {
30         int depth = URLUtil.getDepth(url);
31
32         Decision decision = null;
33
34         if ( depth < minDepth ) {
35             decision = new DecisionInternal ( Decision.RULE_IGNORE, "depth is " + depth + ", lower than minimum " + minDepth);
36         } else if ( depth > maxDepth ) {
37             decision = new DecisionInternal ( Decision.RULE_IGNORE, "depth is " + depth + ", higher than maximum " + maxDepth);
38         } else {
39             decision = new DecisionInternal ( Decision.RULE_ACCEPT, "depth is " + depth + ", within boundaries of [" + minDepth + "," + maxDepth + "]");
40         }
41
42         return decision;
43     }
44
45 }
46
Popular Tags