1 23 package org.archive.crawler.url.canonicalize; 24 25 import java.util.logging.Logger ; 26 import java.util.regex.Matcher ; 27 28 import javax.management.AttributeNotFoundException ; 29 30 import org.archive.crawler.settings.ModuleType; 31 import org.archive.crawler.settings.SimpleType; 32 import org.archive.crawler.url.CanonicalizationRule; 33 34 44 public abstract class BaseRule 45 extends ModuleType 46 implements CanonicalizationRule { 47 private static Logger logger = 48 Logger.getLogger(BaseRule.class.getName()); 49 public static final String ATTR_ENABLED = "enabled"; 50 51 56 public BaseRule(String name, String description) { 57 super(name, description); 58 setExpertSetting(true); 59 setOverrideable(true); 60 Object [] possibleValues = {Boolean.TRUE, Boolean.FALSE}; 61 addElementToDefinition(new SimpleType(ATTR_ENABLED, 62 "Rule is enabled.", new Boolean (true), possibleValues)); 63 } 64 65 public boolean isEnabled(Object context) { 66 boolean result = true; 67 try { 68 Boolean b = (Boolean )getAttribute(context, ATTR_ENABLED); 69 if (b != null) { 70 result = b.booleanValue(); 71 } 72 } catch (AttributeNotFoundException e) { 73 logger.warning("Failed get of 'enabled' attribute."); 74 } 75 76 return result; 77 } 78 79 91 protected String doStripRegexMatch(String url, Matcher matcher) { 92 return (matcher != null && matcher.matches())? 93 checkForNull(matcher.group(1)) + checkForNull(matcher.group(2)): 94 url; 95 } 96 97 101 private String checkForNull(String string) { 102 return (string != null)? string: ""; 103 } 104 } 105 | Popular Tags |