public class

Uri

extends Object
java.lang.Object
   ↳ com.sun.jndi.toolkit.url.Uri
Known Direct Subclasses

Class Overview

A Uri object represents an absolute Uniform Resource Identifier (URI) as defined by RFC 2396 and updated by RFC 2373 and RFC 2732. The most commonly used form of URI is the Uniform Resource Locator (URL).

The java.net.URL class cannot be used to parse URIs since it requires the installation of URL stream handlers that may not be available. The hack of getting around this by temporarily replacing the scheme part of a URI is not appropriate here: JNDI service providers must work on older Java platforms, and we want new features and bug fixes that are not available in old versions of the URL class.

It may be appropriate to drop this code in favor of the java.net.URI class. The changes would need to be written so as to still run on pre-1.4 platforms not containing that class.

The format of an absolute URI (see the RFCs mentioned above) is:

      absoluteURI   = scheme ":" ( hier_part | opaque_part )

      scheme        = alpha *( alpha | digit | "+" | "-" | "." )

      hier_part     = ( net_path | abs_path ) [ "?" query ]
      opaque_part   = uric_no_slash *uric

      net_path      = "//" authority [ abs_path ]
      abs_path      = "/"  path_segments

      authority     = server | reg_name
      reg_name      = 1*( unreserved | escaped | "$" | "," |
                          ";" | ":" | "@" | "&" | "=" | "+" )
      server        = [ [ userinfo "@" ] hostport ]
      userinfo      = *( unreserved | escaped |
                         ";" | ":" | "&" | "=" | "+" | "$" | "," )

      hostport      = host [ ":" port ]
      host          = hostname | IPv4address | IPv6reference
      port          = *digit

      IPv6reference = "[" IPv6address "]"
      IPv6address   = hexpart [ ":" IPv4address ]
      IPv4address   = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit
      hexpart       = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ]
      hexseq        = hex4 *( ":" hex4)
      hex4          = 1*4hex

      path          = [ abs_path | opaque_part ]
      path_segments = segment *( "/" segment )
      segment       = *pchar *( ";" param )
      param         = *pchar
      pchar         = unreserved | escaped |
                      ":" | "@" | "&" | "=" | "+" | "$" | ","

      query         = *uric

      uric          = reserved | unreserved | escaped
      uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
                      "&" | "=" | "+" | "$" | ","
      reserved      = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                      "$" | "," | "[" | "]"
      unreserved    = alphanum | mark
      mark          = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
      escaped       = "%" hex hex
      unwise        = "{" | "}" | "|" | "\" | "^" | "`"
 

Currently URIs containing userinfo or reg_name are not supported. The opaque_part of a non-hierarchical URI is treated as if if were a path without a leading slash.

Summary

Fields
protected boolean hasAuthority
protected String host
protected String path
protected int port
protected String query
protected String scheme
protected String uri
Public Constructors
Uri(String uri)
Creates a Uri object given a URI string.
Protected Constructors
Uri()
Creates an uninitialized Uri object.
Public Methods
String getHost()
Returns the host from the URI's authority part, or null if no host is provided.
String getPath()
Returns the URI's path.
int getPort()
Returns the port from the URI's authority part, or -1 if no port is provided.
String getQuery()
Returns the URI's query part, or null if no query is provided.
String getScheme()
Returns the URI's scheme.
String toString()
Returns the URI as a string.
Protected Methods
void init(String uri)
Initializes a Uri object given a URI string.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected boolean hasAuthority

protected String host

protected String path

protected int port

protected String query

protected String scheme

protected String uri

Public Constructors

public Uri (String uri)

Creates a Uri object given a URI string.

Protected Constructors

protected Uri ()

Creates an uninitialized Uri object. The init() method must be called before any other Uri methods.

Public Methods

public String getHost ()

Returns the host from the URI's authority part, or null if no host is provided. If the host is an IPv6 literal, the delimiting brackets are part of the returned value (see getHost()).

public String getPath ()

Returns the URI's path. The path is never null. Note that a slash following the authority part (or the scheme if there is no authority part) is part of the path. For example, the path of "http://host/a/b" is "/a/b".

public int getPort ()

Returns the port from the URI's authority part, or -1 if no port is provided.

public String getQuery ()

Returns the URI's query part, or null if no query is provided. Note that a query always begins with a leading "?".

public String getScheme ()

Returns the URI's scheme.

public String toString ()

Returns the URI as a string.

Returns
  • a string representation of the object.

Protected Methods

protected void init (String uri)

Initializes a Uri object given a URI string. This method must be called exactly once, and before any other Uri methods.