KickJava   Java API By Example, From Geeks To Geeks.

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


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

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