KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.javacoding.jspider.mod.rule;
2
3 import net.javacoding.jspider.api.model.Decision;
4 import net.javacoding.jspider.api.model.Site;
5 import net.javacoding.jspider.core.SpiderContext;
6 import net.javacoding.jspider.core.rule.impl.BaseRuleImpl;
7 import net.javacoding.jspider.core.model.DecisionInternal;
8
9 import java.net.URL JavaDoc;
10
11 /**
12  * Rule implementation that only accepts a resource URL if it is external to
13  * the site currently being spidered.
14  *
15  * $Id: ExternallyReferencedOnlyRule.java,v 1.2 2003/04/25 21:29:06 vanrogu Exp $
16  *
17  * @author Günther Van Roey
18  */

19 public class ExternallyReferencedOnlyRule extends BaseRuleImpl {
20
21     public Decision apply(SpiderContext context, Site currentSite, URL JavaDoc url) {
22         if (currentSite == null) {
23             return new DecisionInternal(Decision.RULE_DONTCARE);
24         } else {
25             if (currentSite.getHost().equalsIgnoreCase(url.getHost()) && (currentSite.getPort() == url.getPort())) {
26                 return new DecisionInternal(Decision.RULE_IGNORE, "url is within same site - not ignored");
27             } else {
28                 return new DecisionInternal(Decision.RULE_ACCEPT, "url is accepted because it is referenced from another site");
29             }
30         }
31     }
32
33 }
34
Popular Tags