SUGGESTED FIX
This is a suggested fix, contributed by a Java Licensee - SAP.
SAP would like Sun's opinion on the fix and also for us to consider
including it in the SUN JDK?
-- Fix suggestion --
We prepared a fix for this problem for the SAP JVM 6. It simply re-adds a small
code block in
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.fixURI(String)
that was present in JDK5, but removed in JDK6. This code replaces spaces in file
names by "%20". With this change, parsing files with blanks in path names works
again as expected.
protected static String fixURI(String str) {
// handle platform dependent strings
str = str.replace(java.io.File.separatorChar, '/');
// Windows fix
if (str.length() >= 2) {
char ch1 = str.charAt(1);
// change "C:blah" to "/C:blah"
if (ch1 == ':') {
char ch0 = Character.toUpperCase(str.charAt(0));
if (ch0 >= 'A' && ch0 <= 'Z') {
str = "/" + str;
}
}
// change "//blah" to "file://blah"
else if (ch1 == '/' && str.charAt(0) == '/') {
str = "file:" + str;
}
}
===== begin insert =====
// replace spaces in file names with %20.
// Original comment from JDK5: the following algorithm might not be
// very performant, but people who want to use invalid URI's have to
// pay the price.
int pos = str.indexOf(' ');
if (pos >= 0) {
StringBuilder sb = new StringBuilder(str.length());
// put characters before ' ' into the string builder
for (int i = 0; i < pos; i++)
sb.append(str.charAt(i));
// and %20 for the space
sb.append("%20");
// for the remamining part, also convert ' ' to "%20".
for (int i = pos+1; i < str.length(); i++) {
if (str.charAt(i) == ' ')
sb.append("%20");
else
sb.append(str.charAt(i));
}
str = sb.toString();
}
===== end insert =====
// done
return str;
} // fixURI(String):String
|