public class URI
extends java.lang.Object
implements java.io.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 | Class and Description |
|---|---|
static class |
URI.MalformedURIException
MalformedURIExceptions are thrown in the process of building a URI or setting fields on a URI
when an operation would result in an invalid URI specification.
|
| Constructor and Description |
|---|
URI()
Construct a new and uninitialized URI.
|
URI(java.lang.String p_uriSpec)
Construct a new URI from a URI specification string.
|
URI(java.lang.String p_scheme,
java.lang.String p_schemeSpecificPart)
Construct a new URI that does not follow the generic URI syntax.
|
URI(URI p_other)
Construct a new URI from another URI.
|
URI(URI p_base,
java.lang.String p_uriSpec)
Construct a new URI from a base URI and a URI specification string.
|
| Modifier and Type | Method and Description |
|---|---|
void |
appendPath(java.lang.String p_addToPath)
Append to the end of the path of this URI.
|
java.lang.String |
getFragment()
Get the fragment for this URI.
|
java.lang.String |
getHost()
Get the host for this URI.
|
java.lang.String |
getPath()
Get the path for this URI.
|
java.lang.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.
|
java.lang.String |
getQueryString()
Get the query string for this URI.
|
java.lang.String |
getScheme()
Get the scheme for this URI.
|
java.lang.String |
getSchemeSpecificPart()
Get the scheme-specific part for this URI (everything following the scheme and the first
colon).
|
java.lang.String |
getUserinfo()
Get the userinfo for this URI.
|
static boolean |
isConformantSchemeName(java.lang.String p_scheme)
Determine whether a scheme conforms to the rules for a scheme name.
|
static boolean |
isWellFormedAddress(java.lang.String p_address)
Determine whether a string is syntactically capable of representing a valid IPv4 address or
the domain name of a network host.
|
void |
setHost(java.lang.String p_host)
Set the host for this URI.
|
void |
setPath(java.lang.String p_path)
Set the path for this URI.
|
void |
setPort(int p_port)
Set the port for this URI.
|
void |
setScheme(java.lang.String p_scheme)
Set the scheme for this URI.
|
void |
setUserinfo(java.lang.String p_userinfo)
Set the userinfo for this URI.
|
public URI()
public URI(URI p_other)
p_other - the URI to copy (cannot be null)public URI(java.lang.String p_uriSpec)
throws URI.MalformedURIException
p_uriSpec - the URI specification string (cannot be null or empty)URI.MalformedURIException - if p_uriSpec violates any syntax rulespublic URI(URI p_base, java.lang.String p_uriSpec) throws URI.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)URI.MalformedURIException - if p_uriSpec violates any syntax rulespublic URI(java.lang.String p_scheme,
java.lang.String p_schemeSpecificPart)
throws URI.MalformedURIException
p_scheme - the URI scheme (cannot be null or empty)p_schemeSpecificPart - the scheme-specific part (cannot be null or empty)URI.MalformedURIException - if p_scheme violates any syntax rulespublic java.lang.String getScheme()
public java.lang.String getSchemeSpecificPart()
public java.lang.String getUserinfo()
public java.lang.String getHost()
public int getPort()
public java.lang.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 java.lang.String getPath()
public java.lang.String getQueryString()
public java.lang.String getFragment()
public void setScheme(java.lang.String p_scheme)
throws URI.MalformedURIException
p_scheme - the scheme for this URI (cannot be null)URI.MalformedURIException - if p_scheme is not a conformant scheme namepublic void setUserinfo(java.lang.String p_userinfo)
throws URI.MalformedURIException
p_userinfo - the userinfo for this URIURI.MalformedURIException - if p_userinfo contains invalid characterspublic void setHost(java.lang.String p_host)
throws URI.MalformedURIException
p_host - the host for this URIURI.MalformedURIException - if p_host is not a valid IP address or DNS hostname.public void setPort(int p_port)
throws URI.MalformedURIException
p_port - the port number for this URIURI.MalformedURIException - if p_port is not -1 and not a valid port numberpublic void setPath(java.lang.String p_path)
throws URI.MalformedURIException
p_path - the path for this URI (may be null)URI.MalformedURIException - if p_path contains invalid characterspublic void appendPath(java.lang.String p_addToPath)
throws URI.MalformedURIException
p_addToPath - the new segment to be added to the current pathURI.MalformedURIException - if p_addToPath contains syntax errorspublic static boolean isConformantSchemeName(java.lang.String p_scheme)
p_scheme - The sheme name to checkpublic static boolean isWellFormedAddress(java.lang.String p_address)
p_address - The address string to checkCopyright © 2004-2020 The Apache Software Foundation. All Rights Reserved.