@Override public String extractRootDirPath(String location) { int prefixEnd = location.indexOf(":") + 1; int rootDirEnd = location.length(); while (rootDirEnd > prefixEnd && getPathMatcher().isPattern(location.substring(prefixEnd, rootDirEnd))) { rootDirEnd = location.lastIndexOf('/', rootDirEnd - 2) + 1; } if (rootDirEnd == 0) { rootDirEnd = prefixEnd; } return location.substring(0, rootDirEnd); }
public PathPatternRequestMatcher(String path,PathMatcher matcher, boolean ignroeCase) { Args.notNull(path); Args.notNull(matcher); this.path = path; this.matcher = matcher; this.isPattern = matcher.isPattern(path); this.ignoreCase = ignroeCase; this.pattern = ignroeCase ? path.toLowerCase() : path; }
protected void parsePatterns(String patterns){ if(!Strings.isEmpty(patterns)){ if(ignoreCase){ patterns = patterns.toLowerCase(); } Set<String> set = new LinkedHashSet<String>(); String[] lines = Strings.splitMultiLines(patterns); for(String line : lines){ if(!Strings.isEmpty(line = line.trim())){ if(!line.startsWith("/")){ line = "/" + line; } if(!patternMatcher.isPattern(line)){ throw new IllegalArgumentException("'" + line + "' is not a valid ant path pattern"); } set.add(line); } } if(!set.isEmpty()){ this.patterns = set.toArray(new String[set.size()]); } } }
public Resource[] scan(String locationPattern) throws IOException { Args.notNull(locationPattern, "Location pattern"); if (locationPattern.startsWith(Urls.CLASSPATH_ALL_URL_PREFIX)) { String locationPatternWithPrefix = locationPattern.substring(Urls.CLASSPATH_ALL_URL_PREFIX.length()); // a class path resource (multiple resources for same name possible) if (getPathMatcher().isPattern(locationPatternWithPrefix)) { // a class path resource pattern return findPathMatchingResources(locationPattern); } else { // all class path resources with the given name return findAllClassPathResources(locationPatternWithPrefix); } } else { // Only look for a pattern after a prefix here // (to not get fooled by a pattern symbol in a strange prefix). int prefixEnd = locationPattern.indexOf(":") + 1; if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) { // a file pattern return findPathMatchingResources(locationPattern); } else { // a single resource with the given name return new Resource[] {getResourceLoader().getResource(locationPattern)}; } } }