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

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

Introduction

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

Prototype

long NO_FRAGMENTS

To view the source code for org.apache.commons.validator.routines UrlValidator NO_FRAGMENTS.

Click Source Link

Document

Enabling this options disallows any URL fragments.

Usage

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:org.geoserver.security.iride.util.factory.util.UrlValidatorFactory.java

@Override
protected final UrlValidator newInstance() {
    return new UrlValidator(new String[] { "http", "https" },
            UrlValidator.NO_FRAGMENTS + UrlValidator.ALLOW_LOCAL_URLS);
}

From source file:org.geoserver.security.iride.util.factory.validator.UrlValidatorFactory.java

@Override
protected final UrlValidator newInstance() {
    return new UrlValidator(new String[] { "http", "https" }, UrlValidator.NO_FRAGMENTS);
}

From source file:org.lirazs.gbackbone.validation.client.rule.UrlRule.java

@Override
public boolean isValid(final String url, String attribute) {
    String[] schemes = ruleAnnotation.schemes();
    long options = ruleAnnotation.allowFragments() ? 0 : UrlValidator.NO_FRAGMENTS;

    UrlValidator urlValidator = schemes != null && schemes.length > 0 ? new UrlValidator(schemes, options)
            : UrlValidator.getInstance();

    return urlValidator.isValid(url);
}

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  www.j  av  a 2s.  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);
    }
}