|
|
@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -43,11 +44,8 @@ import java.util.List; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class PrefixResourceResolver extends AbstractResourceResolver { |
|
|
|
public class PrefixResourceResolver extends AbstractResourceResolver { |
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(PathResourceResolver.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String prefix; |
|
|
|
private final String prefix; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PrefixResourceResolver(String prefix) { |
|
|
|
public PrefixResourceResolver(String prefix) { |
|
|
|
Assert.hasText(prefix, "prefix must not be null or empty"); |
|
|
|
Assert.hasText(prefix, "prefix must not be null or empty"); |
|
|
|
this.prefix = prefix.startsWith("/") ? prefix.substring(1) : prefix; |
|
|
|
this.prefix = prefix.startsWith("/") ? prefix.substring(1) : prefix; |
|
|
@ -57,9 +55,6 @@ public class PrefixResourceResolver extends AbstractResourceResolver { |
|
|
|
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, |
|
|
|
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, |
|
|
|
List<? extends Resource> locations, ResourceResolverChain chain) { |
|
|
|
List<? extends Resource> locations, ResourceResolverChain chain) { |
|
|
|
|
|
|
|
|
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
|
|
|
|
logger.trace("Resolving resource: requestPath=\"" + requestPath + "\""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (requestPath.startsWith(this.prefix)) { |
|
|
|
if (requestPath.startsWith(this.prefix)) { |
|
|
|
requestPath = requestPath.substring(this.prefix.length()); |
|
|
|
requestPath = requestPath.substring(this.prefix.length()); |
|
|
|
} |
|
|
|
} |
|
|
@ -72,7 +67,10 @@ public class PrefixResourceResolver extends AbstractResourceResolver { |
|
|
|
ResourceResolverChain chain) { |
|
|
|
ResourceResolverChain chain) { |
|
|
|
|
|
|
|
|
|
|
|
String baseUrl = chain.resolvePublicUrlPath(resourceUrlPath, locations); |
|
|
|
String baseUrl = chain.resolvePublicUrlPath(resourceUrlPath, locations); |
|
|
|
return this.prefix + (baseUrl.startsWith("/") ? baseUrl : "/" + baseUrl); |
|
|
|
if (StringUtils.hasText(baseUrl)) { |
|
|
|
|
|
|
|
return this.prefix + (baseUrl.startsWith("/") ? baseUrl : "/" + baseUrl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return baseUrl; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|