URL.java (getPath): New JDK 1.3 method.
authorPer Bothner <per@bothner.com>
Sat, 23 Feb 2002 00:15:49 +0000 (16:15 -0800)
committerPer Bothner <bothner@gcc.gnu.org>
Sat, 23 Feb 2002 00:15:49 +0000 (16:15 -0800)
* java/net/URL.java (getPath):  New JDK 1.3 method.

* java/net/URLStreamHandler.java (parseURL):
It is wrong to prepend '/' to the file part of a relative url.

* java/net/URLStreamHandler.java (parseURL):
Minor optizations - append '/' rather than "/".

* java/net/URLStreamHandler.java (parseURL):
Don't canonicalize "xx/.." or "./" URLs - JDK doesn't.
We probably should canonicalize for a context-relative url, though.
* java/net/URL.java (sameFile):  Delegate to URLStreamHandler.
* java/net/URLStreamHandler.java (canonicalizeFilename):  New helper.
(sameFile):  New method.  Uses canonicalizeFilename.

From-SVN: r49980

libjava/ChangeLog
libjava/java/net/URL.java
libjava/java/net/URLStreamHandler.java

index 72802f6..168abd0 100644 (file)
@@ -1,3 +1,20 @@
+2002-02-20  Per Bothner  <per@bothner.com>
+
+       * java/net/URL.java (getPath):  New JDK 1.3 method.
+
+       * java/net/URLStreamHandler.java (parseURL):
+       It is wrong to prepend '/' to the file part of a relative url.
+
+       * java/net/URLStreamHandler.java (parseURL):
+       Minor optizations - append '/' rather than "/".
+
+       * java/net/URLStreamHandler.java (parseURL):
+       Don't canonicalize "xx/.." or "./" URLs - JDK doesn't.
+       We probably should canonicalize for a context-relative url, though.
+       * java/net/URL.java (sameFile):  Delegate to URLStreamHandler.
+       * java/net/URLStreamHandler.java (canonicalizeFilename):  New helper.
+       (sameFile):  New method.  Uses canonicalizeFilename.
+
 2002-02-22  Tom Tromey  <tromey@redhat.com>
 
        * java/lang/natSystem.cc (init_properties): Include the `Inc.' in
index 636e6ef..a3e9d78 100644 (file)
@@ -1,6 +1,6 @@
 // URL.java - A Uniform Resource Locator.
 
-/* Copyright (C) 1999, 2000  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -219,6 +219,12 @@ public final class URL implements Serializable
     return file;
   }
 
+  public String getPath()
+  {
+    int quest = file.indexOf('?');
+    return quest < 0 ? file : file.substring(0, quest);
+  }
+
   public String getHost()
   {
     return host;
@@ -274,16 +280,7 @@ public final class URL implements Serializable
 
   public boolean sameFile(URL other)
   {
-    // This comparison is very conservative.  It assumes that any
-    // field can be null.
-    return (other != null 
-           && port == other.port
-           && ((protocol == null && other.protocol == null)
-               || (protocol != null && protocol.equals(other.protocol)))
-           && ((host == null && other.host == null)
-               || (host != null && host.equals(other.host)))
-           && ((file == null && other.file == null)
-               || (file != null && file.equals(other.file))));
+    return handler.sameFile(this, other);
   }
 
   protected void set(String protocol, String host, int port, String file,
index 2b646b4..bb3d8e8 100644 (file)
@@ -1,6 +1,6 @@
 // URLStreamHandler.java - Superclass of all stream protocol handlers.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -84,17 +84,20 @@ public abstract class URLStreamHandler
     else if (file == null || file.length() <= 0)
       {
        // No file context available; just spec for file.
-       file = "/" + spec.substring(start, limit);
+       file = spec.substring(start, limit);
       }
     else if (start < limit)
       {
        // Context is available, but only override it if there is a new file.
-        // FIXME: unsure to what extent `/` and File.separatorChar
-       //        can mix in URLs.  Ignore File.separatorChar for now.
        file = file.substring(0, file.lastIndexOf('/'))
-               + "/" + spec.substring(start, limit);
+               + '/' + spec.substring(start, limit);
       }
 
+    u.set(u.getProtocol(), host, port, file, u.getRef());
+  }
+  
+  private static String canonicalizeFilename(String file)
+  {
     int index;
 
     // Replace "/./" with "/".  This probably isn't very efficient in
@@ -113,10 +116,33 @@ public abstract class URLStreamHandler
        else
          break;
       }
-    
-    u.set(u.getProtocol(), host, port, file, u.getRef());
+    return file; 
   }
-  
+
+  public boolean sameFile(URL url1, URL url2)
+  {
+    if (url1 == url2)
+      return true;
+    // This comparison is very conservative.  It assumes that any
+    // field can be null.
+    if (url1 == null || url2 == null || url1.getPort() != url2.getPort())
+      return false;
+    String s1, s2;
+    s1 = url1.getProtocol();
+    s2 = url2.getProtocol();
+    if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
+      return false;
+    s1 = url1.getHost();
+    s2 = url2.getHost();
+    if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
+      return false;
+    s1 = canonicalizeFilename(url1.getFile());
+    s2 = canonicalizeFilename(url2.getFile());
+    if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
+      return false;
+    return true;
+  }
+
   protected void setURL(URL u, String protocol, String host, int port,
                        String file, String ref)
   {