From d288ff8d54dce83ba0ccea262d4da42a820a1bfc Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Wed, 20 Apr 2005 09:36:06 +0000 Subject: [PATCH] [multiple changes] 2005-04-20 Andrew John Hughes * java/net/URI.java: Added class documentation. (parseURI(String)): Only handle scheme-specific parts if URI is not opaque. Allow for parts that can't be null. (toString()): Output the scheme-specific part whole, rather than as its possibly non-existent components. 2005-04-20 Jeroen Frijters * java/net/URI.java (AUTHORITY_REGEXP): Corrected regexp. (AUTHORITY_USERINFO_GROUP,AUTHORITY_HOST_GROUP,AUTHORITY_PORT_GROUP): Adjusted to match new regexp. From-SVN: r98451 --- libjava/ChangeLog | 15 ++++++++ libjava/java/net/URI.java | 87 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 8213dd5..55e9b6a 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,18 @@ +2005-04-20 Andrew John Hughes + + * java/net/URI.java: + Added class documentation. + (parseURI(String)): Only handle scheme-specific parts + if URI is not opaque. Allow for parts that can't be null. + (toString()): Output the scheme-specific part whole, rather + than as its possibly non-existent components. + +2005-04-20 Jeroen Frijters + + * java/net/URI.java (AUTHORITY_REGEXP): Corrected regexp. + (AUTHORITY_USERINFO_GROUP,AUTHORITY_HOST_GROUP,AUTHORITY_PORT_GROUP): + Adjusted to match new regexp. + 2005-04-20 Michael Koch * gnu/java/net/protocol/file/Connection.java, diff --git a/libjava/java/net/URI.java b/libjava/java/net/URI.java index 23e3e7c..95577fc 100644 --- a/libjava/java/net/URI.java +++ b/libjava/java/net/URI.java @@ -46,12 +46,67 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** + *

+ * A URI instance represents that defined by + * RFC2396, + * with some deviations. + *

+ *

+ * At its highest level, a URI consists of: + *

+ * [scheme:]scheme-specific-part + * [#fragment] + *

+ *

+ * where # and : are literal characters, + * and those parts enclosed in square brackets are optional. + *

+ *

+ * There are two main types of URI. An opaque URI is one + * which just consists of the above three parts, and is not further + * defined. An example of such a URI would be mailto: URI. + * In contrast, hierarchical URIs give further definition + * to the scheme-specific part, so as represent some part of a hierarchical + * structure. + *

+ *

+ * [//authority][path] + * [?query] + *

+ *

+ * with / and ? being literal characters. + * When server-based, the authority section is further subdivided into: + *

+ *

+ * [user-info@]host + * [:port] + *

+ *

+ * with @ and : as literal characters. + * Authority sections that are not server-based are said to be registry-based. + *

+ *

+ * Hierarchical URIs can be either relative or absolute. Absolute URIs + * always start with a `/', while relative URIs don't + * specify a scheme. Opaque URIs are always absolute. + *

+ *

+ * Each part of the URI may have one of three states: undefined, empty + * or containing some content. The former two of these are represented + * by null and the empty string in Java, respectively. + * The scheme-specific part may never be undefined. It also follows from + * this that the path sub-part may also not be undefined, so as to ensure + * the former. + *

+ * * @author Ito Kazumitsu (ito.kazumitsu@hitachi-cable.co.jp) * @author Dalibor Topic (robilad@kaffe.org) * @author Michael Koch (konqueror@gmx.de) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @since 1.4 */ -public final class URI implements Comparable, Serializable +public final class URI + implements Comparable, Serializable { static final long serialVersionUID = -6052424284110960213L; @@ -65,7 +120,7 @@ public final class URI implements Comparable, Serializable "^(([^:/?#]+):)?((//([^/?#]*))?([^?#]*)(\\?([^#]*))?)?(#(.*))?"; private static final String AUTHORITY_REGEXP = - "^((([^?#]*)@)?([^?#:]*)(:([^?#]*)))?"; + "(([^?#]*)@)?([^?#:]*)(:([^?#]*))?"; /** * Valid characters (taken from rfc2396) @@ -115,9 +170,9 @@ public final class URI implements Comparable, Serializable */ private static final int FRAGMENT_GROUP = 10; - private static final int AUTHORITY_USERINFO_GROUP = 3; - private static final int AUTHORITY_HOST_GROUP = 4; - private static final int AUTHORITY_PORT_GROUP = 6; + private static final int AUTHORITY_USERINFO_GROUP = 2; + private static final int AUTHORITY_HOST_GROUP = 3; + private static final int AUTHORITY_PORT_GROUP = 5; private transient String scheme; private transient String rawSchemeSpecificPart; @@ -180,10 +235,14 @@ public final class URI implements Comparable, Serializable if (matcher.matches()) { scheme = getURIGroup(matcher, SCHEME_GROUP); - rawSchemeSpecificPart = getURIGroup(matcher, SCHEME_SPEC_PART_GROUP); - rawAuthority = getURIGroup(matcher, AUTHORITY_GROUP); - rawPath = getURIGroup(matcher, PATH_GROUP); - rawQuery = getURIGroup(matcher, QUERY_GROUP); + rawSchemeSpecificPart = matcher.group(SCHEME_SPEC_PART_GROUP); + schemeSpecificPart = unquote(rawSchemeSpecificPart); + if (!isOpaque()) + { + rawAuthority = getURIGroup(matcher, AUTHORITY_GROUP); + rawPath = matcher.group(PATH_GROUP); + rawQuery = getURIGroup(matcher, QUERY_GROUP); + } rawFragment = getURIGroup(matcher, FRAGMENT_GROUP); } else @@ -221,7 +280,6 @@ public final class URI implements Comparable, Serializable // We must eagerly unquote the parts, because this is the only time // we may throw an exception. - schemeSpecificPart = unquote(rawSchemeSpecificPart); authority = unquote(rawAuthority); userInfo = unquote(rawUserInfo); host = unquote(rawHost); @@ -814,14 +872,15 @@ public final class URI implements Comparable, Serializable } /** - * Returns the URI as string + * Returns the URI as a String. If the URI was created using a constructor, + * then this will be the same as the original input string. + * + * @return a string representation of the URI. */ public String toString() { return (getScheme() == null ? "" : getScheme() + ":") - + (getRawAuthority() == null ? "" : "//" + getRawAuthority()) - + (getRawPath() == null ? "" : getRawPath()) - + (getRawQuery() == null ? "" : "?" + getRawQuery()) + + getRawSchemeSpecificPart() + (getRawFragment() == null ? "" : "#" + getRawFragment()); } -- 2.7.4