01: package net.javacoding.jspider.mod.rule;
02:
03: import net.javacoding.jspider.api.model.Decision;
04: import net.javacoding.jspider.api.model.Site;
05: import net.javacoding.jspider.core.SpiderContext;
06: import net.javacoding.jspider.core.rule.impl.BaseRuleImpl;
07: import net.javacoding.jspider.core.model.DecisionInternal;
08: import net.javacoding.jspider.core.util.URLUtil;
09:
10: import java.net.URL;
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,
18: URL url) {
19:
20: Decision decision = new DecisionInternal(
21: Decision.RULE_FORBIDDEN,
22: "url not deeper in site that baseURL");
23:
24: URL baseURL = context.getBaseURL();
25:
26: String baseUrlPath = URLUtil.stripResource(context.getBaseURL()
27: .getPath());
28: String urlPath = URLUtil.stripResource(url.getPath());
29:
30: if (url.getProtocol().equals(baseURL.getProtocol())) {
31: if (url.getPort() == baseURL.getPort()) {
32: if (urlPath.startsWith(baseUrlPath)) {
33: decision = new DecisionInternal(
34: Decision.RULE_ACCEPT);
35: }
36: }
37: }
38:
39: context.getBaseURL();
40:
41: return decision;
42:
43: }
44: }
|