Commit e930d01a by Michael Koch

[multiple changes]

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
parent 5d79367d
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> 2004-04-22 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java * java/net/Socket.java
......
...@@ -108,7 +108,7 @@ public abstract class URLConnection ...@@ -108,7 +108,7 @@ public abstract class URLConnection
* This is the default value that will be used to determine whether or * This is the default value that will be used to determine whether or
* not user interaction should be allowed. * 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 * This is the default flag indicating whether or not to use caches to
...@@ -126,7 +126,7 @@ public abstract class URLConnection ...@@ -126,7 +126,7 @@ public abstract class URLConnection
* Indicates whether or not a connection has been established to the * Indicates whether or not a connection has been established to the
* destination specified in the URL * destination specified in the URL
*/ */
protected boolean connected = false; protected boolean connected;
/** /**
* Indicates whether or not input can be read from this URL * Indicates whether or not input can be read from this URL
...@@ -136,7 +136,7 @@ public abstract class URLConnection ...@@ -136,7 +136,7 @@ public abstract class URLConnection
/** /**
* Indicates whether or not output can be sent to this URL * 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 * If this flag is set, the protocol is allowed to cache data whenever
...@@ -157,7 +157,7 @@ public abstract class URLConnection ...@@ -157,7 +157,7 @@ public abstract class URLConnection
* modified more recently than the date set in this variable. That date * 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. * 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 * This is the URL associated with this connection
...@@ -165,8 +165,10 @@ public abstract class URLConnection ...@@ -165,8 +165,10 @@ public abstract class URLConnection
protected URL url; protected URL url;
private static Hashtable handlers = new Hashtable(); private static Hashtable handlers = new Hashtable();
private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3; private static SimpleDateFormat dateFormat1;
private static boolean dateformats_initialized = false; 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. * Creates a URL connection to a given URL. A real connection is not made.
...@@ -430,10 +432,10 @@ public abstract class URLConnection ...@@ -430,10 +432,10 @@ public abstract class URLConnection
String type = getContentType(); String type = getContentType();
ContentHandler ch = setContentHandler(type); ContentHandler ch = setContentHandler(type);
if (ch == null) if (ch != null)
return getInputStream(); return ch.getContent(this);
return ch.getContent(this); return getInputStream();
} }
/** /**
......
...@@ -126,6 +126,13 @@ public abstract class URLStreamHandler ...@@ -126,6 +126,13 @@ public abstract class URLStreamHandler
int port = url.getPort(); int port = url.getPort();
String file = url.getFile(); String file = url.getFile();
String ref = url.getRef(); 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)) if (spec.regionMatches(start, "//", 0, 2))
{ {
...@@ -141,14 +148,17 @@ public abstract class URLStreamHandler ...@@ -141,14 +148,17 @@ public abstract class URLStreamHandler
else else
hostEnd = end; hostEnd = end;
host = spec.substring(start, hostEnd); authority = host = spec.substring(start, hostEnd);
// We first need a genuine host name (with userinfo). // We first need a genuine host name (with userinfo).
// So we check for '@': if it's present check the port in the // 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. // 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. // P.S.: We don't care having '@' at the beginning of the string.
if ((at_host = host.indexOf('@')) >= 0) if ((at_host = host.indexOf('@')) >= 0)
genuineHost = host.substring(at_host); {
genuineHost = host.substring(at_host);
userInfo = host.substring(0, at_host);
}
else else
genuineHost = host; genuineHost = host;
...@@ -193,18 +203,10 @@ public abstract class URLStreamHandler ...@@ -193,18 +203,10 @@ public abstract class URLStreamHandler
else if (start < end) else if (start < end)
{ {
// Context is available, but only override it if there is a new file. // Context is available, but only override it if there is a new file.
char sepChar = '/'; int lastSlash = file.lastIndexOf('/');
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);
}
file = file =
file.substring(0, lastSlash) + sepChar + spec.substring(start, end); file.substring(0, lastSlash) + '/' + spec.substring(start, end);
if (url.getProtocol().equals("file")) if (url.getProtocol().equals("file"))
{ {
...@@ -214,6 +216,7 @@ public abstract class URLStreamHandler ...@@ -214,6 +216,7 @@ public abstract class URLStreamHandler
{ {
boolean endsWithSlash = file.charAt(file.length() - 1) == '/'; boolean endsWithSlash = file.charAt(file.length() - 1) == '/';
file = new File(file).getCanonicalPath(); file = new File(file).getCanonicalPath();
file = file.replace(File.separatorChar, '/');
if (endsWithSlash && file.charAt(file.length() - 1) != '/') if (endsWithSlash && file.charAt(file.length() - 1) != '/')
file += '/'; file += '/';
} }
...@@ -238,10 +241,21 @@ public abstract class URLStreamHandler ...@@ -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 // XXX - Classpath used to call PlatformHelper.toCanonicalForm() on
// the file part. It seems like overhead, but supposedly there is some // the file part. It seems like overhead, but supposedly there is some
// benefit in windows based systems (it also lowercased the string). // 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 ...@@ -492,42 +506,31 @@ public abstract class URLStreamHandler
String file; String file;
String ref; String ref;
String user; String user;
String authority;
int port; int port;
protocol = url.getProtocol(); protocol = url.getProtocol();
authority = url.getAuthority();
// JDK 1.2 online doc infers that host could be null because it if (authority == null)
// explicitly states that file cannot be null, but is silent on host. authority = "";
host = url.getHost();
if (host == null)
host = "";
port = url.getPort();
file = url.getFile(); file = url.getFile();
ref = url.getRef(); ref = url.getRef();
user = url.getUserInfo();
// Guess a reasonable size for the string buffer so we have to resize // Guess a reasonable size for the string buffer so we have to resize
// at most once. // 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); StringBuffer sb = new StringBuffer(size);
if (protocol.length() != 0) if (protocol != null && protocol.length() > 0)
{ {
sb.append(protocol); sb.append(protocol);
sb.append(":"); sb.append(":");
} }
if (host.length() != 0) if (authority.length() != 0)
{ {
sb.append("//"); sb.append("//").append(authority);
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(file); sb.append(file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment