From 141410702d2753052385e841596a13c4a870b7d7 Mon Sep 17 00:00:00 2001 From: mkoch Date: Thu, 22 Apr 2004 07:02:26 +0000 Subject: [PATCH] 2004-04-22 Jeroen Frijters * java/net/URLStreamHandler.java (parseURL): Convert the file path to using '/' instead of native file separator. 2004-04-22 Guilhem Lavaux * java/net/URL.java (userInfo): New field. (URL): Set authority to the right value. (setURL): Fixed authority and file initialization. * java/net/URLStreamHandler.java (parseURL): Take care of the query tag. Build authority. (toExternalForm): Fixed URL building using authority. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@81006 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 16 ++++++++ libjava/java/net/URLConnection.java | 20 +++++----- libjava/java/net/URLStreamHandler.java | 71 ++++++++++++++++++---------------- 3 files changed, 64 insertions(+), 43 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 60990f9..230e0ae 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,19 @@ +2004-04-22 Jeroen Frijters + + * java/net/URLStreamHandler.java + (parseURL): Convert the file path to using '/' instead of native + file separator. + +2004-04-22 Guilhem Lavaux + + * java/net/URL.java + (userInfo): New field. + (URL): Set authority to the right value. + (setURL): Fixed authority and file initialization. + * java/net/URLStreamHandler.java + (parseURL): Take care of the query tag. Build authority. + (toExternalForm): Fixed URL building using authority. + 2004-04-22 Michael Koch * java/net/Socket.java diff --git a/libjava/java/net/URLConnection.java b/libjava/java/net/URLConnection.java index 6b12568..39fbd32 100644 --- a/libjava/java/net/URLConnection.java +++ b/libjava/java/net/URLConnection.java @@ -108,7 +108,7 @@ public abstract class URLConnection * This is the default value that will be used to determine whether or * not user interaction should be allowed. */ - private static boolean defaultAllowUserInteraction = false; + private static boolean defaultAllowUserInteraction; /** * This is the default flag indicating whether or not to use caches to @@ -126,7 +126,7 @@ public abstract class URLConnection * Indicates whether or not a connection has been established to the * destination specified in the URL */ - protected boolean connected = false; + protected boolean connected; /** * Indicates whether or not input can be read from this URL @@ -136,7 +136,7 @@ public abstract class URLConnection /** * Indicates whether or not output can be sent to this URL */ - protected boolean doOutput = false; + protected boolean doOutput; /** * If this flag is set, the protocol is allowed to cache data whenever @@ -157,7 +157,7 @@ public abstract class URLConnection * modified more recently than the date set in this variable. That date * should be specified as the number of seconds since 1/1/1970 GMT. */ - protected long ifModifiedSince = 0L; + protected long ifModifiedSince; /** * This is the URL associated with this connection @@ -165,8 +165,10 @@ public abstract class URLConnection protected URL url; private static Hashtable handlers = new Hashtable(); - private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3; - private static boolean dateformats_initialized = false; + private static SimpleDateFormat dateFormat1; + private static SimpleDateFormat dateFormat2; + private static SimpleDateFormat dateFormat3; + private static boolean dateformats_initialized; /** * Creates a URL connection to a given URL. A real connection is not made. @@ -430,10 +432,10 @@ public abstract class URLConnection String type = getContentType(); ContentHandler ch = setContentHandler(type); - if (ch == null) - return getInputStream(); + if (ch != null) + return ch.getContent(this); - return ch.getContent(this); + return getInputStream(); } /** diff --git a/libjava/java/net/URLStreamHandler.java b/libjava/java/net/URLStreamHandler.java index 0e2f0c2..509e7f4 100644 --- a/libjava/java/net/URLStreamHandler.java +++ b/libjava/java/net/URLStreamHandler.java @@ -126,6 +126,13 @@ public abstract class URLStreamHandler int port = url.getPort(); String file = url.getFile(); String ref = url.getRef(); + String userInfo = url.getUserInfo(); + String authority = url.getAuthority(); + String query = null; + + // On Windows we need to change \ to / for file URLs + if (url.getProtocol().equals("file")) + spec = spec.replace(File.separatorChar, '/'); if (spec.regionMatches(start, "//", 0, 2)) { @@ -141,14 +148,17 @@ public abstract class URLStreamHandler else hostEnd = end; - host = spec.substring(start, hostEnd); + authority = host = spec.substring(start, hostEnd); // We first need a genuine host name (with userinfo). // So we check for '@': if it's present check the port in the // section after '@' in the other case check it in the full string. // P.S.: We don't care having '@' at the beginning of the string. if ((at_host = host.indexOf('@')) >= 0) - genuineHost = host.substring(at_host); + { + genuineHost = host.substring(at_host); + userInfo = host.substring(0, at_host); + } else genuineHost = host; @@ -193,18 +203,10 @@ public abstract class URLStreamHandler else if (start < end) { // Context is available, but only override it if there is a new file. - char sepChar = '/'; - int lastSlash = file.lastIndexOf(sepChar); - if (lastSlash < 0 && File.separatorChar != sepChar - && url.getProtocol().equals("file")) - { - // On Windows, even '\' is allowed in a "file" URL. - sepChar = File.separatorChar; - lastSlash = file.lastIndexOf(sepChar); - } + int lastSlash = file.lastIndexOf('/'); file = - file.substring(0, lastSlash) + sepChar + spec.substring(start, end); + file.substring(0, lastSlash) + '/' + spec.substring(start, end); if (url.getProtocol().equals("file")) { @@ -214,6 +216,7 @@ public abstract class URLStreamHandler { boolean endsWithSlash = file.charAt(file.length() - 1) == '/'; file = new File(file).getCanonicalPath(); + file = file.replace(File.separatorChar, '/'); if (endsWithSlash && file.charAt(file.length() - 1) != '/') file += '/'; } @@ -238,10 +241,21 @@ public abstract class URLStreamHandler } } + // We care about the query tag only if there is no reference at all. + if (ref == null) + { + int queryTag = file.indexOf('?'); + if (queryTag != -1) + { + query = file.substring(queryTag + 1); + file = file.substring(0, queryTag); + } + } + // XXX - Classpath used to call PlatformHelper.toCanonicalForm() on // the file part. It seems like overhead, but supposedly there is some // benefit in windows based systems (it also lowercased the string). - setURL(url, url.getProtocol(), host, port, file, ref); + setURL(url, url.getProtocol(), host, port, authority, userInfo, file, query, ref); } /* @@ -492,42 +506,31 @@ public abstract class URLStreamHandler String file; String ref; String user; + String authority; int port; protocol = url.getProtocol(); - - // JDK 1.2 online doc infers that host could be null because it - // explicitly states that file cannot be null, but is silent on host. - host = url.getHost(); - if (host == null) - host = ""; - - port = url.getPort(); + authority = url.getAuthority(); + if (authority == null) + authority = ""; + file = url.getFile(); ref = url.getRef(); - user = url.getUserInfo(); // Guess a reasonable size for the string buffer so we have to resize // at most once. - int size = protocol.length() + host.length() + file.length() + 24; + int size = protocol.length() + authority.length() + file.length() + 24; StringBuffer sb = new StringBuffer(size); - if (protocol.length() != 0) + if (protocol != null && protocol.length() > 0) { sb.append(protocol); sb.append(":"); } - - if (host.length() != 0) + + if (authority.length() != 0) { - sb.append("//"); - if (user != null && ! "".equals(user)) - sb.append(user).append('@'); - sb.append(host); - - // Append port if port was in URL spec. - if (port >= 0) - sb.append(':').append(port); + sb.append("//").append(authority); } sb.append(file); -- 2.7.4