|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.io.URI
public class URI
A class to represent and manipulate URI-references as defined in RFC3986. The terms "URI", "URI-reference", "relative-reference", "scheme", "authority", "path", "query", and "fragment" used in this class and associated documentation are used as defined in RFC3986. The reference-transformation algorithm used in this class is "strict" as per the usage in section 5.2.2. This class does not provide any mechanism for scheme- or protocol-based normalization. Instances of this class are immutable after creation.
This class also provides convenience methods to do IDNA-encoding of
internationalized hostnames. If this functionality is desired independently
of URI processing, please use the IDNA
class instead.
Method Summary | ||
---|---|---|
static URI |
create(String uri)
Creates a new URI object from the given string. |
|
static URI |
create(String baseUri,
String uriReference)
Creates a new URI object from the given base URI and
URI-reference. |
|
static URI |
create(URI baseUri,
String uriReference)
Creates a new URI object from the given base URI and
URI-reference. |
|
boolean |
equals(Object other)
Compares two URI-references for equality. |
|
String |
getAuthority()
Get the authority component of the URI-reference. |
|
static String |
getFile(String path)
Convenience method to extract the filename from the path component of a hierarchical URI-reference. |
|
String |
getFragment()
Get the fragment component of the URI-reference. |
|
String |
getHost()
Get the host sub-component of the URI-reference. |
|
String |
getPath()
Get the path component of the URI-reference. |
|
String |
getPort()
Get the port sub-component of the URI-reference. |
|
String |
getQuery()
Get the query component of the URI-reference. |
|
String |
getScheme()
Get the scheme component of the URI-reference. |
|
String |
getUserinfo()
Get the userinfo sub-component of the URI-reference. |
|
int |
hashCode()
Returns a hash code for this object. |
|
boolean |
isAbsolute()
Tests if the URI-reference represented by this object is an absolute URI or a relative-reference. |
|
String |
toIDNAString()
Get a string representation of the normalized URI-reference after having the IDNA algorithm applied as per RFC3490. |
|
String |
toIRIString()
Get a string representation of the normalized URI-reference as per RFC3986 and RFC3987. |
|
String |
toString()
Get a string representation of the normalized URI-reference as per RFC3986. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static URI create(String uri) throws IllegalArgumentException, MalformedURIException
URI
object from the given string.
This method will parse and normalize the string, and
return a URI
object created from the component parts of
the string.
uri
- The string to be parsed and normalized.
URI
object. This will not be null
.
IllegalArgumentException
- If uri
is null
.
MalformedURIException
- If uri
represents an invalid
URI as per the syntax in RFC3986.public static URI create(URI baseUri, String uriReference) throws NullPointerException, IllegalArgumentException, MalformedURIException
URI
object from the given base URI and
URI-reference. This method will parse and normalize the
URI-reference, then resolve it against the base URI, and
return the resulting URI
object. Note that if the
uriReference
parameter represents an absolute URI,
then resolving it against baseUri
will have no effect.
baseUri
- The URI
object that serves as the base URI.uriReference
- The URI-reference to be parsed and resolved.
URI
object. This will not be null
.
NullPointerException
- If baseUri
is null
.
IllegalArgumentException
- If uriReference
is null
,
or if the baseUri
is not an absolute URI.
MalformedURIException
- If uriReference
represents an
invalid URI-reference as per the syntax in RFC3986.public static URI create(String baseUri, String uriReference) throws IllegalArgumentException, MalformedURIException
URI
object from the given base URI and
URI-reference. This method will parse and normalize the base URI,
then parse and normalize the URI-reference, then resolve the
URI-reference against the base URI, and
return the resulting URI
object. Note that if the
uriReference
parameter represents an absolute URI,
then resolving it against baseUri
will have no effect.
However, since baseUri
is parsed and normalized regardless,
exceptions may be thrown even if uriReference
represents a valid
absolute URI. This is by design, so that the cases where uriReference
is absolute or relative are handled consistently.
baseUri
- The base URI to be parsed and normalized.uriReference
- The URI-reference to be parsed and resolved.
URI
object. This will not be null
.
IllegalArgumentException
- If either baseUri
or
uriReference
is null
, or if the baseUri
does not represent an absolute URI.
MalformedURIException
- If either baseUri
or
uriReference
represent an
invalid URI-reference as per the syntax in RFC3986.public static String getFile(String path)
path
- The path component from which the filename should be extracted.
null
,
although it may have a zero length.
NullPointerException
- If path
is null
.public boolean isAbsolute()
true
if the URI-reference is an absolute
URI (i.e. there is a scheme specified), and false
otherwise.public String getScheme()
String
containing the scheme component of the
URI-reference represented by this URI
object. This may be
null
if this URI
object represents a
relative-reference.public String getAuthority()
String
containing the authority component of the
URI-reference represented by this URI
object. This may be
null
if there is no authority component. This may be zero-length
if an empty authority component was specified (such as in "file:///a.file.ext").public String getUserinfo()
String
containing the userinfo sub-component of the
URI-reference represented by this URI
object. This may be
null
if there is no userinfo sub-component. This may be zero-length
if an empty userinfo sub-component was specified (such as in "scheme://@host/").public String getHost()
null
if and only if URI.getAuthority()
also returns null
. Note that the host sub-component may be
an IP address, including strings in the IPvFuture
production
of the RFC3986 grammar. Also note that as part of the URI normalization
process specified in RFC3986, the hostname will be in lowercased (except
for characters in a percent-encoding).
String
containing the host sub-component of the
URI-reference represented by this URI
object. This may be
null
if there is no authority component. This may be zero-length
if an empty host sub-component was specified (such as in "file:///a.file.ext").public String getPort()
String
containing the port sub-component of the
URI-reference represented by this URI
object. This may be
null
if there is no port sub-component. If not null
,
this will not be zero-length.public String getPath()
URI
objects representing URIs with "http" and "https" schemes, a zero-length path will
be changed to a single slash ("/") as they are defined to be equivalent.
String
containing the path component of the
URI-reference represented by this URI
object. This will not be
null
, since the path component is a required component of a
URI-reference.public String getQuery()
String
containing the query component of the
URI-reference represented by this URI
object. This may be
null
if no query was specified.public String getFragment()
String
containing the fragment component of the
URI-reference represented by this URI
object. This may be
null
if no fragment was specified.public int hashCode()
hashCode
in class Object
hashCode
.Object.equals(java.lang.Object)
,
Hashtable
public String toString()
toIDNAString
or toIRIString
.
toString
in class Object
String
that represents the normalized URI-reference. This
will not be null
.public String toIDNAString() throws IDNAException
String
that represents the normalized URI-reference
as per RFC3986 and RFC3490. This will not be null
.
IDNAException
- If the host name could not be transformed as per RFC3490.
See the toASCII
method for details.public String toIRIString()
String
that represents the normalized URI-reference
as per RFC3986 and RFC3987. This will not be null
.public boolean equals(Object other)
equals
in class Object
other
- Either a String
or a URI
object
to compare against this URI
object.
false
under the following conditions: (1) this URI
object represents a relative-reference; since it is not absolute, it
cannot be compared for equality. (2) other
is neither a
String
nor a URI
object (this includes the
case where other
is null
). (3) If other
is a String
and attempts to parse it fail. (4) If, after
any parsing and normalization required of both this URI
object and the provided URI-reference, the URI-references differ in one
or more of their component parts. This method returns true
if, after parsing and normalization, the URI-references have identical
component parts.Boolean.hashCode()
,
Hashtable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal