01: package net.javacoding.jspider.mod.rule;
02:
03: import net.javacoding.jspider.core.rule.impl.BaseRuleImpl;
04: import net.javacoding.jspider.core.util.config.PropertySet;
05: import net.javacoding.jspider.core.util.URLUtil;
06: import net.javacoding.jspider.core.SpiderContext;
07: import net.javacoding.jspider.core.model.DecisionInternal;
08: import net.javacoding.jspider.api.model.Decision;
09: import net.javacoding.jspider.api.model.Site;
10:
11: import java.net.URL;
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 MIN_DEPTH = "depth.min";
19: public static final String 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,
30: URL url) {
31: int depth = URLUtil.getDepth(url);
32:
33: Decision decision = null;
34:
35: if (depth < minDepth) {
36: decision = new DecisionInternal(Decision.RULE_IGNORE,
37: "depth is " + depth + ", lower than minimum "
38: + minDepth);
39: } else if (depth > maxDepth) {
40: decision = new DecisionInternal(Decision.RULE_IGNORE,
41: "depth is " + depth + ", higher than maximum "
42: + maxDepth);
43: } else {
44: decision = new DecisionInternal(Decision.RULE_ACCEPT,
45: "depth is " + depth + ", within boundaries of ["
46: + minDepth + "," + maxDepth + "]");
47: }
48:
49: return decision;
50: }
51:
52: }
|