[kaffe] CVS kaffe (guilhem): Implemented URL's authorithy generation and URL.toExternalForm() output.

Kaffe CVS cvs-commits at kaffe.org
Wed Dec 31 09:09:01 PST 2003


PatchSet 4254 
Date: 2003/12/31 16:53:50
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Implemented URL's authorithy generation and URL.toExternalForm() output.

Members: 
	ChangeLog:1.1841->1.1842 
	libraries/javalib/java/net/URL.java:1.37->1.38 
	libraries/javalib/java/net/URLStreamHandler.java:1.15->1.16 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1841 kaffe/ChangeLog:1.1842
--- kaffe/ChangeLog:1.1841	Wed Dec 31 15:57:22 2003
+++ kaffe/ChangeLog	Wed Dec 31 16:53:50 2003
@@ -1,3 +1,10 @@
+2003-12-31  Guilhem Lavaux <guilhem at kaffe.org>
+
+	* libraries/javalib/java/net/URL.java,
+	libraries/javalib/java/net/URLStreamHandler.java:
+	Implemented authority string generation and fixed toExternalForm()
+	to use authority directly.
+
 2003-12-31  Mark Huizer <xaa+kaffe at timewasters.nl>
 
 	* libraries/clib/net/InetAddressImpl.c
Index: kaffe/libraries/javalib/java/net/URL.java
diff -u kaffe/libraries/javalib/java/net/URL.java:1.37 kaffe/libraries/javalib/java/net/URL.java:1.38
--- kaffe/libraries/javalib/java/net/URL.java:1.37	Wed Dec 31 09:09:38 2003
+++ kaffe/libraries/javalib/java/net/URL.java	Wed Dec 31 16:53:52 2003
@@ -136,11 +136,15 @@
 
   /**
    * The hostname or IP address of this protocol.
-   * This includes a possible user. For example <code>joe at some.host.net</code>.
    */
   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.
    */
@@ -279,7 +283,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)
@@ -696,14 +702,20 @@
     // 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;
+
+    if (host != null)
+      this.authority += host;
+    if (port >= 0)
+      this.authority += ":" + port;
+
     this.ref = ref;
     hashCode = hashCode();			// Used for serialization.
   }
-
+  
   /**
    * Sets the specified fields of the URL. This is not a public method so
    * that only URLStreamHandlers can modify URL fields. URLs are otherwise
@@ -730,15 +742,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: kaffe/libraries/javalib/java/net/URLStreamHandler.java
diff -u kaffe/libraries/javalib/java/net/URLStreamHandler.java:1.15 kaffe/libraries/javalib/java/net/URLStreamHandler.java:1.16
--- kaffe/libraries/javalib/java/net/URLStreamHandler.java:1.15	Wed Dec 31 09:09:38 2003
+++ kaffe/libraries/javalib/java/net/URLStreamHandler.java	Wed Dec 31 16:53:52 2003
@@ -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))
       {
@@ -140,17 +143,20 @@
         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;
-
+	  
 	// Look for optional port number.  It is valid for the non-port
 	// part of the host name to be null (e.g. a URL "http://:80").
 	// TBD: JDK 1.2 in this case sets host to null rather than "";
@@ -235,13 +241,25 @@
 	    ref = file.substring(hash + 1, file.length());
 	    file = file.substring(0, hash);
 	  }
+      }    
+
+    // 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);
   }
   
   /*
@@ -490,25 +508,21 @@
    */
   protected String toExternalForm(URL u)
   {
-    String protocol, host, file, ref, user;
+    String protocol, authority, file, ref;
     int port;
 
     protocol = u.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 = u.getHost();
-    if (host == null)
-      host = "";
+    authority = u.getAuthority();
+    if (authority == null)
+      authority = "";
 
-    port = u.getPort();
     file = u.getFile();
     ref = u.getRef();
-    user = u.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 != null && protocol.length() > 0)
@@ -517,16 +531,9 @@
 	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);




More information about the kaffe mailing list