Browse Source

URIEditor uses straight ClassPathResource.getURI() access

Issue: SPR-16581
pull/999/merge
Juergen Hoeller 8 years ago
parent
commit
499128dae7
  1. 19
      spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java

19
spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -69,6 +69,7 @@ public class URIEditor extends PropertyEditorSupport {
* Create a new URIEditor, converting "classpath:" locations into * Create a new URIEditor, converting "classpath:" locations into
* standard URIs (not trying to resolve them into physical resources). * standard URIs (not trying to resolve them into physical resources).
* @param encode indicates whether Strings will be encoded or not * @param encode indicates whether Strings will be encoded or not
* @since 3.0
*/ */
public URIEditor(boolean encode) { public URIEditor(boolean encode) {
this.classLoader = null; this.classLoader = null;
@ -91,6 +92,7 @@ public class URIEditor extends PropertyEditorSupport {
* @param classLoader the ClassLoader to use for resolving "classpath:" locations * @param classLoader the ClassLoader to use for resolving "classpath:" locations
* (may be {@code null} to indicate the default ClassLoader) * (may be {@code null} to indicate the default ClassLoader)
* @param encode indicates whether Strings will be encoded or not * @param encode indicates whether Strings will be encoded or not
* @since 3.0
*/ */
public URIEditor(@Nullable ClassLoader classLoader, boolean encode) { public URIEditor(@Nullable ClassLoader classLoader, boolean encode) {
this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
@ -103,18 +105,14 @@ public class URIEditor extends PropertyEditorSupport {
if (StringUtils.hasText(text)) { if (StringUtils.hasText(text)) {
String uri = text.trim(); String uri = text.trim();
if (this.classLoader != null && uri.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) { if (this.classLoader != null && uri.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
ClassPathResource resource = ClassPathResource resource = new ClassPathResource(
new ClassPathResource(uri.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), this.classLoader); uri.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), this.classLoader);
try { try {
String url = resource.getURL().toString(); setValue(resource.getURI());
setValue(createURI(url));
} }
catch (IOException ex) { catch (IOException ex) {
throw new IllegalArgumentException("Could not retrieve URI for " + resource + ": " + ex.getMessage()); throw new IllegalArgumentException("Could not retrieve URI for " + resource + ": " + ex.getMessage());
} }
catch (URISyntaxException ex) {
throw new IllegalArgumentException("Invalid URI syntax: " + ex);
}
} }
else { else {
try { try {
@ -131,9 +129,8 @@ public class URIEditor extends PropertyEditorSupport {
} }
/** /**
* Create a URI instance for the given (resolved) String value. * Create a URI instance for the given user-specified String value.
* <p>The default implementation encodes the value into a RFC * <p>The default implementation encodes the value into a RFC-2396 compliant URI.
* 2396 compliant URI.
* @param value the value to convert into a URI instance * @param value the value to convert into a URI instance
* @return the URI instance * @return the URI instance
* @throws java.net.URISyntaxException if URI conversion failed * @throws java.net.URISyntaxException if URI conversion failed

Loading…
Cancel
Save