}
@Override
public boolean validate(String value) {
if (StringUtil.isEmpty(getRegexp())) {
throw new ConfigValidatorException("You must define an attribute called 'regexp' for regexp validator");
}
if (StringUtil.isEmpty(getMode())) {
setMode("contain");
}
if (value == null) {
return true;
}
value = value.trim();
if (StringUtil.isEmpty(value)) {
return true;
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("Validating value with regexp[" + getRegexp() + "]: " + value);
}
Pattern pattern = null;
try {
pattern = new Perl5Compiler().compile(getRegexp(), Perl5Compiler.READ_ONLY_MASK
| Perl5Compiler.SINGLELINE_MASK);
} catch (MalformedPatternException e) {
throw new ConfigValidatorException(e);
}
if (!getMode().endsWith("contain") && !getMode().endsWith("exact") && !getMode().endsWith("prefix")) {
throw new ConfigValidatorException("Invalid regexp mode: " + getMode()
+ ", should be contain, exact or prefix.");
}
// ƥ��
PatternMatcher matcher = new Perl5Matcher();