1 24 package org.archive.crawler.framework; 25 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 29 import javax.management.AttributeNotFoundException ; 30 31 import org.archive.crawler.datamodel.CrawlURI; 32 import org.archive.crawler.settings.ComplexType; 33 import org.archive.crawler.settings.MapType; 34 import org.archive.crawler.settings.ModuleType; 35 import org.archive.crawler.settings.SimpleType; 36 37 51 public class Filter extends ModuleType { 52 53 private static final long serialVersionUID = -356718306794776802L; 54 55 private static Logger logger = 56 Logger.getLogger("org.archive.crawler.framework.Filter"); 57 58 public static final String ATTR_ENABLED = "enabled"; 59 60 66 public Filter(String name, String description) { 67 super(name, description); 68 addElementToDefinition( 69 new SimpleType(ATTR_ENABLED, 70 "Filter is enabled.", new Boolean (true))); 71 } 72 73 77 public Filter(String name) { 78 this(name, "Null filter - accepts everything."); 79 } 80 81 public boolean accepts(Object o) { 82 CrawlURI curi = (o instanceof CrawlURI) ? (CrawlURI) o : null; 83 84 try { 86 if (!((Boolean )getAttribute(ATTR_ENABLED, curi)).booleanValue()) { 87 return getFilterOffPosition(curi); 88 } 89 } catch (AttributeNotFoundException e) { 90 logger.severe(e.getMessage()); 91 } 92 93 boolean accept = returnTrueIfMatches(curi) == innerAccepts(o); 94 if (accept && logger.isLoggable(Level.FINEST)) { 95 ComplexType p = this.getParent(); 97 if (p instanceof MapType) { 98 p = p.getParent(); 99 } 100 String msg = this.toString() + " belonging to " + p.toString() 101 + " accepted " + o.toString(); 102 logger.finest(msg); 103 } 104 return accept; 105 } 106 107 116 protected boolean getFilterOffPosition(CrawlURI curi) { 117 return true; 118 } 119 120 134 protected boolean returnTrueIfMatches(CrawlURI curi){ 135 return true; 136 } 137 138 145 protected boolean innerAccepts(Object o) { 146 return true; 147 } 148 149 public String toString() { 150 return "Filter<" + getName() + ">"; 151 } 152 153 public void kickUpdate() { 154 } 156 } 157 | Popular Tags |