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 ; 11 12 15 public class OnlyDeeperInSiteRule extends BaseRuleImpl { 16 17 public Decision apply(SpiderContext context, Site currentSite, URL url) { 18 19 Decision decision = new DecisionInternal ( Decision.RULE_FORBIDDEN, "url not deeper in site that baseURL" ); 20 21 URL baseURL = context.getBaseURL(); 22 23 String baseUrlPath = URLUtil.stripResource ( context.getBaseURL().getPath() ); 24 String 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 |