diff --git a/openide.filesystems/src/org/openide/filesystems/NbfsUtil.java b/openide.filesystems/src/org/openide/filesystems/NbfsUtil.java --- a/openide.filesystems/src/org/openide/filesystems/NbfsUtil.java +++ b/openide.filesystems/src/org/openide/filesystems/NbfsUtil.java @@ -42,9 +42,9 @@ package org.openide.filesystems; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URL; import java.net.URLDecoder; -import java.net.URLEncoder; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -57,6 +57,8 @@ final class NbfsUtil { /** url separator */ private static final char SEPARATOR = '/'; + /** old host name field prior to #39613 */ + private static final String HOST = "nbhost"; // NOI18N /** * Gets URL with nbfs protocol for passes fo @@ -64,13 +66,7 @@ * @return url with nbfs protocol * @throws FileStateInvalidException if FileObject somehow corrupted */ - static URL getURL(FileObject fo) throws FileStateInvalidException { - final String fsPart = encodeFsPart(fo); - final String foPart = encodeFoPart(fo); - - final String host = "nbhost"; //NOI18N - final String file = combine(fsPart, foPart); - + static URL getURL(final FileObject fo) throws FileStateInvalidException { // #13038: the URL constructor accepting a handler is a security-sensitive // operation. Sometimes a user class loaded internally (customized bean...), // which has no privileges, needs to make and use an nbfs: URL, since this @@ -79,8 +75,7 @@ return AccessController.doPrivileged( new PrivilegedExceptionAction() { public URL run() throws Exception { - // #30397: the fsPart name cannot be null - return new URL(FileURL.PROTOCOL, host, -1, file, new FileURL.Handler()); + return new URI(FileURL.PROTOCOL, fo.getFileSystem().getSystemName(), "/" + fo.getPath(), null).toURL(); } } ); @@ -92,14 +87,6 @@ } } - private static String combine(final String host, final String file) { - StringBuffer sb = new StringBuffer(); - sb.append(SEPARATOR).append(host); - sb.append(file); - - return sb.toString(); - } - private static String[] split(URL url) { String file = url.getFile(); int idx = file.indexOf("/", 1); @@ -125,45 +112,28 @@ return null; } - if (isOldEncoding(url)) { + String host = url.getHost(); + + if (host == null || host.length() == 0) { return oldDecode(url); } - String[] urlParts = split(url); + String fsName, foName; + if (host.equals(HOST)) { + String[] urlParts = split(url); - String fsName = decodeFsPart(urlParts[0]); - String foName = decodeFoPart(urlParts[1]); + fsName = decodeFsPart(urlParts[0]); + foName = decodeFoPart(urlParts[1]); + } else { + fsName = host; + foName = url.getPath().substring(1); + } FileSystem fsys = Repository.getDefault().findFileSystem(fsName); return (fsys == null) ? null : fsys.findResource(foName); } - private static String encodeFsPart(FileObject fo) throws FileStateInvalidException { - FileSystem fs = fo.getFileSystem(); - - return encoder(fs.getSystemName()); - } - - private static String encodeFoPart(FileObject fo) { - StringTokenizer elemsEnum; - StringBuffer sBuff = new StringBuffer(); - elemsEnum = new StringTokenizer(fo.getPath(), String.valueOf(SEPARATOR)); - - while (elemsEnum.hasMoreElements()) { - sBuff.append(SEPARATOR); - sBuff.append(encoder((String) elemsEnum.nextElement())); - } - - String retVal = sBuff.toString(); - - if ((retVal.length() == 0) || (fo.isFolder() && (retVal.charAt(retVal.length() - 1) != SEPARATOR))) { - retVal += SEPARATOR; - } - - return retVal; - } - private static String decodeFsPart(String encodedStr) { return decoder(encodedStr); } @@ -185,14 +155,6 @@ return sBuff.toString(); } - private static String encoder(String elem) { - try { - return URLEncoder.encode(elem, "UTF-8"); // NOI18N - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } - } - private static String decoder(String elem) { try { return URLDecoder.decode(elem, "UTF-8"); // NOI18N @@ -201,13 +163,6 @@ } } - // backward compatibility - private static boolean isOldEncoding(URL url) { - String host = url.getHost(); - - return (host == null) || (host.length() == 0); - } - private static FileObject oldDecode(URL u) { String resourceName = u.getFile(); diff --git a/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java b/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java --- a/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java +++ b/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java @@ -330,7 +330,7 @@ Handler handler = new Handler(DTD_MAP, rootElem = new ResourceElem(true, urls, null), validate); // NOI18N try { - _setSystemName("XML_" + urls[0].toExternalForm().replace('/','-')); // NOI18N + _setSystemName(urls[0].toExternalForm()); } catch (PropertyVetoException pvx) { rootElem = null; throw pvx; diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/FileObjectTestHid.java b/openide.filesystems/test/unit/src/org/openide/filesystems/FileObjectTestHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/FileObjectTestHid.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/FileObjectTestHid.java @@ -2727,6 +2727,7 @@ assertNotNull("had a URL for " + f1, u1); URI uri1 = new URI(u1.toExternalForm()); String path1 = uri1.getPath(); + System.err.println("XXX u1=" + u1 + " uri1=" + uri1 + " path1=" + path1); if (path1 != null) { assertTrue("path of " + uri1 + " ends with /", path1.endsWith("/")); String path2 = path1 + f2.getNameExt();