KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > mod > rule > TextHtmlMimeTypeOnlyRule


1 package net.javacoding.jspider.mod.rule;
2
3 import net.javacoding.jspider.api.model.*;
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
8 import java.net.URL JavaDoc;
9
10 /**
11  * $Id: TextHtmlMimeTypeOnlyRule.java,v 1.2 2003/05/02 17:36:59 vanrogu Exp $
12  */

13 public class TextHtmlMimeTypeOnlyRule extends BaseRuleImpl {
14
15     public Decision apply(SpiderContext context, Site currentSite, URL JavaDoc url) {
16         FetchedResource resource = (FetchedResource)context.getStorage().getResourceDAO().getResource(url);
17         String JavaDoc mime = resource.getMime();
18         Decision decision = new DecisionInternal(Decision.RULE_IGNORE, "mimetype is '" + mime + "' - resource ignored");
19
20         if ( mime == null ) {
21             decision = new DecisionInternal(Decision.RULE_ACCEPT, "mimetype is null - defaulted to text/html - accepted" );
22         } else if (mime.toLowerCase().indexOf("text/html") > -1) { // can also contain charset info
23
decision = new DecisionInternal(Decision.RULE_ACCEPT, "mimetype is '" + mime + "' - resource accepted");
24         }
25
26         return decision;
27     }
28 }
29
Popular Tags