List of usage examples for org.apache.commons.validator.routines UrlValidator isValid
public boolean isValid(String value)
Checks if a field has a valid url address.
From source file:com.fluxit.camel.component.n4.N4Component.java
private void validateRequiredProperties(N4Endpoint endpoint) throws Exception { // valido que la URI del provider exista if (ObjectHelper.isEmpty(endpoint.getN4EndpointURI())) { throw new IllegalArgumentException("La propiedad n4EndpointURI no puede ser nula"); } else {/*www .j ava 2 s.co m*/ UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(endpoint.getN4EndpointURI())) { throw new IllegalArgumentException( "La URL del provider no es valida, corregir la propiedad n4EndpointURI"); } } // valido que exista uno y solo un mtodo de transformacin de entrada if (endpoint.getUriMapInput() == null && endpoint.getUriXSLTInput() == null) { LOG.error("No se seteo ningn mtodo de transformacin de entrada"); throw new IllegalArgumentException("Se debe setear un mtodo de transformacion de entrada"); } else if (endpoint.getUriMapInput() != null && endpoint.getUriXSLTInput() != null) { LOG.error("Se setearon ambas transformaciones de entrada, se debe usar solo una"); throw new IllegalArgumentException("Solo puede existir un mtodo de transformacion de entrada"); } if (endpoint.getClassSerialization() != null) { LOG.debug("Instanciando el contexto de JAXB"); JAXBContext jaxbContext = JAXBContext.newInstance(Class.forName(endpoint.getClassSerialization())); endpoint.setJaxbContext(jaxbContext); } }
From source file:com.intel.rsa.podm.rest.filters.UrlValidationFilter.java
private boolean isUrlValid(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { if (String.format("%s %s HTTP/1.1\n\r", httpServletRequest.getMethod(), httpServletRequest.getRequestURL()) .getBytes(StandardCharsets.UTF_8).length > URL_MAX_LENGTH_IN_BYTES) { logger.w("Requested URI exceeds maximum URI length which is set to {} octets", URL_MAX_LENGTH_IN_BYTES); setErrorResponse(httpServletResponse, ErrorResponse.URI_TOO_LONG); return false; }/*from ww w . ja v a2s.c om*/ String url = httpServletRequest.getRequestURL().toString(); UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); if (urlValidator.isValid(url) && isUrlDecodingPossible(url)) { return true; } else { setErrorResponse(httpServletResponse, ErrorResponse.MALFORMED_URI); return false; } }
From source file:de.fhg.fokus.odp.portal.managedatasets.validator.EmailOrURLValidator.java
@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { if (((String) value).isEmpty()) { throwValidatorException();//from www .j av a 2 s. c o m } else { String[] schemes = { "http", "https", "ftp", "ftps" }; UrlValidator urlValidator = new UrlValidator(schemes); // UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid((String) value)) { return; } else if (EmailValidator.getInstance().isValid((String) value)) { return; } else { throwValidatorException(); } } }
From source file:com.liferay.ide.project.core.workspace.BundleUrlValidationService.java
@Override protected Status compute() { Status retval = Status.createOkStatus(); BaseLiferayWorkspaceOp op = _op();/*from ww w . j a va 2 s .com*/ String bundleUrl = op.getBundleUrl().content(); UrlValidator urlValidator = new UrlValidator( UrlValidator.ALLOW_LOCAL_URLS | UrlValidator.ALLOW_ALL_SCHEMES); if ((bundleUrl != null) && !urlValidator.isValid(bundleUrl)) { retval = Status.createWarningStatus("The bundle URL may not be a vaild URL."); } return retval; }
From source file:com.musala.core.RssUrlsObserver.java
@Override @Transactional//from w w w . java 2 s .c o m public void update(ArticleInfo articleInfo) { if (articleInfo.getTagType() == TagType.CATEGORY) { if (articleInfo.getCategoryName() != null && !articleInfo.getCategoryName().isEmpty() && articleInfo.getCategoryName() != null) { Article article = articleService.findByLink(currentLink); Category category = categoryService.findByCategoryName(articleInfo.getCategoryName()); category.getArticles().add(article); article.getCategories().add(category); } } if (articleInfo.getTagType() == TagType.LINK) { UrlValidator defaultValidator = new UrlValidator(); if (defaultValidator.isValid(articleInfo.getCategoryName())) {//getCategoryName() have URL information //TODO rename CategoryName to categoryTag Article article = new Article(articleInfo.getCategoryName(), articleInfo.getSite()); try { getTextFromPages.readArticleText(article); } catch (IOException e) { articleService.delete(article); logger.warn("For the article %s following error occurs.", e); } //Check for null category checkForArticleWithoutCategories(); currentLink = articleInfo.getCategoryName(); //Search if there is article with the current link. This is done because //If there are link with invalid information, they will not be persisted if (articleService.findByLink(articleInfo.getCategoryName()) == null) { currentLink = null; } } else { throw new RuntimeException(ErrorMessages.INVALID_URL_FROM_RSS + articleInfo.getCategoryName()); } } }
From source file:cz.hobrasoft.pdfmu.operation.signature.TimestampParameters.java
@Override public void setFromNamespace(Namespace namespace) throws OperationException { url = namespace.get("tsa_url"); if (url != null) { UrlValidator urlValidator = new UrlValidator(); if (!urlValidator.isValid(url)) { throw new OperationException(SIGNATURE_ADD_TSA_INVALID_URL); }/*from w ww . jav a 2 s. c o m*/ } username = namespace.getString("tsa_username"); passwordArgs.setFromNamespace(namespace); sslKeystore.setFromNamespace(namespace); if (sslKeystore.file != null) { String password = sslKeystore.getPassword(); if (password == null || password.isEmpty()) { LOGGER.warning( "SSL KeyStore: Location has been set but password has not. Only KeyStores protected by a non-empty password are supported."); } } sslKeystore.setSystemProperties(SslKeystore.PRIVATE); sslTruststore.setFromNamespace(namespace); sslTruststore.setSystemProperties(SslKeystore.TRUSTSTORE); }
From source file:de.ist.clonto.webwiki.InfoboxParser.java
private String removeExternalAnchors(String text) { Pattern eanchorPattern = Pattern.compile("\\[.*?\\]"); Matcher eanchorMatcher = eanchorPattern.matcher(text); while (eanchorMatcher.find()) { String anchor = eanchorMatcher.group(); String manchor = anchor.replaceAll("\\[", ""); manchor = manchor.replaceAll("\\]", ""); String[] manchorParts = manchor.split("\\s"); UrlValidator validator = new UrlValidator(); if (validator.isValid(manchorParts[0])) { text = text.replace(anchor, manchor); }/*from w w w.j av a 2 s . c o m*/ } return text; }
From source file:eu.freme.broker.tools.NIFParameterFactory.java
public NIFParameterSet constructFromHttp(String input, String informat, String outformat, String postBody, String acceptHeader, String contentTypeHeader, String prefix, boolean allowEmptyInput) throws BadRequestException { String thisInput;/* w w w . j ava2 s. c om*/ if (!allowEmptyInput && input == null && postBody == null) { throw new BadRequestException("no input found in request"); } else if (input != null) { thisInput = input; } else { thisInput = postBody; } RDFSerialization thisInformat; if (informat == null && contentTypeHeader == null) { thisInformat = RDFSerialization.TURTLE; } else if (informat != null) { if (!rdfSerializationFormats.containsKey(informat)) { throw new BadRequestException("parameter informat has invalid value \"" + informat + "\""); } thisInformat = rdfSerializationFormats.get(informat); } else { String[] contentTypeHeaderParts = contentTypeHeader.split(";"); if (!rdfSerializationFormats.containsKey(contentTypeHeaderParts[0])) { throw new BadRequestException( "Content-Type header has invalid value \"" + contentTypeHeader + "\""); } thisInformat = rdfSerializationFormats.get(contentTypeHeaderParts[0]); } RDFSerialization thisOutformat; if (acceptHeader != null && acceptHeader.equals("*/*")) { acceptHeader = "text/turtle"; } if (outformat == null && acceptHeader == null) { thisOutformat = RDFSerialization.TURTLE; } else if (outformat != null) { if (!rdfSerializationFormats.containsKey(outformat)) { throw new BadRequestException("Parameter outformat has invalid value \"" + outformat + "\""); } thisOutformat = rdfSerializationFormats.get(outformat); if (thisOutformat == RDFConstants.RDFSerialization.PLAINTEXT) { throw new BadRequestException("Parameter outformat has invalid value \"" + outformat + "\""); } } else { if (!rdfSerializationFormats.containsKey(acceptHeader)) { throw new BadRequestException("Parameter outformat has invalid value \"" + acceptHeader + "\""); } thisOutformat = rdfSerializationFormats.get(acceptHeader); if (thisOutformat == RDFConstants.RDFSerialization.PLAINTEXT) { throw new BadRequestException("Parameter outformat has invalid value \"" + acceptHeader + "\""); } } String thisPrefix; if (prefix == null) { thisPrefix = defaultPrefix; } else { thisPrefix = prefix; } String[] schemes = { "http", "https" }; UrlValidator urlValidator = new UrlValidator(schemes); if (!urlValidator.isValid(thisPrefix)) { throw new BadRequestException("invalid prefix"); } return new NIFParameterSet(thisInput, thisInformat, thisOutformat, thisPrefix); }
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 ww. jav a 2s.com*/ ; 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:it.cnr.ilc.soapclient.app.Theservice.java
/** * This method does the following:/*from w w w . j a v a 2 s . c om*/ * <ul> * <li>Sets the input parameters as service inputs; </li> * <li>Checks if the input string is a URL. If so then executes the corresponding methods; </li> * <li>Executes the service. </li> * </ul> */ public void run() { String message = "", routine = "run"; boolean fromUrl = false; service.setInputs(inputs); UrlValidator defaultValidator = new UrlValidator(); // default schemes if (defaultValidator.isValid(input)) { fromUrl = true; message = String.format("Routine %s. The inputType supplied -%s- requires to be read from a URL. " + "So fromUrl is set to %s", routine, input, fromUrl); Logger.getLogger(CLASS_NAME).log(Level.INFO, message); } else { fromUrl = false; message = String.format( "The inputType supplied -%s- requires to be read from a String. So fromUrl is set to %s", input, fromUrl); Logger.getLogger(CLASS_NAME).log(Level.INFO, message); } // Map inputs = new HashMap(); //inputs.put("output_format", "tagged"); //freelingIt.setInputs(inputs); message = String.format("Calling service %s with fromUrl %s", service.getSERVICE_NAME(), fromUrl); Logger.getLogger(CLASS_NAME).log(Level.INFO, message); service.runService(input, inputs, fromUrl); if (service.getStatus() == 0 && !service.getOutputUrl().isEmpty()) { message = String.format("Executed service %s with status %s and output url %s", service.getSERVICE_NAME(), service.getStatus(), service.getOutputUrl()); Logger.getLogger(CLASS_NAME).log(Level.INFO, message); } }