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:com.vmware.identity.openidconnect.common.CommonUtils.java

public static boolean isValidUri(URI uri) {
    Validate.notNull(uri, "uri");

    String[] schemes = { "https" };
    UrlValidator urlValidator = new UrlValidator(schemes);
    return urlValidator.isValid(uri.toString());
}

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 av a 2 s  . c o  m*/
            return new URL(urlStr);
        } catch (Exception e) {
        }
    }
    throw new MalformedURLException("Invalid URL\n" + urlStr);
}

From source file:de.micromata.jira.rest.core.util.URIParser.java

public static URI parseStringToURI(String uri) {
    String[] schemes = { "http", "https" };
    UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS);
    if (urlValidator.isValid(uri)) {
        try {//from ww  w .  ja  v a 2 s  .c o  m
            return new URI(uri);
        } catch (URISyntaxException e) {
            return null;
        }
    }
    return null;
}

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:com.magnet.plugin.helpers.VerifyHelper.java

public static boolean isValidUrl(String url) {
    String templateURL = url;// ww w  .j av  a 2 s.  c  o  m
    templateURL = templateURL.replaceAll(Rest2MobileConstants.START_TEMPLATE_VARIABLE_REGEX, "");
    templateURL = templateURL.replaceAll(Rest2MobileConstants.END_TEMPLATE_VARIABLE_REGEX, "");
    UrlValidator urlValidator = new UrlValidator(SUPPORTED_PROTOCOL_SCHEMES, URL_VALIDATION_OPTIONS);
    return urlValidator.isValid(templateURL);
}

From source file:com.ocrix.ppc.commons.Validator.java

/**
 * Validates an URI, if it is not valid then throws IllegalArgumentException
 * //from  ww w .  j  a  va  2s. co 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:com.vmware.identity.openidconnect.protocol.URIUtils.java

public static URI parseURI(String uriString) throws ParseException {
    Validate.notEmpty(uriString, "uriString");

    URI uri;/*from w  w w . ja v  a  2s  . c om*/
    try {
        uri = new URI(uriString);
    } catch (URISyntaxException e) {
        throw new ParseException("failed to parse uri", e);
    }

    String[] allowedSchemes = { "https" };
    UrlValidator urlValidator = new UrlValidator(allowedSchemes, UrlValidator.ALLOW_LOCAL_URLS);
    if (!urlValidator.isValid(uri.toString())) {
        throw new ParseException("uri is not a valid https url");
    }

    return uri;
}

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;/* w  w w .  j ava  2s  .c  om*/
    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:com.adobe.sign.utils.validator.ApiValidatorHelper.java

/**
 * Helper function to validate the url passed to it.
 *
 * @param url          The url that needs to be validated.
 * @param sdkErrorCode The error message that needs to be thrown.
 * @throws ApiException/*from   w  ww.  j a v a  2  s .  co m*/
 */
public static void validateUrlParameter(String url, SdkErrorCodes sdkErrorCode) throws ApiException {
    UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
    if (!urlValidator.isValid(url))
        throw new ApiException(sdkErrorCode);
}

From source file:elh.eus.absa.MicroTextNormalizer.java

/**
 *  Normalize input String (urls -> URL) 
 * /*from  w w w  .  j ava  2  s.  com*/
 * @param input : input string to normalize
 * @returns String
 */
private static String normalizeURL(String input) {

    //URL normalization
    UrlValidator defaultValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES);

    if (defaultValidator.isValid(input)) {
        return "URLURLURL"; // valid
    } else {
        return input;
    }
}