try {
if (properties != null && properties.containsKey("minLength"))
min = Integer.parseInt(properties.getProperty("minLength"));
} catch (NumberFormatException nfe) {
log.error("Failed to get minimum value for validator.", nfe);
throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR,
ErrorConstants.CATEGORY_NAME,
ErrorConstants.BUNDLE_NAME,
null,
value);
}
int max = maxLength;
try {
if (properties != null && properties.containsKey("maxLength"))
max = Integer.parseInt(properties.getProperty("maxLength"));
} catch (NumberFormatException nfe) {
log.error("Failed to get maximum value for validator.", nfe);
throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR,
ErrorConstants.CATEGORY_NAME,
ErrorConstants.BUNDLE_NAME,
null,
value);
}
// Validate
if (value.length() < min) {
throw new CoreException(ErrorConstants.ERR_STRING_TOO_SHORT,
ErrorConstants.CATEGORY_NAME,
ErrorConstants.BUNDLE_NAME,
null,
String.valueOf(min),
String.valueOf(max),
value,
null);
}
if (value.length() > max) {
throw new CoreException(ErrorConstants.ERR_STRING_TOO_LONG,
ErrorConstants.CATEGORY_NAME,
ErrorConstants.BUNDLE_NAME,
null,
String.valueOf(min),
String.valueOf(max),
value,
null);
}
// Regular expression
String regExp = properties == null ? this.regExp : Util.trimmedOrBlank(properties.getProperty("regExp", this.regExp));
if (regExp != null && !regExp.equals("") && !value.matches(regExp)) {
throw new CoreException(regExpErrCode,
ErrorConstants.CATEGORY_NAME,
ErrorConstants.BUNDLE_NAME,
null,
String.valueOf(regExp),
value,
null,
null);
}
// Simple pattern
String pattern = Util.trimmedOrBlank(properties == null ? this.pattern : properties.getProperty("pattern", this.pattern));
if (!pattern.equals("")) {
pattern = Util.parseSimplePatternToRegExp(pattern);
if(!value.matches(pattern)) {
throw new CoreException(ErrorConstants.ERR_STRING_DOESNT_MATCH_SIMPLE_PATTERN,
ErrorConstants.CATEGORY_NAME,
ErrorConstants.BUNDLE_NAME,
null,
String.valueOf(pattern),
value,