[multiple changes]
authorMichael Koch <mkoch@gcc.gnu.org>
Thu, 22 Apr 2004 07:02:26 +0000 (07:02 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Thu, 22 Apr 2004 07:02:26 +0000 (07:02 +0000)
2004-04-22  Jeroen Frijters <jeroen@sumatra.nl>

* java/net/URLStreamHandler.java
(parseURL): Convert the file path to using '/' instead of native
file separator.

2004-04-22  Guilhem Lavaux <guilhem@kaffe.org>

* 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.

From-SVN: r81006

libjava/ChangeLog
libjava/java/net/URLConnection.java
libjava/java/net/URLStreamHandler.java

index 60990f981bc89133affece8c905fddc5dcb8fe72..230e0ae66e5914049e7cc6d76ada55e8eb1c1e1d 100644 (file)
@@ -1,3 +1,19 @@
+2004-04-22  Jeroen Frijters <jeroen@sumatra.nl>
+
+       * java/net/URLStreamHandler.java
+       (parseURL): Convert the file path to using '/' instead of native
+       file separator.
+
+2004-04-22  Guilhem Lavaux <guilhem@kaffe.org>
+
+       * 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  <konqueror@gmx.de>
 
        * java/net/Socket.java
index 6b125680cacae448053d841971fd0cbde6f533df..39fbd32ec2812707fce6a47ae13bba55dc778f07 100644 (file)
@@ -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();
   }
 
   /**
index 0e2f0c2b0781bb2c1305341b34d5887e9107bab3..509e7f415866820bf10eb2b5c46e2cb51ea37550 100644 (file)
@@ -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);