public class UsableURI extends LaxURI implements CharSequence, Serializable
URI adding caching
and methods. It cannot be instantiated directly. Go via UURIFactory.
We used to use URI for parsing URIs but ran across
quirky behaviors and bugs. URI is not subclassable --
its final -- and its unlikely that java.net.URI will change any time soon
(See Gordon's considered petition here:
java.net.URI
should have loose/tolerant/compatibility option (or allow reuse)).
This class tries to cache calculated strings such as the extracted host and this class as a string rather than have the parent class rerun its calculation everytime.
URI,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static String |
MASSAGEHOST_PATTERN |
static int |
MAX_URL_LENGTH
Consider URIs too long for IE as illegal.
|
HTTP_SCHEME, HTTPS_SCHEME, lax_abs_path, lax_query, lax_rel_path, lax_rel_segment_authority, _fragment, _host, _is_abs_path, _is_hier_part, _is_hostname, _is_IPv4address, _is_IPv6reference, _is_net_path, _is_opaque_part, _is_reg_name, _is_rel_path, _is_server, _opaque, _path, _port, _query, _scheme, _uri, _userinfo, abs_path, absoluteURI, allowed_abs_path, allowed_authority, allowed_fragment, allowed_host, allowed_IPv6reference, allowed_opaque_part, allowed_query, allowed_reg_name, allowed_rel_path, allowed_userinfo, allowed_within_authority, allowed_within_path, allowed_within_query, allowed_within_userinfo, alpha, alphanum, authority, control, defaultDocumentCharset, defaultDocumentCharsetByLocale, defaultDocumentCharsetByPlatform, defaultProtocolCharset, delims, digit, disallowed_opaque_part, disallowed_rel_path, domainlabel, escaped, fragment, hash, hex, hier_part, host, hostname, hostport, IPv4address, IPv6address, IPv6reference, mark, net_path, opaque_part, param, path, path_segments, pchar, percent, port, protocolCharset, query, reg_name, rel_path, rel_segment, relativeURI, reserved, rootPath, scheme, segment, server, space, toplabel, unreserved, unwise, URI_reference, uric, uric_no_slash, userinfo, within_userinfo| Modifier | Constructor and Description |
|---|---|
protected |
UsableURI()
Shutdown access to default constructor.
|
protected |
UsableURI(String uri,
boolean escaped) |
protected |
UsableURI(String uri,
boolean escaped,
String charset) |
protected |
UsableURI(UsableURI base,
UsableURI relative) |
| Modifier and Type | Method and Description |
|---|---|
char |
charAt(int index) |
protected void |
coalesceHostAuthorityStrings()
The two String fields cachedHost and cachedAuthorityMinusUserInfo are
usually identical; if so, coalesce into a single instance.
|
protected void |
coalesceUriStrings()
The two String fields cachedString and cachedEscapedURI are
usually identical; if so, coalesce into a single instance.
|
int |
compareTo(Object arg0) |
boolean |
equals(Object obj)
Test an object if this UURI is equal to another.
|
String |
getAuthorityMinusUserinfo()
Return the authority minus userinfo (if any).
|
String |
getEscapedURI() |
String |
getHost() |
String |
getHostBasename()
Strips www variants from the host.
|
String |
getReferencedHost()
Return the referenced host in the UURI, if any, also extracting the
host of a DNS-lookup URI where necessary.
|
String |
getSurtForm() |
static boolean |
hasScheme(String possibleUrl)
Test if passed String has likely URI scheme prefix.
|
int |
length() |
static String |
parseFilename(String pathOrUri) |
UsableURI |
resolve(String uri) |
UsableURI |
resolve(String uri,
boolean e) |
UsableURI |
resolve(String uri,
boolean e,
String charset) |
CharSequence |
subSequence(int start,
int end) |
String |
toCustomString()
Returns an alternate, functional String representation -- in this
case, a String of the URI represented by this UURI instance.
|
String |
toString()
Override to cache result
TODO: eliminate, moving most callers to toCustomString, to avoid
overloading/diluting toString()
(see http://webteam.archive.org/confluence/display/Heritrix/Preserve+toString%28%29 )
|
String |
toUnicodeHostString()
In the case of a puny encoded IDN, this method returns the decoded Unicode version.
|
decode, decode, getPath, getPathQuery, getURI, lax, parseAuthority, parseUriReference, setURI, validate, validateclone, encode, equals, getAboveHierPath, getAuthority, getCurrentHierPath, getDefaultDocumentCharset, getDefaultDocumentCharsetByLocale, getDefaultDocumentCharsetByPlatform, getDefaultProtocolCharset, getEscapedAboveHierPath, getEscapedAuthority, getEscapedCurrentHierPath, getEscapedFragment, getEscapedName, getEscapedPath, getEscapedPathQuery, getEscapedQuery, getEscapedURIReference, getEscapedUserinfo, getFragment, getName, getPort, getProtocolCharset, getQuery, getRawAboveHierPath, getRawAuthority, getRawCurrentHierPath, getRawCurrentHierPath, getRawFragment, getRawHost, getRawName, getRawPath, getRawPathQuery, getRawQuery, getRawScheme, getRawURI, getRawURIReference, getRawUserinfo, getScheme, getURIReference, getUserinfo, hasAuthority, hasFragment, hashCode, hasQuery, hasUserinfo, indexFirstOf, indexFirstOf, indexFirstOf, indexFirstOf, isAbsoluteURI, isAbsPath, isHierPart, isHostname, isIPv4address, isIPv6reference, isNetPath, isOpaquePart, isRegName, isRelativeURI, isRelPath, isServer, normalize, normalize, prevalidate, removeFragmentIdentifier, resolvePath, setDefaultDocumentCharset, setDefaultProtocolCharset, setEscapedAuthority, setEscapedFragment, setEscapedPath, setEscapedQuery, setFragment, setPath, setQuery, setRawAuthority, setRawFragment, setRawPath, setRawQuerypublic static final int MAX_URL_LENGTH
public static final String MASSAGEHOST_PATTERN
protected UsableURI()
protected UsableURI(String uri, boolean escaped, String charset) throws org.apache.commons.httpclient.URIException
uri - String representation of an absolute URI.escaped - If escaped.charset - Charset to use.org.apache.commons.httpclient.URIExceptionprotected UsableURI(UsableURI base, UsableURI relative) throws org.apache.commons.httpclient.URIException
relative - String representation of URI.base - Parent UURI to use derelativizing.org.apache.commons.httpclient.URIExceptionprotected UsableURI(String uri, boolean escaped) throws org.apache.commons.httpclient.URIException, NullPointerException
uri - String representation of a URI.escaped - If escaped.NullPointerExceptionorg.apache.commons.httpclient.URIExceptionpublic UsableURI resolve(String uri) throws org.apache.commons.httpclient.URIException
uri - URI as string that is resolved relative to this UURI.org.apache.commons.httpclient.URIExceptionpublic UsableURI resolve(String uri, boolean e) throws org.apache.commons.httpclient.URIException
uri - URI as string that is resolved relative to this UURI.e - True if escaped.org.apache.commons.httpclient.URIExceptionpublic UsableURI resolve(String uri, boolean e, String charset) throws org.apache.commons.httpclient.URIException
uri - URI as string that is resolved relative to this UURI.e - True if uri is escaped.charset - Charset to use.org.apache.commons.httpclient.URIExceptionpublic boolean equals(Object obj)
equals in class org.apache.commons.httpclient.URIobj - an object to comparepublic String getHostBasename() throws org.apache.commons.httpclient.URIException
org.apache.commons.httpclient.URIExceptionpublic String toCustomString()
public String toString()
toString in interface CharSequencetoString in class org.apache.commons.httpclient.URIpublic String toUnicodeHostString()
Most of this implementation is copied from URI.setURI().
public String getEscapedURI()
getEscapedURI in class org.apache.commons.httpclient.URIprotected void coalesceUriStrings()
public String getHost() throws org.apache.commons.httpclient.URIException
getHost in class org.apache.commons.httpclient.URIorg.apache.commons.httpclient.URIExceptionprotected void coalesceHostAuthorityStrings()
public String getReferencedHost() throws org.apache.commons.httpclient.URIException
org.apache.commons.httpclient.URIExceptionpublic String getSurtForm()
public String getAuthorityMinusUserinfo() throws org.apache.commons.httpclient.URIException
org.apache.commons.httpclient.URIExceptionpublic int length()
length in interface CharSequencepublic char charAt(int index)
charAt in interface CharSequencepublic CharSequence subSequence(int start, int end)
subSequence in interface CharSequencepublic int compareTo(Object arg0)
compareTo in interface ComparablecompareTo in class org.apache.commons.httpclient.URIpublic static boolean hasScheme(String possibleUrl)
possibleUrl - URL string to examine.public static String parseFilename(String pathOrUri) throws URISyntaxException
pathOrUri - A file path or a URI.pathOrUri.URISyntaxExceptionCopyright © 2015 The International Internet Preservation Consortium. All Rights Reserved.