APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.jndi.toolkit.url

public Class Uri

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.jndi.ldap.LdapURL
Imports
java.net.MalformedURLException, .URI, .URISyntaxException

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 strict parsing mode uses the java.net.URI class to syntactically validate URI strings. The compat mode validate the URI authority and rejects URI fragments, but doesn't perform any additional validation on path and query, other than that which may be implemented in the concrete the Uri subclasses. The legacy mode should not be used unless the application is capable of validating all URI strings before any constructors of this class is invoked.

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
protected String
protected boolean
protected String
protected String
protected int
protected String
protected String
protected String

Constructor Summary

AccessConstructor and Description
public
Uri(String uri)

Creates a Uri object given a URI string.

protected
Uri()

Creates an uninitialized Uri object.

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

true if fragments are supported.
acceptsFragment
()

Whether fragments are supported.

protected boolean

Returns:

true if the URI should be considered as a scheme-only URI supported by this URI scheme.
checkSchemeOnly
(String
the URI
uri
,
String
the scheme
scheme
)

Checks whether the given uri string should be considered as a scheme-only URI.

public String
getHost()

Returns the host from the URI's authority part, or null if no host is provided.

public String
getPath()

Returns the URI's path.

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.

public String
getScheme()

Returns the URI's scheme.

protected void
init(String uri)

Initializes a Uri object given a URI string.

protected boolean

Returns:

if this is a scheme-only URI supported by the subclass
isSchemeOnly
(String
An URI string
uri
)

A subclass of Uri that supports scheme only URIs can override this method and return true in the case where the URI string is a scheme-only URI that the subclass supports.

protected MalformedURLException
newInvalidURISchemeException(String
the URI string
uri
)

Creates a MalformedURLException to be thrown when the URI scheme is not supported.

private MalformedURLException
private void
private void
private void
protected Uri.ParseMode

Returns:

the parse mode for parsing this URI.
parseMode
()

The parse mode for parsing this URI.

private void
public String
toString()

Overrides java.lang.Object.toString.

Returns the URI as a string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fragmentback to summary
protected String fragment
hasAuthorityback to summary
protected boolean hasAuthority
hostback to summary
protected String host
pathback to summary
protected String path
portback to summary
protected int port
queryback to summary
protected String query
schemeback to summary
protected String scheme
uriback to summary
protected String uri

Constructor Detail

Uriback to summary
public Uri(String uri) throws MalformedURLException

Creates a Uri object given a URI string.

Uriback to summary
protected Uri()

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

Method Detail

acceptsFragmentback to summary
protected boolean acceptsFragment()

Whether fragments are supported.

Implementation Specification

The default implementation of this method retturns false, always.

Returns:boolean

true if fragments are supported.

checkSchemeOnlyback to summary
protected boolean checkSchemeOnly(String uri, String scheme)

Checks whether the given uri string should be considered as a scheme-only URI. For some protocols - e.g. DNS, we might accept "dns://" as a valid URL denoting default DNS. For others - we might only accept "scheme:".

Implementation Specification

The default implementation of this method returns true if the URI is of the form "<scheme>:" with nothing after the scheme delimiter.

Parameters
uri:String

the URI

scheme:String

the scheme

Returns:boolean

true if the URI should be considered as a scheme-only URI supported by this URI scheme.

getHostback to summary
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 java.net.URI#getHost).

getPathback to summary
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".

getPortback to summary
public int getPort()

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

getQueryback to summary
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 "?".

getSchemeback to summary
public String getScheme()

Returns the URI's scheme.

initback to summary
protected void init(String uri) throws MalformedURLException

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

isSchemeOnlyback to summary
protected boolean isSchemeOnly(String uri)

A subclass of Uri that supports scheme only URIs can override this method and return true in the case where the URI string is a scheme-only URI that the subclass supports.

Implementation Specification

The default implementation of this method returns false, always.

Parameters
uri:String

An URI string

Returns:boolean

if this is a scheme-only URI supported by the subclass

newInvalidURISchemeExceptionback to summary
protected MalformedURLException newInvalidURISchemeException(String uri)

Creates a MalformedURLException to be thrown when the URI scheme is not supported.

Parameters
uri:String

the URI string

Returns:MalformedURLException

a MalformedURLException

newMalformedURLExceptionback to summary
private MalformedURLException newMalformedURLException(String prefix, String msg)
parseback to summary
private void parse(String uri, Uri.ParseMode mode) throws MalformedURLException
parseCompatback to summary
private void parseCompat(String uri) throws MalformedURLException
parseLegacyback to summary
private void parseLegacy(String uri) throws MalformedURLException
parseModeback to summary
protected Uri.ParseMode parseMode()

The parse mode for parsing this URI. The default is ParseMode#COMPAT.

Returns:Uri.ParseMode

the parse mode for parsing this URI.

parseStrictback to summary
private void parseStrict(String uri) throws MalformedURLException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the URI as a string.

com.sun.jndi.toolkit.url back to summary

public final Enum Uri.ParseMode

extends Enum<Uri.ParseMode>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Uri.ParseMode
COMPAT

Compatibility mode.

public static final Uri.ParseMode
LEGACY

Legacy mode.

public static final Uri.ParseMode
STRICT

Strict validation mode.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Uri.ParseMode
public static Uri.ParseMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

COMPATback to summary
public static final Uri.ParseMode COMPAT

Compatibility mode. The URI authority is syntactically validated. Rejects URI fragments unless explicitly supported by the subclass. This is the default.

LEGACYback to summary
public static final Uri.ParseMode LEGACY

Legacy mode. In this mode, no validation is performed.

STRICTback to summary
public static final Uri.ParseMode STRICT

Strict validation mode. Validate the URI syntactically using java.net.URI. Rejects URI fragments unless explicitly supported by the subclass.

Constructor Detail

ParseModeback to summary
private ParseMode()

Method Detail

valueOfback to summary
public static Uri.ParseMode valueOf(String name)
valuesback to summary
public static Uri.ParseMode[] values()