List of usage examples for org.apache.commons.validator.routines UrlValidator UrlValidator
public UrlValidator(RegexValidator authorityValidator, long options)
From source file:org.lirazs.gbackbone.validation.client.rule.UrlRule.java
@Override public boolean isValid(final String url, String attribute) { String[] schemes = ruleAnnotation.schemes(); long options = ruleAnnotation.allowFragments() ? 0 : UrlValidator.NO_FRAGMENTS; UrlValidator urlValidator = schemes != null && schemes.length > 0 ? new UrlValidator(schemes, options) : UrlValidator.getInstance(); return urlValidator.isValid(url); }
From source file:org.opens.tgol.validator.CreateContractFormValidator.java
/** * * @param userSubscriptionCommand/*from ww w. ja v a2 s .c o m*/ * @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" }; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_2_SLASHES); if (!urlValidator.isValid(url)) { errors.rejectValue(CONTRACT_URL_KEY, INVALID_URL_KEY); return false; } return true; }
From source file:org.orcid.frontend.web.controllers.DeveloperToolsController.java
/** * Checks if a redirect uri contains a valid URI associated to it * //w w w . j ava2s . co m * @param redirectUri * @return null if there are no errors, an List of strings containing error * messages if any error happens * */ private List<String> validateRedirectUri(RedirectUri redirectUri) { List<String> errors = null; String[] schemes = { "http", "https" }; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS); if (!PojoUtil.isEmpty(redirectUri.getValue())) { try { String redirectUriString = redirectUri.getValue().getValue(); if (!urlValidator.isValid(redirectUriString)) { errors = new ArrayList<String>(); errors.add(getMessage("manage.developer_tools.invalid_redirect_uri")); } } catch (NullPointerException npe) { errors = new ArrayList<String>(); errors.add(getMessage("manage.developer_tools.empty_redirect_uri")); } } else { errors = new ArrayList<String>(); errors.add(getMessage("manage.developer_tools.empty_redirect_uri")); } return errors; }
From source file:ws.argo.probe.Probe.java
/** * Add a URL that specifies where the Responder should send the response. * Provide a label as a hint to the Responder about why this URL was included. * For example: give a "internal" label for a respondToURL that is only * accessible from inside a NATed network. * /* ww w . ja v a 2 s . c o m*/ * @param label - hint about the URL * @param respondToURL - the URL the responder will POST a payload to * @throws MalformedURLException if the URL is bad */ public void addRespondToURL(String label, String respondToURL) throws MalformedURLException { // Sanity check on the respondToURL // The requirement for the respondToURL is a REST POST call, so that means // only HTTP and HTTPS schemes. // Localhost is allowed as well as a valid response destination String[] schemes = { "http", "https" }; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(respondToURL)) throw new MalformedURLException("The probe respondTo URL is invalid: " + respondToURL); _probe.addRespondToURL(label, respondToURL); }