Java 类org.springframework.validation.ValidationUtils 实例源码

项目:SpringTutorial    文件:LogonValidator.java   
@Override
public void validate(Object target, Errors errors) {
    System.out.println("validate(Object target, Errors errors) ");

    System.out.println(target);

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId",
        "required.userName", "Field name is required.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
        "required.password", "Field name is required.");

    System.out.println("validate() : - "+errors);

    Logon logon = (Logon)target;
    if(logon.getPassword()!=null && !(logon.getPassword().equals(logon.getUserId()+"111"))){
        errors.rejectValue("password", "invalid.logon");
        System.out.println("rejected");
    }
    }
项目:SpringTutorial    文件:LogonValidator.java   
@Override
public void validate(Object target, Errors errors) {
    System.out.println("Entered : validate(Object target, Errors errors) ");

    System.out.println("target : " + target);

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId",
            "required.userName", "Field name is required.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
            "required.password", "Field name is required.");
    Logon logon = (Logon) target;

    if("blank".equals(logon.getUserRole())){
        errors.rejectValue("userRole", "required.role");
    }

    if(logon.getDaysCount()==null){
        errors.rejectValue("daysCount", "required.dayscount");
    }

    if (logon.getPassword() != null
            && !(logon.getPassword().equals(logon.getUserId() + "111"))) {
        errors.rejectValue("password", "invalid.logon");
    }
    System.out.println("validate() : - " + errors);
}
项目:amv-access-api-poc    文件:UserValidator.java   
@Override
public void validate(Object o, Errors errors) {
    UserEntity user = (UserEntity) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
    if (user.getName().length() < 3 || user.getName().length() > 32) {
        errors.rejectValue("username", "Size.userForm.username");
    }
    if (userRepository.findByName(user.getName(), firstPageSingleItemRequest).hasContent()) {
        errors.rejectValue("username", "Duplicate.userForm.username");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
    if (user.getPassword().length() < 3) {
        errors.rejectValue("password", "Size.userForm.password");
    }
}
项目:timesheet-upload    文件:UpdatePasswordValidator.java   
@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "employeeFirstName", "NotEmpty.registration.fname");
    Employee employeeRegistration = (Employee) target;

    if (StringUtils.isNotBlank(employeeRegistration.getEmpPassword())) {
        if (passwordValidator.validate(employeeRegistration.getEmpPassword())) {
            //Check if the confirmation password is same as the new password.
            if (!StringUtils.equalsIgnoreCase(employeeRegistration.getEmpPassword(), employeeRegistration.getEmpPassword2())) {
                errors.rejectValue("empPassword2", "NotValid.registration.confirm.password");
            }
        } else {
            errors.rejectValue("empPassword", "NotValid.registration.password");
        }
    }

}
项目:nixmash-blog    文件:SiteOptionTests.java   
@Test
public void SiteOptionMapDtoValidationTests() {

    SiteOptionMapDTO siteOptionMapDTO = SiteOptionMapDTO.withGeneralSettings(
            null,
            siteOptions.getSiteDescription(),
            siteOptions.getAddGoogleAnalytics(),
            siteOptions.getGoogleAnalyticsTrackingId(),
            siteOptions.getUserRegistration())
            .build();

    Errors errors = new BeanPropertyBindingResult(siteOptionMapDTO, "siteOptionMapDTO");
    ValidationUtils.invokeValidator(new SiteOptionMapDtoValidator(), siteOptionMapDTO, errors);
    assertTrue(errors.hasFieldErrors("siteName"));
    assertEquals("EMPTY", errors.getFieldError("siteName").getCode());

}
项目:SmartSync    文件:WeatherValidator.java   
@Override
public void validate(Object object, Errors errors) {

    WeatherLocationDTO weatherLocationDTO = (WeatherLocationDTO) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
            "User Id must not be empty");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "city", "field.required",
            "City must not be empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "state", "field.required",
            "State must not be empty");

    if(!errors.hasErrors()) {
        if(weatherLocationDTO.getState().length() != 2) {
            errors.rejectValue("state", "filed.invalid",
                    "State must be length 2. Did you forget to use state code?");
        }

    }


}
项目:SmartSync    文件:UpdateTaskValidator.java   
@Override
public void validate(Object o, Errors errors) {

    UpdateTaskDTO updateTaskDTO = (UpdateTaskDTO) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskId", "field.required",
            "User Id must not be empty.");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "field.required", "" +
            "Description must not be empty.");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dueDate", "field.required",
            "Due Date must not be empty");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isCompleted", "field.required",
            "Is Completed must not be empty");
}
项目:SmartSync    文件:UpdateServiceValidator.java   
/**
 * Validates the input
 * @param object the user to validate
 * @param errors the errors
 */
public void validate(Object object, Errors errors) {

    UpdateServiceDTO user = (UpdateServiceDTO) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "field.required",
            "Service name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "field.required",
            "Service description must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isActive", "field.required",
            "Service isActive must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "wide", "field.required",
            "Service wide must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "tall", "field.required",
            "Service tall must not be empty.");


}
项目:SmartSync    文件:ServiceValidator.java   
/**
 * Validates the input
 * @param object the user to validate
 * @param errors the errors
 */
public void validate(Object object, Errors errors) {

    ServiceDTO user = (ServiceDTO) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "field.required",
            "Service name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "field.required",
            "Service description must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isActive", "field.required",
            "Service isActive must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "wide", "field.required",
            "Service wide must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "tall", "field.required",
            "Service tall must not be empty.");


}
项目:SmartSync    文件:UserValidator.java   
/**
 * Validates the input
 * @param object the user to validate
 * @param errors the errors
 */
public void validate(Object object, Errors errors) {

    UserDTO user = (UserDTO) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
            "googleId must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
            "User Full Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
            "User Given Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
            "User Family Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
            "User Image URL must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
            "User Email must not be empty");
    ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
            "User Role must not be empty.");

    // doing specific input validaiton, so we need to make sure all of the fields are there
    if(!errors.hasErrors()) {
        if(user.getRole() < 0 || user.getRole() > 1) {
            errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
        }

        if(!EmailValidator.getInstance().isValid(user.getEmail())) {
            errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
        }

        if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
            errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
        }
    }



}
项目:SmartSync    文件:UpdateUserValidator.java   
@Override
public void validate(Object o, Errors errors) {
    UpdateUserDTO user = (UpdateUserDTO) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
            "User Id must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
            "googleId must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
            "User Full Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
            "User Given Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
            "User Family Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
            "User Image URL must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
            "User Email must not be empty");
    ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
            "User Role must not be empty.");

    // doing specific input validaiton, so we need to make sure all of the fields are there
    if(!errors.hasErrors()) {
        if(user.getRole() < 0 || user.getRole() > 1) {
            errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
        }

        if(!EmailValidator.getInstance().isValid(user.getEmail())) {
            errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
        }

        if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
            errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
        }
    }
}
项目:SmartSync    文件:UserPreferencesValidator.java   
@Override
public void validate(Object o, Errors errors) {
    UserPreferencesDTO userPreferencesDTO = (UserPreferencesDTO) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
            "User Id must not be empty.");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "field.required",
            "Name must not be empty");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "primaryColor", "field.required",
            "Primary Color must not be empty");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "secondaryColor", "field.required",
            "Secondary Color must not be empty");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accentColor", "field.required",
            "Accent Color must not be empty");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "neutralLightColor", "field.required",
            "Neutral Light Color must not be empty");


    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "neutralDarkColor", "field.required",
            "Neutral Dark Color must not be empty");
}
项目:QRcode-factory    文件:UserValidator.java   
/** {@inheritDoc} */
@Override
public void validate(final Object o, Errors errors) {
    User user = (User) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
    if (user.getUsername().length() < ValidationConstants.MIN_USERNAME_LENGTH ||
            user.getUsername().length() > ValidationConstants.MAX_USERNAME_LENGTH) {
        errors.rejectValue("username", "Size.userForm.username");
    }
    if (userService.findByUsername(user.getUsername()).isPresent()) {
        errors.rejectValue("username", "Duplicate.userForm.username");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
    if (user.getPassword().length() < ValidationConstants.MIN_PASSWORD_LENGTH) {
        errors.rejectValue("password", "Size.userForm.password");
    }

    if (!user.getPasswordConfirm().equals(user.getPassword())) {
        errors.rejectValue("passwordConfirm", "Diff.userForm.passwordConfirm");
    }
}
项目:Restaurant    文件:CustomerInfoValidator.java   
public void validate(Object target, Errors errors) {
    CustomerInfo custInfo = (CustomerInfo) target;

       ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fName", "NotEmpty.customerForm.fName");
       ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lName", "NotEmpty.customerForm.lName");
       ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "NotEmpty.customerForm.email");
       ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address", "NotEmpty.customerForm.address");
       ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "NotEmpty.customerForm.phone");



       if(!errors.hasErrors() && custInfo.getPhone().length()!=10){
        errors.rejectValue("phone","Length.greater.phone");
       }

       if(!errors.hasErrors() && custInfo.getPhone().contains("[0-9]+")){
        errors.rejectValue("phone","NoCharacater.cusomerForm.phone");
       }


       if (!errors.hasErrors() && !emailValidator.isValid(custInfo.getEmail())) {
           errors.rejectValue("email", "NotValid.customer.email");
       }
}
项目:Learning-Spring-5.0    文件:BookValidator2.java   
@Override
public void validate(Object obj, Errors errors) {
    // TODO Auto-generated method stub
    Book book = (Book) obj;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bookName", "bookName.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "author", "authorName.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "description.required");

    if (book.getDescription().length() < 10 || book.getDescription().length() < 40) {
        errors.rejectValue("description", "description.length",
                "Please enter description within 40 charaters only");
    }

    if (book.getISBN() <= 150l) {
        errors.rejectValue("ISBN", "ISBN.required", "Please Enter Correct ISBN number");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "price", "price.incorrect");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "publication", "publication.required");

}
项目:Learning-Spring-5.0    文件:BookValidator2.java   
@Override
public void validate(Object obj, Errors errors) {
    // TODO Auto-generated method stub
    Book book = (Book) obj;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bookName", "bookName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "author", "authorName.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "description.required");

    if (book.getDescription().length() < 10 || book.getDescription().length() > 40) {
        errors.rejectValue("description", "description.length",
                "Please enter description within 40 charaters only");
    }

    if (book.getISBN() <= 150l) {
        errors.rejectValue("ISBN", "ISBN.required", "Please Enter Correct ISBN number");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "price", "price.incorrect");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "publication", "publication.required");

}
项目:web-framework-for-java    文件:UserValidator.java   
@Override
    public void validate(Object o, Errors errors) {
        User user = (User) o;

        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
//        if (user.getUsername().length() < 6 || user.getUsername().length() > 32) {
//            errors.rejectValue("username", "Size.userForm.username");
//        }
        if (userService.findByUsername(user.getUsername()) != null) {
            errors.rejectValue("username", "Duplicate.userForm.username");
        }

        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
//        if (user.getPassword().length() < 8 || user.getPassword().length() > 32) {
//            errors.rejectValue("password", "Size.userForm.password");
//        }

        if (!user.getPasswordConfirm().equals(user.getPassword())) {
            errors.rejectValue("passwordConfirm", "Diff.userForm.passwordConfirm");
        }
    }
项目:registration-login-spring-xml-maven-jsp-mysql    文件:UserValidator.java   
@Override
public void validate(Object o, Errors errors) {
    User user = (User) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
    if (user.getUsername().length() < 6 || user.getUsername().length() > 32) {
        errors.rejectValue("username", "Size.userForm.username");
    }
    if (userService.findByUsername(user.getUsername()) != null) {
        errors.rejectValue("username", "Duplicate.userForm.username");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
    if (user.getPassword().length() < 8 || user.getPassword().length() > 32) {
        errors.rejectValue("password", "Size.userForm.password");
    }

    if (!user.getPasswordConfirm().equals(user.getPassword())) {
        errors.rejectValue("passwordConfirm", "Diff.userForm.passwordConfirm");
    }
}
项目:helium    文件:ReassignacioUsuarisValidatorHelper.java   
public void validate(Object target, Errors errors) {
    Date avui = new Date();
    ReassignacioUsuarisCommand command = (ReassignacioUsuarisCommand)target;
    ValidationUtils.rejectIfEmpty(errors, "usuariOrigen", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "usuariDesti", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "dataInici", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "dataFi", "not.blank");
    if ((command.getDataInici() != null) && (avui.compareTo(command.getDataInici()) > 0)) {
        errors.rejectValue("dataInici", "error.data.anterior");
    }
    if ((command.getDataFi() != null) && (avui.compareTo(command.getDataFi()) > 0)) {
        errors.rejectValue("dataFi", "error.data.anterior");
    }
    if ((command.getDataInici() != null) && (command.getDataFi() != null) && ((command.getDataFi()).compareTo(command.getDataInici()) < 0)) {
        errors.rejectValue("dataFi", "error.dataFi.anterior");
    }
}
项目:helium    文件:DominiController.java   
public void validate(Object target, Errors errors) {
    Domini domini = (Domini)target;
    if (domini.getTipus()!=null) {
        if (domini.getTipus().equals(TipusDomini.CONSULTA_WS)) {
            ValidationUtils.rejectIfEmpty(errors, "url", "not.blank");
            if (!TipusAuthDomini.NONE.equals(domini.getTipusAuth())) {
                ValidationUtils.rejectIfEmpty(errors, "usuari", "not.blank");
                ValidationUtils.rejectIfEmpty(errors, "contrasenya", "not.blank");
            }
        }
        if (domini.getTipus().equals(TipusDomini.CONSULTA_SQL)) {
            ValidationUtils.rejectIfEmpty(errors, "jndiDatasource", "not.blank");
            ValidationUtils.rejectIfEmpty(errors, "sql", "not.blank");
        }
    }
}
项目:helium    文件:ExpedientTipusSistraVariablesController.java   
public void validate(Object target, Errors errors) {
    MapeigSistra command = (MapeigSistra)target;
    ValidationUtils.rejectIfEmpty(errors, "codiHelium", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "codiSistra", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "tipus", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "expedientTipus", "not.blank");


    if (command.getCodiHelium() != null && !("".equalsIgnoreCase(command.getCodiHelium())) && command.getExpedientTipus() != null) {    
        MapeigSistra repetits = dissenyService.findMapeigSistraAmbExpedientTipusICodi(command.getExpedientTipus().getId(), command.getCodiHelium());
        if (repetits != null) {
            errors.rejectValue("codiHelium", "error.expedienttipus.sistra.mapeig.repetit");
        }
    }
    if (command.getCodiHelium().length() > 255) 
        errors.rejectValue("codiHelium", "max.length");
    if (command.getCodiSistra().length() > 255) 
        errors.rejectValue("codiSistra", "max.length");
}
项目:helium    文件:PersonaController.java   
public void validate(Object target, Errors errors) {
    PersonaUsuariCommand command = (PersonaUsuariCommand)target;
    // El codi d'usuari no pot estar repetit
    Persona repetida = personaService.findPersonaAmbCodi(command.getCodi());
    if (repetida != null && !repetida.getId().equals(command.getId())) {
        errors.rejectValue("codi", "error.persona.codi.repetit");
    }
    // Si l'usuari pot fer login la contrasenya i la repetició són obligatoris
    if (command.isLogin() && command.getId() == null) {
        ValidationUtils.rejectIfEmpty(errors, "contrasenya", "not.blank");
        ValidationUtils.rejectIfEmpty(errors, "repeticio", "not.blank");
    }
    // La contrasenya i la repetició han de coincidir
    if (command.getContrasenya() != null) {
        if (command.getRepeticio() == null || !command.getRepeticio().equals(command.getContrasenya())) {
            errors.rejectValue("contrasenya", "error.contrasenya.repeticio");
            errors.rejectValue("repeticio", "error.contrasenya.repeticio");
        }
    }
}
项目:helium    文件:ReassignacioController.java   
public void validate(Object target, Errors errors) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date avui = cal.getTime();

    ReassignacioCommand command = (ReassignacioCommand)target;
    ValidationUtils.rejectIfEmpty(errors, "usuariOrigen", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "usuariDesti", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "dataInici", "not.blank");
    ValidationUtils.rejectIfEmpty(errors, "dataFi", "not.blank");
    if ((command.getDataInici() != null) && (avui.compareTo(command.getDataInici()) > 0)) {
        errors.rejectValue("dataInici", "error.data.anterior");
    }
    if ((command.getDataFi() != null) && (avui.compareTo(command.getDataFi()) > 0)) {
        errors.rejectValue("dataFi", "error.data.anterior");
    }
    if ((command.getDataInici() != null) && (command.getDataFi() != null) && ((command.getDataFi()).compareTo(command.getDataInici()) < 0)) {
        errors.rejectValue("dataFi", "error.dataFi.anterior");
    }
}
项目:helium    文件:ExpedientTipusDominisController.java   
public void validate(Object target, Errors errors) {
    Domini domini = (Domini)target;
    if (domini.getTipus()!=null) {
        if (domini.getTipus().equals(TipusDomini.CONSULTA_WS)) {
            ValidationUtils.rejectIfEmpty(errors, "url", "not.blank");
            if (!TipusAuthDomini.NONE.equals(domini.getTipusAuth())) {
                ValidationUtils.rejectIfEmpty(errors, "usuari", "not.blank");
                ValidationUtils.rejectIfEmpty(errors, "contrasenya", "not.blank");
            }
        }
        if (domini.getTipus().equals(TipusDomini.CONSULTA_SQL)) {
            ValidationUtils.rejectIfEmpty(errors, "jndiDatasource", "not.blank");
            ValidationUtils.rejectIfEmpty(errors, "sql", "not.blank");
        }
    }
}
项目:Spring-MVC-Blueprints    文件:IndexValidator.java   
@Override
public void validate(Object obj, Errors errors) {
    Home homeForm = (Home) obj;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "message",
            "message.empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "quote",
            "quote.empty");

    if (homeForm.getMessage().length() > 500) {
        errors.rejectValue("message", "message.maxlength");
    }
    if (homeForm.getMessage().length() < 50) {
        errors.rejectValue("message", "message.minlength");
    }

    if (homeForm.getQuote().length() > 500) {
        errors.rejectValue("quote", "quote.maxlength");
    }
    if (homeForm.getQuote().length() < 50) {
        errors.rejectValue("quote", "quote.minlength");
    }
}
项目:otinane    文件:UserValidator.java   
@Override
public void validate(Object o, Errors errors) {
    User user = (User) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
    if (user.getUsername().length() < 6 || user.getUsername().length() > 32) {
        errors.rejectValue("username", "Size.userForm.username");
    }
    if (userService.findByUsername(user.getUsername()) != null) {
        errors.rejectValue("username", "Duplicate.userForm.username");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
    if (user.getPassword().length() < 8 || user.getPassword().length() > 32) {
        errors.rejectValue("password", "Size.userForm.password");
    }

    if (!user.getPasswordConfirm().equals(user.getPassword())) {
        errors.rejectValue("passwordConfirm", "Diff.userForm.passwordConfirm");
    }
}
项目:coj-web    文件:WbContestValidator.java   
@Override
public void validate(Object o, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "wbsite.error.empty", "wboard.error.empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "startDate", "wbsite.error.empty", "Field empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "endDate", "wbsite.error.empty", "Field empty");

    if (((WbContest) o).getStartDate() != null && ((WbContest) o).getEndDate() != null) {
        if (((WbContest) o).getStartDate().getTime() >= (((WbContest) o).getEndDate().getTime())) {
            errors.rejectValue("startDate", "wboard.error.startdate.after.endate", "Start date before the end date.");
        }
    }
    if (wbContestDAO.getContestById(((WbContest) o).getId()) != null) {
        errors.rejectValue("name", "wboard.error.contest.exist", "This contest already exists.");
    }

    if (((WbContest) o).getSid() == 0) {
        errors.rejectValue("sid", "wboard.error.nosite", "Select a site.");
    }

    if (!((WbContest) o).getUrl().matches(URLREGEX)) {
        errors.rejectValue("url", "wboard.error.url.invalid");
    }
}
项目:registration-login-spring-hsql    文件:UserValidator.java   
@Override
public void validate(Object o, Errors errors) {
    User user = (User) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
    if (user.getUsername().length() < 6 || user.getUsername().length() > 32) {
        errors.rejectValue("username", "Size.userForm.username");
    }
    if (userService.findByUsername(user.getUsername()) != null) {
        errors.rejectValue("username", "Duplicate.userForm.username");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
    if (user.getPassword().length() < 8 || user.getPassword().length() > 32) {
        errors.rejectValue("password", "Size.userForm.password");
    }

    if (!user.getPasswordConfirm().equals(user.getPassword())) {
        errors.rejectValue("passwordConfirm", "Diff.userForm.passwordConfirm");
    }
}
项目:communote-server    文件:UserManagementUserProfileValidator.java   
/**
 * {@inheritDoc}
 */
public void validate(Object target, Errors errors) {
    UserProfileForm form = (UserProfileForm) target;

    UserProfileVO profile = form.getUserProfile();
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userProfile.firstName",
            "error.valueEmpty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userProfile.lastName",
            "error.valueEmpty");

    validateString(profile.getFirstName(), "userProfile.firstName", errors);
    validateString(profile.getLastName(), "userProfile.lastName", errors);
    validateString(profile.getSalutation(), "userProfile.salutation", errors);
    validateString(profile.getPosition(), "userProfile.position", errors);
    validateString(profile.getCompany(), "userProfile.company", errors);

    validateString(profile.getStreet(), "userProfile.street", errors);
    validateString(profile.getZip(), "userProfile.zip", errors);
    validateString(profile.getCity(), "userProfile.city", errors);
    ValidationHelper.validatePhoneNumber(profile.getPhone(), "phone", errors, false);
    ValidationHelper.validatePhoneNumber(profile.getFax(), "fax", errors, false);
    if (StringUtils.isEmpty(form.getLanguageCode())) {
        errors.rejectValue("languageCode", "error.valueEmpty");
    }
}
项目:communote-server    文件:ClientProfileEmailValidator.java   
/**
 * {@inheritDoc}
 * 
 * @see org.springframework.validation.Validator#validate(Object,
 *      org.springframework.validation.Errors)
 */
public void validate(Object target, Errors errors) {
    ClientProfileEmailForm form = (ClientProfileEmailForm) target;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "clientEmail", "error.valueEmpty");
    if (!errors.hasFieldErrors("clientEmail")) {
        if (!EmailValidator.validateEmailAddressByRegex(form.getClientEmail())) {
            errors.rejectValue("clientEmail", "error.email.not.valid",
                    "The entered email address is not valid!");
        }
    }
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "clientEmailName", "error.valueEmpty");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "clientSupportEmailAddress",
            "error.valueEmpty");
    if (!errors.hasFieldErrors("clientSupportEmailAddress")) {
        if (!EmailValidator.validateEmailAddressByRegex(form.getClientSupportEmailAddress())) {
            errors.rejectValue("clientSupportEmailAddress", "error.email.not.valid",
                    "The entered email address is not valid!");
        }
    }
}
项目:springlets    文件:CollectionValidator.java   
/**
 * Validate each element inside the supplied {@link Collection}.
 * 
 * The supplied errors instance is used to report the validation errors.
 * 
 * @param target the collection that is to be validated
 * @param errors contextual state about the validation process
 */
@Override
@SuppressWarnings("rawtypes")
public void validate(Object target, Errors errors) {
  Collection collection = (Collection) target;
  int index = 0;

  for (Object object : collection) {
    BeanPropertyBindingResult elementErrors = new BeanPropertyBindingResult(object,
        errors.getObjectName());
    elementErrors.setNestedPath("[".concat(Integer.toString(index++)).concat("]."));
    ValidationUtils.invokeValidator(validator, object, elementErrors);

    errors.addAllErrors(elementErrors);
  }
}
项目:communote-server    文件:InstallerAdminAccountValidator.java   
/**
 * {@inheritDoc}
 */
@Override
public void validate(Object target, Errors errors) {
    InstallerForm form = (InstallerForm) target;

    // validate email address
    ValidationHelper.validateEmail("userEmail", form.getUserEmail(), true, errors);

    // check if firstname and lastname contains content
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userFirstName", "error.valueEmpty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userLastName", "error.valueEmpty");

    // check if language code contains content
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userLanguageCode", "error.valueEmpty");

    // check user alias
    validateAlias("userAlias", form.getUserAlias(), errors);

    // check user password
    ValidationHelper.validatePasswords(ServiceLocator.findService(UserPasswordManagement.class),
            "userPassword", form.getUserPassword(), "userPasswordConfirmation",
            form.getUserPasswordConfirmation(), errors);
}
项目:communote-server    文件:EmailAliasInvitationField.java   
/**
 * {@inheritDoc}
 */
@Override
public void validate(InviteUserForm form, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAlias", "error.valueEmpty");
    if (!errors.hasFieldErrors("emailAlias")) {
        if (form.getEmailAlias().contains("@")) {
            if (!EmailValidator.validateEmailAddressByRegex(form.getEmailAlias())) {
                errors.rejectValue("emailAlias", "error.email.not.valid",
                        "The entered email address is not valid!");
            }
        } else {
            if (!form.getEmailAlias().matches(ValidationPatterns.PATTERN_ALIAS)) {
                errors.rejectValue("emailAlias", "error.alias.not.valid",
                        "The entered login is not valid!");
            }
        }
    }
}
项目:EventSoft    文件:UserValidator.java   
@Override
public void validate(Object o, Errors errors) {
    Usuario usuario = (Usuario) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "direccion", "NotEmpty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "localidad", "NotEmpty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "provincia", "NotEmpty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "codigoPostal", "NotEmpty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "telefono", "NotEmpty");
}
项目:Spring-5.0-Cookbook    文件:EmployeeValidator.java   
@Override
public void validate(Object model, Errors errors) {
    EmployeeForm empForm = (EmployeeForm) model;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "empty.firstName");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "empty.lastName");

    if(empForm.getAge() < 0) errors.rejectValue("age", "negative.age");
    if(empForm.getAge() > 65) errors.rejectValue("age", "retirable.age");

    if(empForm.getBirthday().before(new Date(50,0,1))) errors.rejectValue("birthday", "old.birthday");
    Date now = new Date();
    if(empForm.getBirthday().getYear() == now.getYear() || empForm.getBirthday().before(new Date(99,0,1))) errors.rejectValue("birthday", "underage.birthday");
}
项目:Spring-5.0-Cookbook    文件:EmployeeValidator.java   
@Override
public void validate(Object model, Errors errors) {
    EmployeeForm empForm = (EmployeeForm) model;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "empty.firstName");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "empty.lastName");

    if(empForm.getAge() < 0) errors.rejectValue("age", "negative.age");
    if(empForm.getAge() > 65) errors.rejectValue("age", "retirable.age");

    if(empForm.getBirthday().before(new Date(50,0,1))) errors.rejectValue("birthday", "old.birthday");
    Date now = new Date();
    if(empForm.getBirthday().getYear() == now.getYear() || empForm.getBirthday().before(new Date(99,0,1))) errors.rejectValue("birthday", "underage.birthday");
}
项目:Spring-5.0-Cookbook    文件:EmployeeValidator.java   
@Override
public void validate(Object model, Errors errors) {
    EmployeeForm empForm = (EmployeeForm) model;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "empty.firstName");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "empty.lastName");

    if(empForm.getAge() < 0) errors.rejectValue("age", "negative.age");
    if(empForm.getAge() > 65) errors.rejectValue("age", "retirable.age");

    if(empForm.getBirthday().before(new Date(50,0,1))) errors.rejectValue("birthday", "old.birthday");
    Date now = new Date();
    if(empForm.getBirthday().getYear() == now.getYear() || empForm.getBirthday().before(new Date(99,0,1))) errors.rejectValue("birthday", "underage.birthday");
}
项目:Facegram    文件:StoryRequestValidator.java   
@Override
public void validate(Object o, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors,"title","title.empty");
    StoryRequest storyRequest = (StoryRequest) o;
    geolocationValidator = new GeolocationValidator();
    ValidationUtils.invokeValidator(this.geolocationValidator, storyRequest.getGeolocation(), errors);

}
项目:happy-news    文件:UserValidator.java   
@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "field.required");

    User user = (User) target;

    passwordValidator.validate(user.getRawPassword(), errors);
}
项目:SmartSync    文件:TodoListValidator.java   
@Override
public void validate(Object o, Errors errors) {

    TodoListDTO todoListDTO = (TodoListDTO) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
            "User Id must not be empty.");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "field.required",
            "Name must not be empty.");
}