public class Uri extends Object
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.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
hasAuthority |
protected String |
host |
protected String |
path |
protected int |
port |
protected String |
query |
protected String |
scheme |
protected String |
uri |
| Modifier | Constructor and Description |
|---|---|
protected |
Uri()
Creates an uninitialized Uri object.
|
|
Uri(String uri)
Creates a Uri object given a URI string.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
protected void |
init(String uri)
Initializes a Uri object given a URI string.
|
String |
toString()
Returns the URI as a string.
|
protected int port
protected boolean hasAuthority
public Uri(String uri) throws MalformedURLException
MalformedURLExceptionprotected Uri()
protected void init(String uri) throws MalformedURLException
MalformedURLExceptionpublic String getHost()
URI.getHost()).public int getPort()
public String getPath()
public String getQuery()