Search in sources :

Example 6 with UrlValidator

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

the class CreateUserFormValidator method checkSiteUrl.

/**
     *
     * @param userSubscriptionCommand
     * @param errors
     * @return
     */
private boolean checkSiteUrl(CreateUserCommand userSubscriptionCommand, Errors errors) {
    if (!checkSiteUrl) {
        return true;
    }
    if (userSubscriptionCommand.getSiteUrl() == null || userSubscriptionCommand.getSiteUrl().trim().isEmpty()) {
        errors.rejectValue(SITE_URL_KEY, MISSING_URL_KEY);
        return false;
    } else {
        String url = userSubscriptionCommand.getSiteUrl().trim();
        String[] schemes = { "http", "https" };
        UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_2_SLASHES);
        if (!urlValidator.isValid(url)) {
            errors.rejectValue(SITE_URL_KEY, INVALID_URL_KEY);
            return false;
        }
    }
    return true;
}
Also used : UrlValidator(org.apache.commons.validator.routines.UrlValidator)

Example 7 with UrlValidator

use of org.apache.commons.validator.routines.UrlValidator in project maven-plugins by apache.

the class LicensesReport method getLicenseURL.

/**
     * @param project not null
     * @param url     not null
     * @return a valid URL object from the url string
     * @throws IOException if any
     */
protected static URL getLicenseURL(MavenProject project, String url) throws IOException {
    URL licenseUrl;
    UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES);
    // file scheme.
    if (urlValidator.isValid(url) || StringUtils.defaultString(url).startsWith("file://")) {
        try {
            licenseUrl = new URL(url);
        } catch (MalformedURLException e) {
            throw new MalformedURLException("The license url '" + url + "' seems to be invalid: " + e.getMessage());
        }
    } else {
        File licenseFile = new File(project.getBasedir(), url);
        if (!licenseFile.exists()) {
            // Workaround to allow absolute path names while
            // staying compatible with the way it was...
            licenseFile = new File(url);
        }
        if (!licenseFile.exists()) {
            throw new IOException("Maven can't find the file '" + licenseFile + "' on the system.");
        }
        try {
            licenseUrl = licenseFile.toURI().toURL();
        } catch (MalformedURLException e) {
            throw new MalformedURLException("The license url '" + url + "' seems to be invalid: " + e.getMessage());
        }
    }
    return licenseUrl;
}
Also used : MalformedURLException(java.net.MalformedURLException) UrlValidator(org.apache.commons.validator.routines.UrlValidator) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Aggregations

UrlValidator (org.apache.commons.validator.routines.UrlValidator)7 ArrayList (java.util.ArrayList)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 RegexValidator (org.apache.commons.validator.routines.RegexValidator)1 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)1 Text (org.orcid.pojo.ajaxForm.Text)1