Polish PathMatchingResourcePatternResolver
This commit is contained in:
parent
5e979af95a
commit
4515180195
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -279,13 +279,14 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||||
Assert.notNull(locationPattern, "Location pattern must not be null");
|
Assert.notNull(locationPattern, "Location pattern must not be null");
|
||||||
if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) {
|
if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) {
|
||||||
// a class path resource (multiple resources for same name possible)
|
// a class path resource (multiple resources for same name possible)
|
||||||
if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) {
|
String locationPatternWithoutPrefix = locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length());
|
||||||
|
if (getPathMatcher().isPattern(locationPatternWithoutPrefix)) {
|
||||||
// a class path resource pattern
|
// a class path resource pattern
|
||||||
return findPathMatchingResources(locationPattern);
|
return findPathMatchingResources(locationPattern);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// all class path resources with the given name
|
// all class path resources with the given name
|
||||||
return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));
|
return findAllClassPathResources(locationPatternWithoutPrefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -314,13 +315,10 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||||
* @see #convertClassLoaderURL
|
* @see #convertClassLoaderURL
|
||||||
*/
|
*/
|
||||||
protected Resource[] findAllClassPathResources(String location) throws IOException {
|
protected Resource[] findAllClassPathResources(String location) throws IOException {
|
||||||
String path = location;
|
String path = stripLeadingSlash(location);
|
||||||
if (path.startsWith("/")) {
|
|
||||||
path = path.substring(1);
|
|
||||||
}
|
|
||||||
Set<Resource> result = doFindAllClassPathResources(path);
|
Set<Resource> result = doFindAllClassPathResources(path);
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Resolved classpath location [" + location + "] to resources " + result);
|
logger.trace("Resolved classpath location [" + path + "] to resources " + result);
|
||||||
}
|
}
|
||||||
return result.toArray(new Resource[0]);
|
return result.toArray(new Resource[0]);
|
||||||
}
|
}
|
||||||
|
|
@ -833,6 +831,11 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static String stripLeadingSlash(String path) {
|
||||||
|
return (path.startsWith("/") ? path.substring(1) : path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
|
* Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue