Hi,
Here is a patch for URL.java and URLStreamHandler.java to implement
support for authority and cleanup userInfo handling. I have updated a
small testcase in mauve for authority and there does not seem to be any
regression. Please review.
Cheers,
Guilhem.
ChangeLog entry:
2004-04-20 Guilhem Lavaux <[EMAIL PROTECTED]>
* java/net/URL.java
(userInfo): New field.
(URL): Set authority to the right value.
(getContent, openStream): Made final as in the Java spec.
(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.
Index: java/net/URL.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URL.java,v
retrieving revision 1.26
diff -u -r1.26 URL.java
--- java/net/URL.java 8 Apr 2004 17:25:02 -0000 1.26
+++ java/net/URL.java 20 Apr 2004 06:27:29 -0000
@@ -141,6 +141,11 @@
private String host;
/**
+ * The user information necessary to establish the connection.
+ */
+ private String userInfo;
+
+ /**
* The port number of this protocol or -1 if the port number used is
* the default for this protocol.
*/
@@ -276,7 +281,9 @@
this.host = host;
this.port = port;
- this.authority = null;
+ this.authority = (host != null) ? host : "";
+ if (port >= 0)
+ this.authority += ":" + port;
int hashAt = file.indexOf('#');
if (hashAt < 0)
@@ -480,7 +487,7 @@
*
* @since 1.3
*/
- public Object getContent() throws IOException
+ public final Object getContent() throws IOException
{
return openConnection().getContent();
}
@@ -494,7 +501,7 @@
*
* @exception IOException If an error occurs
*/
- public Object getContent(Class[] classes) throws IOException
+ public final Object getContent(Class[] classes) throws IOException
{
// FIXME: implement this
return getContent();
@@ -653,7 +660,7 @@
*
* @exception IOException If an error occurs
*/
- public InputStream openStream() throws IOException
+ public final InputStream openStream() throws IOException
{
return openConnection().getInputStream();
}
@@ -694,11 +701,17 @@
// be aware of this.
this.ph = getURLStreamHandler(protocol);
this.protocol = protocol.toLowerCase();
- this.authority = null;
+ this.authority = "";
this.port = port;
this.host = host;
this.file = file;
this.ref = ref;
+
+ if (host != null)
+ this.authority += host;
+ if (port >= 0)
+ this.authority += ":" + port;
+
hashCode = hashCode(); // Used for serialization.
}
@@ -727,15 +740,15 @@
// be aware of this.
this.ph = getURLStreamHandler(protocol);
this.protocol = protocol.toLowerCase();
- if (userInfo == null)
- this.host = host;
- else
- this.host = userInfo + "@" + host;
+ this.host = host;
+ this.userInfo = userInfo;
this.port = port;
+ this.file = path;
+ this.authority = authority;
if (query == null)
- this.file = path;
+ this.file = file;
else
- this.file = path + "?" + query;
+ this.file = file + "?" + query;
this.ref = ref;
hashCode = hashCode(); // Used for serialization.
}
Index: java/net/URLStreamHandler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLStreamHandler.java,v
retrieving revision 1.26
diff -u -r1.26 URLStreamHandler.java
--- java/net/URLStreamHandler.java 8 Apr 2004 17:25:02 -0000 1.26
+++ java/net/URLStreamHandler.java 20 Apr 2004 06:27:29 -0000
@@ -126,6 +126,9 @@
int port = url.getPort();
String file = url.getFile();
String ref = url.getRef();
+ String userInfo = url.getUserInfo();
+ String authority = url.getAuthority();
+ String query = null;
if (spec.regionMatches(start, "//", 0, 2))
{
@@ -141,14 +144,17 @@
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;
@@ -238,10 +244,21 @@
}
}
+ // 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 +509,31 @@
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);
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath