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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mod.rule;
  2. import net.javacoding.jspider.api.model.*;
  3. import net.javacoding.jspider.core.SpiderContext;
  4. import net.javacoding.jspider.core.rule.impl.BaseRuleImpl;
  5. import net.javacoding.jspider.core.model.DecisionInternal;
  6. import java.net.URL;
  7. /**
  8.  * $Id: TextHtmlMimeTypeOnlyRule.java,v 1.2 2003/05/02 17:36:59 vanrogu Exp $
  9.  */
  10. public class TextHtmlMimeTypeOnlyRule extends BaseRuleImpl {
  11.     public Decision apply(SpiderContext context, Site currentSite, URL url) {
  12.         FetchedResource resource = (FetchedResource)context.getStorage().getResourceDAO().getResource(url);
  13.         String mime = resource.getMime();
  14.         Decision decision = new DecisionInternal(Decision.RULE_IGNORE, "mimetype is '" + mime + "' - resource ignored");
  15.         if ( mime == null ) {
  16.             decision = new DecisionInternal(Decision.RULE_ACCEPT, "mimetype is null - defaulted to text/html - accepted" );
  17.         } else if (mime.toLowerCase().indexOf("text/html") > -1) { // can also contain charset info
  18.             decision = new DecisionInternal(Decision.RULE_ACCEPT, "mimetype is '" + mime + "' - resource accepted");
  19.         }
  20.         return decision;
  21.     }
  22. }