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