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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mod.rule;
  2. import net.javacoding.jspider.api.model.Decision;
  3. import net.javacoding.jspider.api.model.Site;
  4. import net.javacoding.jspider.core.SpiderContext;
  5. import net.javacoding.jspider.core.rule.impl.BaseRuleImpl;
  6. import net.javacoding.jspider.core.model.DecisionInternal;
  7. import java.net.URL;
  8. /**
  9.  * Rule implementation that only accepts a resource URL if it is external to
  10.  * the site currently being spidered.
  11.  *
  12.  * $Id: ExternallyReferencedOnlyRule.java,v 1.2 2003/04/25 21:29:06 vanrogu Exp $
  13.  *
  14.  * @author G黱ther Van Roey
  15.  */
  16. public class ExternallyReferencedOnlyRule extends BaseRuleImpl {
  17.     public Decision apply(SpiderContext context, Site currentSite, URL url) {
  18.         if (currentSite == null) {
  19.             return new DecisionInternal(Decision.RULE_DONTCARE);
  20.         } else {
  21.             if (currentSite.getHost().equalsIgnoreCase(url.getHost()) && (currentSite.getPort() == url.getPort())) {
  22.                 return new DecisionInternal(Decision.RULE_IGNORE, "url is within same site - not ignored");
  23.             } else {
  24.                 return new DecisionInternal(Decision.RULE_ACCEPT, "url is accepted because it is referenced from another site");
  25.             }
  26.         }
  27.     }
  28. }