public class URI extends Object implements Serializable
Parsing of a URI specification is done according to the URI
syntax described in RFC 2396
For URIs that do not follow the "generic URI" syntax (e.g. mailto),
the entire scheme-specific part is treated as the "path" portion
of the URI.
Note that, unlike the java.net.URL class, this class does not provide
any built-in network access functionality nor does it provide any
scheme-specific functionality (for example, it does not know a
default port for a specific scheme). Rather, it only knows the
grammar and basic set of operations that can be applied to a URI.
| Modifier and Type | Field and Description |
|---|---|
static int |
ABSOLUTE |
static int |
GRANDPARENT |
static int |
NETWORK |
static int |
PARENT |
static int |
RELATIVE |
static int |
SAMEDOCUMENT |
| Constructor and Description |
|---|
URI()
Construct a new and uninitialized URI.
|
URI(String p_uriSpec)
Construct a new URI from a URI specification string.
|
URI(String p_scheme,
String p_schemeSpecificPart)
Construct a new URI that does not follow the generic URI syntax.
|
URI(String p_scheme,
String p_userinfo,
String p_host,
int p_port,
String p_path,
String p_queryString,
String p_fragment)
Construct a new URI that follows the generic URI syntax from its
component parts.
|
URI(String p_scheme,
String p_host,
String p_path,
String p_queryString,
String p_fragment)
Construct a new URI that follows the generic URI syntax from its
component parts.
|
URI(URI p_other)
Construct a new URI from another URI.
|
URI(URI p_base,
String p_uriSpec)
Construct a new URI from a base URI and a URI specification string.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object p_test)
Determines if the passed-in Object is equivalent to this URI.
|
static String |
flags2str(int f) |
String |
getFragment()
Get the fragment for this URI.
|
String |
getHost()
Get the host for this URI.
|
String |
getPath()
Get the path for this URI.
|
String |
getPath(boolean p_includeQueryString,
boolean p_includeFragment)
Get the path for this URI (optionally with the query string and
fragment).
|
int |
getPort()
Get the port for this URI.
|
String |
getQueryString()
Get the query string for this URI.
|
String |
getScheme()
Get the scheme for this URI.
|
String |
getSchemeSpecificPart()
Get the scheme-specific part for this URI (everything following the
scheme and the first colon).
|
String |
getURIString()
Get the URI as a string specification.
|
String |
getUserinfo()
Get the userinfo for this URI.
|
int |
hashCode() |
static boolean |
isConformantSchemeName(String p_scheme)
Determine whether a scheme conforms to the rules for a scheme name.
|
boolean |
isGenericURI()
Get the indicator as to whether this URI uses the "generic URI"
syntax.
|
boolean |
isNormalFormC() |
static boolean |
isWellFormedAddress(String p_address)
Determine whether a string is syntactically capable of representing
a valid IPv4 address or the domain name of a network host.
|
String |
relativize(String abs,
int flags) |
void |
setFragment(String p_fragment)
Set the fragment for this URI.
|
static int |
str2flags(String pv) |
String |
toString()
produce a human-consumable string for the URI
|
public static final int SAMEDOCUMENT
public static final int NETWORK
public static final int ABSOLUTE
public static final int RELATIVE
public static final int PARENT
public static final int GRANDPARENT
public URI()
public URI(URI p_other)
p_other - the URI to copy (cannot be null)public URI(String p_uriSpec) throws MalformedURIException
p_uriSpec - the URI specification string (cannot be null or
empty)MalformedURIException - if p_uriSpec violates any syntax
rulespublic URI(URI p_base, String p_uriSpec) throws MalformedURIException
p_base - the base URI (cannot be null if p_uriSpec is null or
empty)p_uriSpec - the URI specification string (cannot be null or
empty if p_base is null)MalformedURIException - if p_uriSpec violates any syntax
rulespublic URI(String p_scheme, String p_schemeSpecificPart) throws MalformedURIException
p_scheme - the URI scheme (cannot be null or empty)p_schemeSpecificPart - the scheme-specific part (cannot be
null or empty)MalformedURIException - if p_scheme violates any
syntax rulespublic URI(String p_scheme, String p_host, String p_path, String p_queryString, String p_fragment) throws MalformedURIException
p_scheme - the URI scheme (cannot be null or empty)p_host - the hostname or IPv4 address for the URIp_path - the URI path - if the path contains '?' or '#',
then the query string and/or fragment will be
set from the path; however, if the query and
fragment are specified both in the path and as
separate parameters, an exception is thrownp_queryString - the URI query string (cannot be specified
if path is null)p_fragment - the URI fragment (cannot be specified if path
is null)MalformedURIException - if any of the parameters violates
syntax rules or semantic rulespublic URI(String p_scheme, String p_userinfo, String p_host, int p_port, String p_path, String p_queryString, String p_fragment) throws MalformedURIException
p_scheme - the URI scheme (cannot be null or empty)p_userinfo - the URI userinfo (cannot be specified if host
is null)p_host - the hostname or IPv4 address for the URIp_port - the URI port (may be -1 for "unspecified"; cannot
be specified if host is null)p_path - the URI path - if the path contains '?' or '#',
then the query string and/or fragment will be
set from the path; however, if the query and
fragment are specified both in the path and as
separate parameters, an exception is thrownp_queryString - the URI query string (cannot be specified
if path is null)p_fragment - the URI fragment (cannot be specified if path
is null)MalformedURIException - if any of the parameters violates
syntax rules or semantic rulespublic String getScheme()
public String getSchemeSpecificPart()
public String getUserinfo()
public String getHost()
public int getPort()
public String getPath(boolean p_includeQueryString, boolean p_includeFragment)
p_includeQueryString - if true (and query string is not null),
then a "?" followed by the query string
will be appendedp_includeFragment - if true (and fragment is not null),
then a "#" followed by the fragment
will be appendedpublic String getPath()
public String getQueryString()
public String getFragment()
public void setFragment(String p_fragment) throws MalformedURIException
p_fragment - the fragment for this URIMalformedURIException - if p_fragment is not null and this
URI does not conform to the generic
URI syntax or if the path is nullpublic boolean equals(Object p_test)
public String toString()
public String getURIString()
public boolean isGenericURI()
public static boolean isConformantSchemeName(String p_scheme)
public static boolean isWellFormedAddress(String p_address)
public boolean isNormalFormC()
public String relativize(String abs, int flags) throws MalformedURIException
MalformedURIExceptionpublic static String flags2str(int f)
public static int str2flags(String pv)
Copyright © 2014. All Rights Reserved.