Example usage for org.springframework.util AntPathMatcher isPattern

List of usage examples for org.springframework.util AntPathMatcher isPattern

Introduction

In this page you can find the example usage for org.springframework.util AntPathMatcher isPattern.

Prototype

@Override
    public boolean isPattern(@Nullable String path) 

Source Link

Usage

From source file:com.ge.predix.uaa.token.lib.DefaultZoneConfiguration.java

@Required
public void setAllowedUriPatterns(final List<String> allowedUriPatterns) {
    AntPathMatcher matcher = new AntPathMatcher();

    for (String pattern : allowedUriPatterns) {
        if (!matcher.isPattern(pattern)) {
            throw new IllegalArgumentException("Invalid pattern: " + pattern);
        }//from  ww w .j av a  2s .  c o  m
    }
    this.allowedUriPatterns = allowedUriPatterns;
}

From source file:com.cloudbees.plugins.credentials.domains.PathSpecification.java

/**
 * {@inheritDoc}/*from ww  w  .  j  a v  a2 s  . c  om*/
 */
@NonNull
@Override
public Result test(@NonNull DomainRequirement requirement) {
    if (requirement instanceof PathRequirement) {
        final AntPathMatcher matcher = new AntPathMatcher();
        String path = ((PathRequirement) requirement).getPath();
        if (!caseSensitive) {
            path = path.toLowerCase();
        }
        if (includes != null) {
            boolean isInclude = false;
            for (String include : includes.split(",")) {
                include = Util.fixEmptyAndTrim(include);
                if (include == null) {
                    continue;
                }
                if (!caseSensitive) {
                    include = include.toLowerCase();
                }
                if (matcher.isPattern(include) ? matcher.match(include, path)
                        : StringUtils.equals(include, path)) {
                    isInclude = true;
                    break;
                }
            }
            if (!isInclude) {
                return Result.NEGATIVE;
            }
        }
        if (excludes != null) {
            boolean isExclude = false;
            for (String exclude : excludes.split(",")) {
                exclude = Util.fixEmptyAndTrim(exclude);
                if (exclude == null) {
                    continue;
                }
                if (!caseSensitive) {
                    exclude = exclude.toLowerCase();
                }
                if (matcher.isPattern(exclude) ? matcher.match(exclude, path)
                        : StringUtils.equals(exclude, path)) {
                    isExclude = true;
                    break;
                }
            }
            if (isExclude) {
                return Result.NEGATIVE;
            }
        }
        return Result.PARTIAL;
    }
    return Result.UNKNOWN;
}

From source file:org.cloudfoundry.identity.uaa.oauth.DisableIdTokenResponseTypeFilter.java

protected boolean applyPath(String path) {
    if (paths == null || paths.size() == 0 || path == null) {
        return false;
    }/*w  w w  .  j  av a2 s. c o m*/
    AntPathMatcher matcher = new AntPathMatcher();
    for (String pattern : paths) {
        if (matcher.isPattern(pattern)) {
            if (matcher.match(pattern, path)) {
                return true;
            }
        } else { //exact match
            if (pattern.equals(path)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.jumpmind.metl.core.runtime.component.FilePoller.java

protected List<FileInfo> matchFiles(String pattern, IDirectory resourceDirectory, AntPathMatcher pathMatcher) {

    StringBuilder subPartToMatch = new StringBuilder();
    List<FileInfo> fileMatches = new ArrayList<FileInfo>();
    String[] patternParts = pattern.split("/");

    for (int i = 0; i < patternParts.length; i++) {
        if (i != patternParts.length - 1) {
            // directory specifications
            if (!pathMatcher.isPattern(patternParts[i])) {
                // fixed path with no wildcards
                if (subPartToMatch.length() > 0) {
                    subPartToMatch.append("/");
                }/*w  w  w. j  a v a 2  s  . c om*/
                subPartToMatch.append(patternParts[i]);
            } else {
                // some type of wildcard pattern in a relative directory
                List<FileInfo> childFileMatches = listFilesAndDirsFromDirectory(subPartToMatch.toString(),
                        patternParts[i], resourceDirectory, pathMatcher);
                String childPartToMatch = null;
                String remainderPath = "";
                for (int j = i + 1; j < patternParts.length; j++) {
                    remainderPath = remainderPath + patternParts[j];
                    if (j != patternParts.length - 1) {
                        remainderPath = remainderPath + "/";
                    }
                }
                for (FileInfo fileInfo : childFileMatches) {
                    if (fileInfo.isDirectory()) {
                        childPartToMatch = subPartToMatch + "/" + fileInfo.getName() + "/" + remainderPath;
                        fileMatches.addAll(matchFiles(childPartToMatch, resourceDirectory, pathMatcher));
                    }
                }
            }
        }
    }
    fileMatches.addAll(listFilesAndDirsFromDirectory(subPartToMatch.toString(),
            patternParts[patternParts.length - 1], resourceDirectory, pathMatcher));

    return fileMatches;
}