List of usage examples for org.apache.commons.validator.routines UrlValidator ALLOW_2_SLASHES
long ALLOW_2_SLASHES
To view the source code for org.apache.commons.validator.routines UrlValidator ALLOW_2_SLASHES.
Click Source Link
From source file:com.coroptis.coidi.rp.services.impl.DiscoverySupportImpl.java
public DiscoverySupportImpl(final HttpService httpService, final XrdsService xrdsService) { this.httpService = Preconditions.checkNotNull(httpService); this.xrdsService = Preconditions.checkNotNull(xrdsService); patternEmail = Pattern.compile(EMAIL_PATTERN); patternXri = Pattern.compile(XRI_PATTERN); patternDomainSlash = Pattern.compile(DOMAIN_SLASH_PATTERN); String[] schemes = { "http", "https" }; urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_2_SLASHES + UrlValidator.ALLOW_LOCAL_URLS + UrlValidator.NO_FRAGMENTS); }
From source file:monasca.api.app.command.CreateNotificationMethodCommand.java
public void validate() { switch (type) { case EMAIL: { if (!EmailValidator.getInstance(true).isValid(address)) throw Exceptions.unprocessableEntity("Address %s is not of correct format", address); }//from w w w . j ava 2 s . co m ; break; case WEBHOOK: { String[] schemes = { "http", "https" }; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS | UrlValidator.ALLOW_2_SLASHES); if (!urlValidator.isValid(address)) throw Exceptions.unprocessableEntity("Address %s is not of correct format", address); } ; break; case PAGERDUTY: { // No known validation for PAGERDUTY type at this time } ; break; } }
From source file:ke.co.tawi.babblesms.server.sendsms.tawismsgw.PostSMS.java
/** * Contains what is required to send SMS using the Tawi SMS Gateway. * /* www . j av a 2s.com*/ * @param smsGateway * @param phoneList * @param smsSource * @param message * @param account * @param retry whether or not to keep retrying if the POST fails */ public PostSMS(TawiGateway smsGateway, List<Phone> phoneList, SMSSource smsSource, String message, Account account, boolean retry) { this.smsGateway = smsGateway; this.phoneList = phoneList; this.smsSource = smsSource; this.message = message; this.account = account; this.retry = retry; retryCount = RETRY_NUMBER; urlValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES + UrlValidator.ALLOW_LOCAL_URLS); outgoingLogDAO = OutgoingLogDAO.getInstance(); logger = Logger.getLogger(this.getClass()); }
From source file:com.hp.autonomy.searchcomponents.hod.view.HodViewServerService.java
@Override public void viewDocument(final String reference, final ResourceIdentifier index, final OutputStream outputStream) throws IOException, HodErrorException { final GetContentRequestBuilder getContentParams = new GetContentRequestBuilder().setPrint(Print.all); final Documents<Document> documents = getContentService.getContent(Collections.singletonList(reference), index, getContentParams);// w w w . j a va 2 s . c o m // This document will always exist because the GetContentService.getContent throws a HodErrorException if the // reference doesn't exist in the index final Document document = documents.getDocuments().get(0); final Map<String, Serializable> fields = document.getFields(); final Object urlField = fields.get(URL_FIELD); final String documentUrl = urlField instanceof List ? ((List<?>) urlField).get(0).toString() : document.getReference(); final UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); InputStream inputStream = null; try { try { final URL url = new URL(documentUrl); final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null); final String encodedUrl = uri.toASCIIString(); if (urlValidator.isValid(encodedUrl)) { inputStream = viewDocumentService.viewUrl(encodedUrl, new ViewDocumentRequestBuilder()); } else { throw new URISyntaxException(encodedUrl, "Invalid URL"); } } catch (URISyntaxException | MalformedURLException e) { // URL was not valid, fall back to using the document content inputStream = formatRawContent(document); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.BACKEND_REQUEST_FAILED) { // HOD failed to read the url, fall back to using the document content inputStream = formatRawContent(document); } else { throw e; } } IOUtils.copy(inputStream, outputStream); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:org.asqatasun.webapp.validator.CreateContractFormValidator.java
/** * * @param userSubscriptionCommand/*from w w w . jav a2s. c om*/ * @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, validatorOptions); if (!urlValidator.isValid(url)) { errors.rejectValue(CONTRACT_URL_KEY, INVALID_URL_KEY); return false; } return true; }
From source file:org.asqatasun.webapp.validator.CreateUserFormValidator.java
/** * * @param userSubscriptionCommand/*from w w w. jav a 2 s . c o m*/ * @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; }
From source file:org.asqatasun.websnapshot.urlmanager.utils.UrlUtils.java
/** * * @param url/*from w w w . ja v a 2 s. c o m*/ * @return */ public static boolean checkIfURLIsValid(String url) { String[] schemes = { "http", "https" }; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_2_SLASHES); return urlValidator.isValid(url); }
From source file:org.codehaus.griffon.runtime.validation.constraints.UrlConstraint.java
@Override @SuppressWarnings("SuspiciousToArrayCall") public void setParameter(@Nonnull Object constraintParameter) { RegexValidator domainValidator = null; if (constraintParameter instanceof Boolean) { url = (Boolean) constraintParameter; } else if (constraintParameter instanceof String) { url = true;//from w w w.j a va 2s . c om domainValidator = new RegexValidator((String) constraintParameter); } else if (constraintParameter instanceof List<?>) { url = true; List<?> regexpList = (List<?>) constraintParameter; domainValidator = new RegexValidator(regexpList.toArray(new String[regexpList.size()])); } else { throw new IllegalArgumentException("Parameter for constraint [" + VALIDATION_DSL_NAME + "] of property [" + constraintPropertyName + "] of class [" + constraintOwningClass + "] must be a boolean, string, or list value"); } validator = new UrlValidator(domainValidator, UrlValidator.ALLOW_ALL_SCHEMES + UrlValidator.ALLOW_2_SLASHES); super.setParameter(constraintParameter); }
From source file:org.mule.modules.validation.ValidationModule.java
/** * If the specified <code>url</code> is not a valid one throw an exception. * <p/>//from w w w .j a v a2s . co m * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-url} * * @param url URL to validate * @param allowTwoSlashes Allow two slashes in the path component of the URL. * @param allowAllSchemes Allows all validly formatted schemes to pass validation instead of supplying a set of valid schemes. * @param allowLocalURLs Allow local URLs, such as http://localhost/ or http://machine/ . * @param noFragments Enabling this options disallows any URL fragments. * @param customExceptionClassName Class name of the exception to throw * @throws Exception if not valid */ @Processor public void validateUrl(String url, @Optional @Default("false") boolean allowTwoSlashes, @Optional @Default("false") boolean allowAllSchemes, @Optional @Default("false") boolean allowLocalURLs, @Optional @Default("false") boolean noFragments, @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName) throws Exception { long options = 0; if (allowAllSchemes) { options |= UrlValidator.ALLOW_ALL_SCHEMES; } if (allowTwoSlashes) { options |= UrlValidator.ALLOW_2_SLASHES; } if (allowLocalURLs) { options |= UrlValidator.ALLOW_LOCAL_URLS; } if (noFragments) { options |= UrlValidator.NO_FRAGMENTS; } UrlValidator validator = new UrlValidator(options); if (!validator.isValid(url)) { throw buildException(customExceptionClassName); } }
From source file:org.opens.tgol.validator.CreateContractFormValidator.java
/** * * @param userSubscriptionCommand//from w ww .j a va 2 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; }