Browse Source

Polish ResourceUrlEncodingFilter

pull/615/merge
Rossen Stoyanchev 10 years ago
parent
commit
f353a28ff4
  1. 23
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java

23
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java

@ -65,19 +65,20 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter { @@ -65,19 +65,20 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter {
@Override
public String encodeURL(String url) {
String name = ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR;
ResourceUrlProvider urlProvider = (ResourceUrlProvider) this.request.getAttribute(name);
if (urlProvider != null) {
String translatedUrl = urlProvider.getForRequestUrl(this.request, url);
if (translatedUrl != null) {
return super.encodeURL(translatedUrl);
}
}
else {
logger.debug("Request attribute exposing ResourceUrlProvider not found under name: " + name);
ResourceUrlProvider resourceUrlProvider = getResourceUrlProvider();
if (resourceUrlProvider == null) {
logger.debug("Request attribute exposing ResourceUrlProvider not found.");
return super.encodeURL(url);
}
return super.encodeURL(url);
String resolvedUrl = resourceUrlProvider.getForRequestUrl(this.request, url);
return (resolvedUrl != null ? super.encodeURL(resolvedUrl) : super.encodeURL(url));
}
private ResourceUrlProvider getResourceUrlProvider() {
String name = ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR;
return (ResourceUrlProvider) this.request.getAttribute(name);
}
}
}

Loading…
Cancel
Save