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;
}
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;
}
Aggregations