Hi,
I was trying to support the platforms who are not supporting ftp
protocol when I have found that setURL has a different behaviour in the
JDK. If the given protocol does not exist it just ignores it and keep
the previous one. This gives us the possibility to call setURL without
any problems on all platforms now.
ChangeLog entry:
2004-04-23 Guilhem Lavaux <[EMAIL PROTECTED]>
* gnu/java/net/protocol/file/Handler.java
(parseURL): Added a comment on ftp implementation in GNU
Classpath.
* java/net/URL.java
(set): This method now matches the behaviour of the JDK.
Cheers,
Guilhem.
Index: gnu/java/net/protocol/file/Handler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/net/protocol/file/Handler.java,v
retrieving revision 1.15
diff -u -r1.15 Handler.java
--- gnu/java/net/protocol/file/Handler.java 23 Apr 2004 06:44:08 -0000 1.15
+++ gnu/java/net/protocol/file/Handler.java 23 Apr 2004 10:00:40 -0000
@@ -79,8 +79,11 @@
// Reset the protocol (and implicitly the handler) for this URL.
// Then have the URL attempt the connection again, as it will
// get the changed handler the next time around.
+ // N.B.: FTP protocol is not supported by default in GNU Classpath
+ // but it does not matter because setURL will keep the current protocol
+ // if "ftp" is not available.
setURL (url, "ftp", url.getHost(), url.getPort(), url.getFile(),
- url.getRef());
+ url.getRef());
return url.openConnection();
}
Index: java/net/URL.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URL.java,v
retrieving revision 1.27
diff -u -r1.27 URL.java
--- java/net/URL.java 20 Apr 2004 16:29:11 -0000 1.27
+++ java/net/URL.java 23 Apr 2004 10:00:41 -0000
@@ -121,7 +121,7 @@
public final class URL implements Serializable
{
private static final String DEFAULT_SEARCH_PATH =
- "gnu.java.net.protocol|sun.net.www.protocol";
+ "gnu.java.net.protocol|gnu.inet|sun.net.www.protocol";
/**
* The name of the protocol for this URL.
@@ -684,7 +684,8 @@
* Sets the specified fields of the URL. This is not a public method so
* that only URLStreamHandlers can modify URL fields. This might be called
* by the <code>parseURL()</code> method in that class. URLs are otherwise
- * constant.
+ * constant. If the given protocol does not exist, it will keep the previously
+ * set protocol.
*
* @param protocol The protocol name for this URL
* @param host The hostname or IP address for this URL
@@ -695,12 +696,15 @@
protected void set(String protocol, String host, int port, String file,
String ref)
{
- // TBD: Theoretically, a poorly written StreamHandler could pass an
- // invalid protocol. It will cause the handler to be set to null
- // thus overriding a valid handler. Callers of this method should
- // be aware of this.
- this.ph = getURLStreamHandler(protocol);
- this.protocol = protocol.toLowerCase();
+ URLStreamHandler protocolHandler = getURLStreamHandler(protocol);
+
+ // It is an hidden feature of the JDK. If the protocol does not exist,
+ // we keep the previously initialized protocol.
+ if (protocolHandler != null)
+ {
+ this.ph = protocolHandler;
+ this.protocol = protocol.toLowerCase();
+ }
this.authority = "";
this.port = port;
this.host = host;
@@ -718,7 +722,8 @@
/**
* Sets the specified fields of the URL. This is not a public method so
* that only URLStreamHandlers can modify URL fields. URLs are otherwise
- * constant.
+ * constant. If the given protocol does not exist, it will keep the previously
+ * set protocol.
*
* @param protocol The protocol name for this URL.
* @param host The hostname or IP address for this URL.
@@ -734,12 +739,15 @@
protected void set(String protocol, String host, int port, String authority,
String userInfo, String path, String query, String ref)
{
- // TBD: Theoretically, a poorly written StreamHandler could pass an
- // invalid protocol. It will cause the handler to be set to null
- // thus overriding a valid handler. Callers of this method should
- // be aware of this.
- this.ph = getURLStreamHandler(protocol);
- this.protocol = protocol.toLowerCase();
+ URLStreamHandler protocolHandler = getURLStreamHandler(protocol);
+
+ // It is an hidden feature of the JDK. If the protocol does not exist,
+ // we keep the previously initialized protocol.
+ if (protocolHandler != null)
+ {
+ this.ph = protocolHandler;
+ this.protocol = protocol.toLowerCase();
+ }
this.host = host;
this.userInfo = userInfo;
this.port = port;
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath