1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@ public URIEditor() {
69
69
* Create a new URIEditor, converting "classpath:" locations into
70
70
* standard URIs (not trying to resolve them into physical resources).
71
71
* @param encode indicates whether Strings will be encoded or not
72
+ * @since 3.0
72
73
*/
73
74
public URIEditor (boolean encode ) {
74
75
this .classLoader = null ;
@@ -91,6 +92,7 @@ public URIEditor(@Nullable ClassLoader classLoader) {
91
92
* @param classLoader the ClassLoader to use for resolving "classpath:" locations
92
93
* (may be {@code null} to indicate the default ClassLoader)
93
94
* @param encode indicates whether Strings will be encoded or not
95
+ * @since 3.0
94
96
*/
95
97
public URIEditor (@ Nullable ClassLoader classLoader , boolean encode ) {
96
98
this .classLoader = (classLoader != null ? classLoader : ClassUtils .getDefaultClassLoader ());
@@ -103,18 +105,14 @@ public void setAsText(String text) throws IllegalArgumentException {
103
105
if (StringUtils .hasText (text )) {
104
106
String uri = text .trim ();
105
107
if (this .classLoader != null && uri .startsWith (ResourceUtils .CLASSPATH_URL_PREFIX )) {
106
- ClassPathResource resource =
107
- new ClassPathResource ( uri .substring (ResourceUtils .CLASSPATH_URL_PREFIX .length ()), this .classLoader );
108
+ ClassPathResource resource = new ClassPathResource (
109
+ uri .substring (ResourceUtils .CLASSPATH_URL_PREFIX .length ()), this .classLoader );
108
110
try {
109
- String url = resource .getURL ().toString ();
110
- setValue (createURI (url ));
111
+ setValue (resource .getURI ());
111
112
}
112
113
catch (IOException ex ) {
113
114
throw new IllegalArgumentException ("Could not retrieve URI for " + resource + ": " + ex .getMessage ());
114
115
}
115
- catch (URISyntaxException ex ) {
116
- throw new IllegalArgumentException ("Invalid URI syntax: " + ex );
117
- }
118
116
}
119
117
else {
120
118
try {
@@ -131,9 +129,8 @@ public void setAsText(String text) throws IllegalArgumentException {
131
129
}
132
130
133
131
/**
134
- * Create a URI instance for the given (resolved) String value.
135
- * <p>The default implementation encodes the value into a RFC
136
- * 2396 compliant URI.
132
+ * Create a URI instance for the given user-specified String value.
133
+ * <p>The default implementation encodes the value into a RFC-2396 compliant URI.
137
134
* @param value the value to convert into a URI instance
138
135
* @return the URI instance
139
136
* @throws java.net.URISyntaxException if URI conversion failed
0 commit comments