List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, @Nullable Object[] errorArgs)
From source file:de.fhg.fokus.odp.portal.managedatasets.validator.MetaDataValidator.java
public void validate(Object obj, Errors errors) { MetaDataBean metaData = (MetaDataBean) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-required")); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-required")); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "author", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-required")); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "author_email", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-required")); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "license_id", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-required")); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "date_released", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-required")); if (metaData.getGroups() == null) { errors.rejectValue("groups", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-required")); }/*from ww w .ja va2s . c o m*/ if (!metaData.getUrl().isEmpty() && !ValidationUtilsOc.validUrl(metaData.getUrl())) { errors.rejectValue("url", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-url")); } if (!ValidationUtilsOc.validEmail(metaData.getAuthor_email())) { errors.rejectValue("author_email", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-email")); } if (!ValidationUtilsOc.validPackageName(metaData.getName())) { errors.rejectValue("name", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-name")); } if (!ValidationUtilsOc.validStandardLength(metaData.getAuthor())) { errors.rejectValue("author", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getAuthor_email())) { errors.rejectValue("author_email", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getGeographical_coverage())) { errors.rejectValue("geographical_coverage", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getGeographical_granularity())) { errors.rejectValue("geographical_granularity", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getName())) { errors.rejectValue("name", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getNotes())) { errors.rejectValue("notes", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getOthers())) { errors.rejectValue("others", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getTags())) { errors.rejectValue("tags", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getTemporal_granularity())) { errors.rejectValue("temporal_granularity", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getTitle())) { errors.rejectValue("title", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } if (!ValidationUtilsOc.validStandardLength(metaData.getVersion())) { errors.rejectValue("version", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-too-long")); } String temporal_coverage_from = metaData.getTemporal_coverage_from().trim(); if (!temporal_coverage_from.isEmpty() && !ValidationUtilsOc.validDate(temporal_coverage_from)) { errors.rejectValue("temporal_coverage_from", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-date")); } String temporal_coverage_to = metaData.getTemporal_coverage_to().trim(); if (!temporal_coverage_to.isEmpty() && !ValidationUtilsOc.validDate(temporal_coverage_to)) { errors.rejectValue("temporal_coverage_to", "", LanguageUtil.get(LocaleUtils.getLocale(), "oc_validation-date")); } // for (int i = 0; i <= metaData.getResources().size(); i++) { // Resource resource = metaData.getResources().get(i); // if (!ValidationUtilsOc.validStandardLength(resource // .getDescription())) { // errors.rejectValue("metaData.resources[" + i + "].description", // LanguageUtil.get(LocaleUtils.getLocale(), // "oc_validation-too-long")); // } // // if (!ValidationUtilsOc.validStandardLength(resource.getFormat())) { // errors.rejectValue("metaData.resources[" + i + "].format", // LanguageUtil.get(LocaleUtils.getLocale(), // "oc_validation-too-long")); // } // // if (!ValidationUtilsOc.validStandardLength(resource.getUrl())) { // errors.rejectValue("metaData.resources[" + i + "].url", // LanguageUtil.get(LocaleUtils.getLocale(), // "oc_validation-too-long")); // } // // if (!ValidationUtilsOc.validUrl(resource.getUrl())) { // errors.rejectValue("metaData.resources[" + i + "].url", // LanguageUtil.get(LocaleUtils.getLocale(), // "oc_validation-url")); // } // } }
From source file:sample.contact.AddPermissionValidator.java
public void validate(Object obj, Errors errors) { AddPermission addPermission = (AddPermission) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "permission", "err.permission", "Permission is required. *"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "recipient", "err.recipient", "Recipient is required. *"); if (addPermission.getPermission() != null) { int permission = addPermission.getPermission().intValue(); if ((permission != BasePermission.ADMINISTRATION.getMask()) && (permission != BasePermission.READ.getMask()) && (permission != BasePermission.DELETE.getMask())) { errors.rejectValue("permission", "err.permission.invalid", "The indicated permission is invalid. *"); }/*from w w w.ja v a 2 s . c o m*/ } if (addPermission.getRecipient() != null) { if (addPermission.getRecipient().length() > 100) { errors.rejectValue("recipient", "err.recipient.length", "The recipient is too long (maximum 100 characters). *"); } } }
From source file:com.expedia.weather.model.validator.ForecastFormValidator.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "zip", ForecastFormValidator.ERR_CODE_ZIP_INVALID, ForecastFormValidator.ERR_CODE_ZIP_NOTFOUND); if (!errors.hasErrors()) { ForecastForm form = (ForecastForm) target; if (!Pattern.matches(ForecastFormValidator.US_ZIPCODE_REGEXP, form.getZip())) { errors.rejectValue("zip", ForecastFormValidator.ERR_CODE_ZIP_INVALID, ForecastFormValidator.ERR_CODE_ZIP_INVALID); }/* ww w . j ava 2 s. c om*/ } }
From source file:JavaMvc.web.SignupValidator.java
public void validate(Object o, Errors errors) { SignupCommand command = (SignupCommand) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.username.empty", "Please specify a username."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty", "Please specify an email address."); if (StringUtils.hasText(command.getEmail()) && !Pattern.matches(SIMPLE_EMAIL_REGEX, command.getEmail().toUpperCase())) { errors.rejectValue("email", "error.email.invalid", "Please enter a valid email address."); }//from ww w.j a v a2 s . c o m ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty", "Please specify a password."); }
From source file:JavaMvc.web.EditUserValidator.java
public void validate(Object o, Errors errors) { EditUserCommand command = (EditUserCommand) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.username.empty", "Please specify a username."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty", "Please specify an email address."); if (StringUtils.hasText(command.getEmail()) && !Pattern.matches(SIMPLE_EMAIL_REGEX, command.getEmail().toUpperCase())) { errors.rejectValue("email", "error.email.invalid", "Please enter a valid email address."); }//from w w w.ja va 2s .co m }
From source file:org.opentides.web.validator.CommentValidator.java
@Override public void validate(Object obj, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "text", "error.required", "Text is required."); }
From source file:org.xinta.eazycode.components.shiro.web.validator.SignupValidator.java
public void validate(Object o, Errors errors) { SignupVO command = (SignupVO) o;/* w w w . ja v a2 s . com*/ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginName", "error.username.empty", "Please specify a loginName."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.username.empty", "Please specify a loginName."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty", "Please specify an email address."); if (StringUtils.hasText(command.getEmail()) && !Pattern.matches(SIMPLE_EMAIL_REGEX, command.getEmail().toUpperCase())) { errors.rejectValue("email", "error.email.invalid", "Please enter a valid email address."); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty", "Please specify a password."); }
From source file:org.xinta.eazycode.components.shiro.web.validator.EditUserValidator.java
public void validate(Object o, Errors errors) { EditUserVO command = (EditUserVO) o; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginName", "error.loginName.empty", "Please specify a loginName."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty", "Please specify an email address."); if (StringUtils.hasText(command.getEmail()) && !Pattern.matches(SIMPLE_EMAIL_REGEX, command.getEmail().toUpperCase())) { errors.rejectValue("email", "error.email.invalid", "Please enter a valid email address."); }// w ww . j a va 2 s. co m }
From source file:net.eewiki.user.UserValidator.java
public void validate(Object target, Errors errors) { // Spring uses a little magic here to check the target for its specific attributes. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "field.required", "First name field cannot be empty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "field.required", "Last name field cannot be empty"); }
From source file:com.google.ie.common.validation.AuditValidator.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.USER_KEY, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.ENTITY_KEY, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.ACTION, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.ENTITY_TYPE, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.AUDIT_DATE, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); if (log.isDebugEnabled()) { if (errors.hasErrors()) { log.debug("Validator found " + errors.getErrorCount() + " errors"); for (Iterator<FieldError> iterator = errors.getFieldErrors().iterator(); iterator.hasNext();) { FieldError fieldError = iterator.next(); log.debug("Error found in field: " + fieldError.getField() + " Message :" + fieldError.getDefaultMessage()); }/*from w w w . ja va 2 s . c o m*/ } else { log.debug("Validator found no errors"); } } }