OnlyDeeperInSiteRule.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 net.javacoding.jspider.core.util.URLUtil;
  8. import java.net.URL;
  9. /**
  10.  * $Id: OnlyDeeperInSiteRule.java,v 1.1 2003/04/03 16:10:52 vanrogu Exp $
  11.  */
  12. public class OnlyDeeperInSiteRule extends BaseRuleImpl {
  13.     public Decision apply(SpiderContext context, Site currentSite, URL url) {
  14.         Decision decision = new DecisionInternal ( Decision.RULE_FORBIDDEN, "url not deeper in site that baseURL" );
  15.         URL baseURL = context.getBaseURL();
  16.         String baseUrlPath = URLUtil.stripResource ( context.getBaseURL().getPath() );
  17.         String urlPath = URLUtil.stripResource ( url.getPath() );
  18.         if ( url.getProtocol().equals(baseURL.getProtocol())) {
  19.             if (url.getPort() == baseURL.getPort()) {
  20.                 if ( urlPath.startsWith(baseUrlPath )) {
  21.                   decision = new DecisionInternal(Decision.RULE_ACCEPT);
  22.                 }
  23.             }
  24.         }
  25.         context.getBaseURL();
  26.         return decision;
  27.     }
  28. }