BoundedDepthRule.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:2k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mod.rule;
  2. import net.javacoding.jspider.core.rule.impl.BaseRuleImpl;
  3. import net.javacoding.jspider.core.util.config.PropertySet;
  4. import net.javacoding.jspider.core.util.URLUtil;
  5. import net.javacoding.jspider.core.SpiderContext;
  6. import net.javacoding.jspider.core.model.DecisionInternal;
  7. import net.javacoding.jspider.api.model.Decision;
  8. import net.javacoding.jspider.api.model.Site;
  9. import java.net.URL;
  10. /**
  11.  * $Id: BoundedDepthRule.java,v 1.1 2003/04/07 15:50:58 vanrogu Exp $
  12.  */
  13. public class BoundedDepthRule extends BaseRuleImpl {
  14.     public static final String MIN_DEPTH = "depth.min";
  15.     public static final String MAX_DEPTH = "depth.max";
  16.     protected int minDepth;
  17.     protected int maxDepth;
  18.     public BoundedDepthRule(PropertySet config) {
  19.         minDepth = config.getInteger(MIN_DEPTH, 0);
  20.         maxDepth = config.getInteger(MAX_DEPTH, 0);
  21.     }
  22.     public Decision apply(SpiderContext context, Site currentSite, URL url) {
  23.         int depth = URLUtil.getDepth(url);
  24.         Decision decision = null;
  25.         if ( depth < minDepth ) {
  26.             decision = new DecisionInternal ( Decision.RULE_IGNORE, "depth is " + depth + ", lower than minimum " + minDepth);
  27.         } else if ( depth > maxDepth ) {
  28.             decision = new DecisionInternal ( Decision.RULE_IGNORE, "depth is " + depth + ", higher than maximum " + maxDepth);
  29.         } else {
  30.             decision = new DecisionInternal ( Decision.RULE_ACCEPT, "depth is " + depth + ", within boundaries of [" + minDepth + "," + maxDepth + "]");
  31.         }
  32.         return decision;
  33.     }
  34. }