List of usage examples for org.apache.commons.validator.routines UrlValidator UrlValidator
public UrlValidator()
From source file:com.jonbanjo.cupsprint.Util.java
public static URL getURL(String urlStr) throws MalformedURLException { UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid(urlStr)) { try {/*w w w.j a v a 2 s . c o m*/ return new URL(urlStr); } catch (Exception e) { } } throw new MalformedURLException("Invalid URL\n" + urlStr); }
From source file:eu.freme.broker.tools.TemplateValidator.java
public void validateTemplateEndpoint(String uri) { UrlValidator urlValidator = new UrlValidator(); if (!urlValidator.isValid(uri)) { throw new InvalidTemplateEndpointException("The endpoint URL \"" + uri + "\" is invalid."); }// w w w . j av a 2 s . c o m }
From source file:com.ocrix.ppc.commons.Validator.java
/** * Validates an URI, if it is not valid then throws IllegalArgumentException * //from www . java 2s .c o m * @param uri * to be validated */ public static void validateURI(URI uri) { UrlValidator urlValidator = new UrlValidator(); if (!urlValidator.isValid(uri.toString())) throw new IllegalArgumentException("Please check a provided URI [ " + uri + " ]"); }
From source file:eu.freme.eservices.elink.TemplateValidator.java
public void validateTemplateEndpoint(String uri) { if (uri.contains("localhost")) { logger.warn("replacing \"localhost\" in the uri=" + uri + " by \"127.0.0.1\""); uri = uri.replace("localhost", "127.0.0.1"); }/*from w w w.j a v a 2s .co m*/ UrlValidator urlValidator = new UrlValidator(); if (!urlValidator.isValid(uri)) { throw new InvalidTemplateEndpointException("The endpoint URL \"" + uri + "\" is invalid."); } }
From source file:net.daporkchop.porkselfbot.command.base.CommandGET.java
@Override public void excecute(MessageReceivedEvent evt, String[] a, String message) { try {//from w ww . j ava2 s .com YMLParser yml = new YMLParser(); yml.loadRaw(message.substring(6)); String url = yml.get("url", null); if (url == null) { throw new IndexOutOfBoundsException(); //sends the error message } UrlValidator validator = new UrlValidator(); if (validator.isValid(url)) { String data = HTTPUtils.performGetRequest(HTTPUtils.constantURL(url)); String toSend = "GET result from `" + url + "`:\n\n```html\n" + data + "\n```"; if (toSend.length() < 2000) { evt.getMessage().editMessage(toSend).queue(); } else { evt.getMessage().editMessage("*Output too long!*").queue(); } } else { evt.getMessage().editMessage("Invalid URL: `" + url + "`").queue(); } } catch (IndexOutOfBoundsException e) { this.sendErrorMessage(evt, "Not enough arguments!"); } catch (IOException e) { this.sendErrorMessage(evt, "IOException lol"); } catch (YAMLException e) { evt.getMessage().editMessage("Bad YML formatting!").queue(); } }
From source file:com.magnet.plugin.helpers.VerifyHelper.java
public static boolean isValidUrlWithoutPerformance(String url) { UrlValidator urlValidator = new UrlValidator(); return urlValidator.isValid(url); }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.WebDavExplorer.java
public static List<Source> getFilesFrom(Repository repository) throws IOException, DavException, PanelException { List<Source> repositoryFiles = new LinkedList<Source>(); IOException ioe = null;//from ww w.j av a 2 s.c o m DavException dee = null; String user = repository.getUser(); String pass = repository.getPassword(); String url = repository.getUrl(); UrlValidator urlValidator = new UrlValidator(); if (!urlValidator.isValid(url)) { throw new PanelException("La url del repositorio no es vlida: " + url); } HttpClient client = new HttpClient(); if (!StringUtils.isEmpty(user) || !StringUtils.isEmpty(pass)) { Credentials creds = new UsernamePasswordCredentials(user, pass); client.getState().setCredentials(AuthScope.ANY, creds); } DavMethod lsMethod = null; try { lsMethod = new PropFindMethod(url, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1); client.executeMethod(lsMethod); MultiStatus multiStatus = lsMethod.getResponseBodyAsMultiStatus(); for (MultiStatusResponse msResponse : multiStatus.getResponses()) { // gets properties from the remote resource String sourceUrl = null, sourceName = null, sourceCType = null; Integer sourceSize = -1; FileType sourceType = null; DavPropertySet properties = msResponse.getProperties(200); // url sourceUrl = msResponse.getHref(); // name DavProperty<?> propName = properties.get(DavPropertyName.DISPLAYNAME); if (propName != null) { sourceName = (String) propName.getValue(); } if (StringUtils.isEmpty(sourceName)) { sourceName = Utils.getFileNameFromPath(sourceUrl); } // size DavProperty<?> propLength = properties.get(DavPropertyName.GETCONTENTLENGTH); if (propLength != null) { String sizeStr = (String) propLength.getValue(); try { sourceSize = Integer.parseInt(sizeStr); } catch (NumberFormatException e) { // none } } // content-type DavProperty<?> propCType = properties.get(DavPropertyName.GETCONTENTTYPE); if (propCType != null) { sourceCType = (String) propCType.getValue(); } // type sourceType = Utils.getTypeFromContentType(sourceCType); if (sourceType == FileType.UNKNOW) { sourceType = Utils.getTypeFromName(sourceName); } // creates the source and adds it to the list if (sourceType != null) { boolean validShape = ((sourceType == FileType.SHAPEFILE) && (Pattern.matches("^.+\\.shp$", sourceName.toLowerCase()))); boolean validCSV = (sourceType == FileType.CSV); boolean validFile = (validShape || validCSV || Utils.isCompressedFile(sourceCType)); if (validFile) { Source source = new Source(); source.setRemote(true); source.setName(sourceName); source.setSize(sourceSize); source.setContentType(sourceCType); source.setType(sourceType); // repository source.setAlias(repository.getAlias()); source.setUrl(repository.getUrl()); source.setUser(repository.getUser()); source.setPassword(repository.getPassword()); repositoryFiles.add(source); } } } } catch (IOException e) { ioe = e; } catch (DavException e) { dee = e; } finally { if (lsMethod != null) { lsMethod.releaseConnection(); } } if (ioe != null) { throw ioe; } if (dee != null) { throw dee; } return repositoryFiles; }
From source file:net.daporkchop.porkselfbot.command.base.CommandPOST.java
@Override public void excecute(MessageReceivedEvent evt, String[] args, String message) { try {/*from w w w. j av a 2 s.c o m*/ YMLParser yml = new YMLParser(); yml.loadRaw(message.substring(7)); String url = yml.get("url", null); String content = yml.get("content", null); if (url == null) { throw new IndexOutOfBoundsException(); //sends the error message } boolean doAuth = yml.getBoolean("doAuth", false); String contentType = yml.get("contentType", "text/plain"); String authKey = yml.get("authKey", null); UrlValidator validator = new UrlValidator(); if (validator.isValid(url)) { URL urI = HTTPUtils.constantURL(url); if (doAuth) { if (authKey == null) { evt.getMessage().editMessage("Auth key not given!").queue(); return; } String data = HTTPUtils.performPostRequestWithAuth(urI, content, contentType, authKey); String toSend = "POST result from `" + url + "` (with auth):\n\n```html\n" + data + "\n```"; if (toSend.length() < 2000) { evt.getMessage().editMessage(toSend).queue(); } else { evt.getMessage().editMessage("*Output too long!*").queue(); } } else { String data = HTTPUtils.performPostRequest(urI, content, contentType); String toSend = "POST result from `" + url + "`:\n\n```html\n" + data + "\n```"; if (toSend.length() < 2000) { evt.getMessage().editMessage(toSend).queue(); } else { evt.getMessage().editMessage("*Output too long!*").queue(); } } } else { evt.getMessage().editMessage("Invalid URL: `" + url + "`").queue(); } } catch (IndexOutOfBoundsException e) { this.sendErrorMessage(evt, "Not enough arguments!"); } catch (IOException e) { this.sendErrorMessage(evt, "IOException lol"); } catch (YAMLException e) { evt.getMessage().editMessage("Bad YML formatting!").queue(); } }
From source file:com.musala.core.RssUrlsObserver.java
@Override @Transactional/*from w ww .ja v a 2s. 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:Commander.Main.java
private static void prepareCommand(String string) { String extension = null;//from w ww . j a va 2 s . c om List<String> options; String command; String[] commands = string.split(","); //Split to extension, options and command for (String s : commands) { options = getOptions(string); string = options.remove(options.size() - 1); //Get command without options String website = string; if (!website.contains("http") && !website.contains("https")) { if (!website.contains("www.")) { website = "http://www." + website; } else { website = "http://" + website; } } if (new UrlValidator().isValid(website)) { //Website System.out.println("website"); runWebsite(website); } else { //Not a website if (string.lastIndexOf(".") < string.length() - 1 && string.lastIndexOf(".") > 0) { extension = string.substring(string.lastIndexOf("."), string.length() - 1); command = string.replace("." + extension, ""); } else { command = string; } } } System.out.println(string); }