1 24 package org.archive.crawler.settings; 25 26 import java.io.Serializable ; 27 import java.util.logging.Level ; 28 29 import org.archive.util.TextUtils; 30 31 37 public class RegularExpressionConstraint 38 extends Constraint implements Serializable { 39 private static final long serialVersionUID = -5916211981136071809L; 40 private final String pattern; 41 42 49 public RegularExpressionConstraint(String pattern, Level level, String msg) { 50 super(level, msg); 51 this.pattern = pattern; 52 } 53 54 61 public RegularExpressionConstraint(String pattern, String msg) { 62 this(pattern, Level.WARNING, msg); 63 } 64 65 72 public RegularExpressionConstraint(String pattern, Level level) { 73 this(pattern, level, "Value did not match pattern: \"" + pattern + "\""); 74 } 75 76 81 public RegularExpressionConstraint(String pattern) { 82 this(pattern, Level.WARNING); 83 } 84 85 91 public FailedCheck innerCheck(CrawlerSettings settings, ComplexType owner, 92 Type definition, Object value) { 93 if (value instanceof CharSequence ) { 94 if (!TextUtils 95 .matches(pattern, (CharSequence ) value)) { 96 return new FailedCheck(settings, owner, definition, value); 97 98 } 99 } else { 100 return new FailedCheck(settings, owner, definition, value, 101 "Can't do regexp on non CharSequence."); 102 } 103 return null; 104 } 105 106 } | Popular Tags |