Example usage for org.apache.commons.validator.routines UrlValidator isValid

List of usage examples for org.apache.commons.validator.routines UrlValidator isValid

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines UrlValidator isValid.

Prototype

public boolean isValid(String value) 

Source Link

Document

Checks if a field has a valid url address.

Usage

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.");
    }//from   w w  w . j a v  a 2  s .co m
}

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 av  a2  s.  com
    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(uri)) {
        throw new InvalidTemplateEndpointException("The endpoint URL \"" + uri + "\" is invalid.");
    }
}

From source file:com.intel.podm.services.detection.filesystem.ServiceListFileRecordsParser.java

private boolean containsValidUrl(String[] recordParts) {
    UrlValidator urlValidator = new UrlValidator(ALLOW_LOCAL_URLS);
    return urlValidator.isValid(recordParts[SERVICE_LIST_URL_POSITION]);
}

From source file:net.daporkchop.porkselfbot.command.base.CommandGET.java

@Override
public void excecute(MessageReceivedEvent evt, String[] a, String message) {
    try {//from  w w w. j av  a  2s  .  c  o m
        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.intel.podm.rest.HttpServletRequestValidator.java

private void validateUrlSyntax(String urlString) throws HttpServletRequestValidationException {
    UrlValidator urlValidator = new UrlValidator(ALLOW_LOCAL_URLS);
    if (!urlValidator.isValid(urlString)) {
        String errorMessage = format("Requested URI %s is not valid", urlString);
        LOGGER.w(errorMessage);//from  ww w.  j  a  v a2s. c o  m
        throw new HttpServletRequestValidationException(errorMessage, MALFORMED_URI);
    }
}

From source file:com.formkiq.core.service.formInterceptor.SystemConfigInterceptor.java

/**
 * Validate Host.//from   www .  j  a  v a  2  s . c om
 * @param host {@link FormJSONField}
 * @param errors {@link Map}
 */
private void validateHost(final FormJSONField host, final Map<String, String> errors) {

    String[] schemes = { "http", "https" };
    UrlValidator urlValidator = new UrlValidator(schemes);

    if (!urlValidator.isValid(host.getValue())) {
        errors.put("" + host.getId(), "Invalid URL");
    }
}

From source file:com.alefissak.web.AlefissakListener.java

/**
 * Verify if the parameter is a valid URL 
 * /*  w w w .  j  a v  a 2 s. c om*/
 * @param configUri
 * @return true if configUri is a valid URL
 */
private boolean isURL(String configUri) {
    UrlValidator urlValidator = new UrlValidator(new String[] { "http", "https" });

    return urlValidator.isValid(configUri);
}

From source file:io.confluent.support.metrics.submitters.ConfluentSubmitter.java

private boolean testEndpointValid(String[] schemes, String endpoint) {
    UrlValidator urlValidator = new UrlValidator(schemes);
    if (urlValidator.isValid(endpoint)) {
        return true;
    } else {//  www  .j av a  2  s.  c o  m
        return false;
    }
}

From source file:net.daporkchop.porkselfbot.command.base.CommandPOST.java

@Override
public void excecute(MessageReceivedEvent evt, String[] args, String message) {
    try {// w  ww  .  j  a va 2s  .c om
        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:$.ApplicationAction.java

private void validateApplication(Application app, String appname) {
        if (StringUtils.isBlank(app.getDisplayName())) {
            addFieldError("app.displayName", getText("message.application.name.notempty"));
        }//from  w w w . j av a  2 s  .  c  o  m

        if (StringUtils.isBlank(app.getSite())) {
            addFieldError("app.site", getText("message.application.site.notempty"));
        }

        UrlValidator validator = new UrlValidator(new String[] { "http", "https" });
        if (!validator.isValid(app.getSite())) {
            addFieldError("app.site", getText("message.application.site.notvalid"));
        }
    }