1 package net.javacoding.jspider.mod.rule; 2 3 import net.javacoding.jspider.core.util.config.PropertySet; 4 import net.javacoding.jspider.core.SpiderContext; 5 import net.javacoding.jspider.core.rule.impl.BaseRuleImpl; 6 import net.javacoding.jspider.core.model.DecisionInternal; 7 import net.javacoding.jspider.api.model.Decision; 8 import net.javacoding.jspider.api.model.Site; 9 10 import java.net.URL ; 11 12 15 public class ForbiddenPathRule extends BaseRuleImpl { 16 17 public static final String PATH = "path"; 18 19 protected String forbiddenPath; 20 21 22 public ForbiddenPathRule(PropertySet config) { 23 forbiddenPath = config.getString(PATH, "/"); 24 } 25 26 33 public Decision apply(SpiderContext context, Site currentSite, URL url) { 34 String path = url.getPath(); 35 Decision decision = new DecisionInternal(); 36 37 if (matches(url, forbiddenPath)) { 38 decision = new DecisionInternal(Decision.RULE_FORBIDDEN, "access to '" + path + "' forbidden"); 39 } 40 return decision; 41 } 42 43 public boolean matches(URL url, String forbiddenPath) { 44 String path = url.getPath(); 45 if (path.length() == 0 && forbiddenPath.equals("/")) { 46 return true; 47 } else { 48 return url.getPath().startsWith(forbiddenPath); 49 } 50 } 51 52 } | Popular Tags |