Search in sources :

Example 1 with RegexValidator

use of org.apache.commons.validator.routines.RegexValidator in project Asqatasun by Asqatasun.

the class CreateContractFormValidator method checkContractUrl.

/**
     *
     * @param userSubscriptionCommand
     * @param errors
     * @return
     */
private boolean checkContractUrl(CreateContractCommand createContractCommand, Errors errors) {
    String url = createContractCommand.getContractUrl().trim();
    if (StringUtils.isBlank(url)) {
        return true;
    }
    String[] schemes = { "http", "https" };
    long validatorOptions = UrlValidator.ALLOW_2_SLASHES + UrlValidator.ALLOW_LOCAL_URLS;
    UrlValidator urlValidator = new UrlValidator(schemes, new RegexValidator(".*"), validatorOptions);
    if (!urlValidator.isValid(url)) {
        errors.rejectValue(CONTRACT_URL_KEY, INVALID_URL_KEY);
        return false;
    }
    return true;
}
Also used : RegexValidator(org.apache.commons.validator.routines.RegexValidator) UrlValidator(org.apache.commons.validator.routines.UrlValidator)

Aggregations

RegexValidator (org.apache.commons.validator.routines.RegexValidator)1 UrlValidator (org.apache.commons.validator.routines.UrlValidator)1