KickJava   Java API By Example, From Geeks To Geeks.

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


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 import net.javacoding.jspider.core.util.URLUtil;
9
10 import java.net.URL JavaDoc;
11
12 /**
13  * $Id: OnlyDeeperInSiteRule.java,v 1.1 2003/04/03 16:10:52 vanrogu Exp $
14  */

15 public class OnlyDeeperInSiteRule extends BaseRuleImpl {
16
17     public Decision apply(SpiderContext context, Site currentSite, URL JavaDoc url) {
18
19         Decision decision = new DecisionInternal ( Decision.RULE_FORBIDDEN, "url not deeper in site that baseURL" );
20
21         URL JavaDoc baseURL = context.getBaseURL();
22
23         String JavaDoc baseUrlPath = URLUtil.stripResource ( context.getBaseURL().getPath() );
24         String JavaDoc urlPath = URLUtil.stripResource ( url.getPath() );
25
26         if ( url.getProtocol().equals(baseURL.getProtocol())) {
27             if (url.getPort() == baseURL.getPort()) {
28                 if ( urlPath.startsWith(baseUrlPath )) {
29                   decision = new DecisionInternal(Decision.RULE_ACCEPT);
30                 }
31             }
32         }
33
34
35         context.getBaseURL();
36
37         return decision;
38
39     }
40 }
41
Popular Tags