public class VFSURI extends Object implements Comparable<VFSURI>, Serializable
java.net.URI
which allows special characters like SPACE in paths.
The Java URI
class complains about such chars with a java.net.URISyntaxException
while VFS accepts it. The URI
is final and must not be subclassed.
Constructor and Description |
---|
VFSURI()
Constructor method for i18n purposes only.
|
VFSURI(String str)
Constructs a URI by parsing the given string.
|
VFSURI(String scheme,
String ssp,
String fragment)
Constructs a URI from the given components.
|
VFSURI(String scheme,
String userInfo,
String host,
int port,
String path,
String query,
String fragment)
Constructs a hierarchical URI from the given components.
|
VFSURI(String scheme,
String host,
String path,
String fragment)
Constructs a hierarchical URI from the given components.
|
VFSURI(String scheme,
String authority,
String path,
String query,
String fragment)
Constructs a hierarchical URI from the given components.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(VFSURI that)
Compares this URI to another object, which must be a URI.
|
static VFSURI |
create(String str)
Creates a URI by parsing the given string.
|
boolean |
equals(Object ob)
Tests this URI for equality with another object.
|
String |
getAuthority()
Returns the decoded authority component of this URI.
|
org.apache.commons.vfs2.FileType |
getFileType()
Getter for the VFS type (file, folder, ...).
|
String |
getFragment()
Returns the decoded fragment component of this URI.
|
String |
getHost()
Returns the host component of this URI.
|
String |
getPath()
Returns the decoded path component of this URI.
|
int |
getPort()
Returns the port number of this URI.
|
String |
getQuery()
Returns the decoded query component of this URI.
|
String |
getRawAuthority()
Returns the raw authority component of this URI.
|
String |
getRawFragment()
Returns the raw fragment component of this URI.
|
String |
getRawPath()
Returns the raw path component of this URI.
|
String |
getRawQuery()
Returns the raw query component of this URI.
|
String |
getRawSchemeSpecificPart()
Returns the raw scheme-specific part of this URI.
|
String |
getRawUserInfo()
Returns the raw user-information component of this URI.
|
String |
getScheme()
Returns the scheme component of this URI.
|
String |
getSchemeSpecificPart()
Returns the decoded scheme-specific part of this URI.
|
String |
getUserInfo()
Returns the decoded user-information component of this URI.
|
int |
hashCode()
Returns a hash-code value for this URI.
|
boolean |
isAbsolute()
Tells whether or not this URI is absolute.
|
boolean |
isOpaque()
Tells whether or not this URI is opaque.
|
VFSURI |
normalize()
Normalizes this URI's path.
|
VFSURI |
parseServerAuthority()
Attempts to parse this URI's authority component, if defined, into
user-information, host, and port components.
|
VFSURI |
relativize(VFSURI uri)
Relativizes the given URI against this URI.
|
VFSURI |
resolve(String str)
Constructs a new URI by parsing the given string and then resolving it
against this URI.
|
VFSURI |
resolve(VFSURI uri)
Resolves the given URI against this URI.
|
void |
setFileType(org.apache.commons.vfs2.FileType type)
Setter for the VFS type (file, folder, ...).
|
String |
toASCIIString()
Returns the content of this URI as a US-ASCII string.
|
String |
toString()
Returns the content of this URI as a string.
|
URL |
toURL()
Constructs a URL from this URI.
|
public VFSURI()
Can only be used if beans design time is set (e.g. by external tools like the
I18NExtractor
).
public VFSURI(String str) throws URISyntaxException
This constructor parses the given string exactly as specified by the grammar in RFC 2396, Appendix A, except for the following deviations:
str
- The string to be parsed into a URINullPointerException
- If str is nullURISyntaxException
- If the given string violates RFC 2396, as augmented
by the above deviationspublic VFSURI(String scheme, String userInfo, String host, int port, String path, String query, String fragment) throws URISyntaxException
If a scheme is given then the path, if also given, must either be empty or begin with a slash character ('/'). Otherwise a component of the new URI may be left undefined by passing null for the corresponding parameter or, in the case of the port parameter, by passing -1.
This constructor first builds a URI string from the given components according to the rules specified in RFC 2396, section 5.2, step 7:
The resulting URI string is then parsed as if by invoking the VFSURI(String)
constructor and then invoking the parseServerAuthority()
method upon the result; this may cause a URISyntaxException
to be thrown.
scheme
- Scheme nameuserInfo
- User name and authorization informationhost
- Host nameport
- Port numberpath
- Pathquery
- Queryfragment
- FragmentURISyntaxException
- If both a scheme and a path are given but the path is relative,
if the URI string constructed from the given components violates
RFC 2396, or if the authority component of the string is
present but cannot be parsed as a server-based authoritypublic VFSURI(String scheme, String authority, String path, String query, String fragment) throws URISyntaxException
If a scheme is given then the path, if also given, must either be empty or begin with a slash character ('/'). Otherwise a component of the new URI may be left undefined by passing null for the corresponding parameter.
This constructor first builds a URI string from the given components according to the rules specified in RFC 2396, section 5.2, step 7:
The resulting URI string is then parsed as if by invoking the VFSURI(String)
constructor and then invoking the parseServerAuthority()
method upon the result; this may cause a URISyntaxException
to be thrown.
scheme
- Scheme nameauthority
- Authoritypath
- Pathquery
- Queryfragment
- FragmentURISyntaxException
- If both a scheme and a path are given but the path is relative,
if the URI string constructed from the given components violates
RFC 2396, or if the authority component of the string is
present but cannot be parsed as a server-based authoritypublic VFSURI(String scheme, String host, String path, String fragment) throws URISyntaxException
A component may be left undefined by passing null.
This convenience constructor works as if by invoking the seven-argument constructor as follows:
new URI
(scheme, null, host, -1, path, null, fragment);
scheme
- Scheme namehost
- Host namepath
- Pathfragment
- FragmentURISyntaxException
- If the URI string constructed from the given components
violates RFC 2396public VFSURI(String scheme, String ssp, String fragment) throws URISyntaxException
A component may be left undefined by passing null.
This constructor first builds a URI in string form using the given components as follows:
he resulting URI string is then parsed in order to create the new
URI instance as if by invoking the VFSURI(String)
constructor;
this may cause a URISyntaxException
to be thrown.
scheme
- Scheme namessp
- Scheme-specific partfragment
- FragmentURISyntaxException
- If the URI string constructed from the given components
violates RFC 2396public static VFSURI create(String str)
This convenience factory method works as if by invoking the VFSURI(String)
constructor; any URISyntaxException
thrown by the
constructor is caught and wrapped in a new IllegalArgumentException
object, which is then thrown.
This method is provided for use in situations where it is known that
the given string is a legal URI, for example for URI constants declared
within in a program, and so it would be considered a programming error
for the string not to parse as such. The constructors, which throw
URISyntaxException
directly, should be used situations where a
URI is being constructed from user input or from some other source that
may be prone to errors.
str
- The string to be parsed into a URINullPointerException
- If str is nullIllegalArgumentException
- If the given string violates RFC 2396public VFSURI parseServerAuthority() throws URISyntaxException
If this URI's authority component has already been recognized as being server-based then it will already have been parsed into user-information, host, and port components. In this case, or if this URI has no authority component, this method simply returns this URI.
Otherwise this method attempts once more to parse the authority component into user-information, host, and port components, and throws an exception describing why the authority component could not be parsed in that way.
This method is provided because the generic URI syntax specified in RFC 2396 cannot always distinguish a malformed server-based authority from a legitimate registry-based authority. It must therefore treat some instances of the former as instances of the latter. The authority component in the URI string "//foo:bar", for example, is not a legal server-based authority but it is legal as a registry-based authority.
In many common situations, for example when working URIs that are known to be either URNs or URLs, the hierarchical URIs being used will always be server-based. They therefore must either be parsed as such or treated as an error. In these cases a statement such as
URI u = new URI(str).parseServerAuthority();
can be used to ensure that u always refers to a URI that, if it has an authority component, has a server-based authority with proper user-information, host, and port components. Invoking this method also ensures that if the authority could not be parsed in that way then an appropriate diagnostic message can be issued based upon the exception that is thrown.
URISyntaxException
- If the authority component of this URI is defined
but cannot be parsed as a server-based authority
according to RFC 2396public VFSURI normalize()
If this URI is opaque, or if its path is already in normal form, then this URI is returned. Otherwise a new URI is constructed that is identical to this URI except that its path is computed by normalizing this URI's path in a manner consistent with RFC 2396, section 5.2, step 6, sub-steps c through f; that is:
A normalized path will begin with one or more ".." segments if there were insufficient non-".." segments preceding them to allow their removal. A normalized path will begin with a "." segment if one was inserted by step 3 above. Otherwise, a normalized path will not contain any "." or ".." segments.
public VFSURI resolve(VFSURI uri)
If the given URI is already absolute, or if this URI is opaque, then the given URI is returned.
If the given URI's fragment component is defined, its path component is empty, and its scheme, authority, and query components are undefined, then a URI with the given fragment but with all other components equal to those of this URI is returned. This allows a URI representing a standalone fragment reference, such as "#foo", to be usefully resolved against a base URI.
Otherwise this method constructs a new hierarchical URI in a manner consistent with RFC 2396, section 5.2; that is:
normalize
method.The result of this method is absolute if, and only if, either this URI is absolute or the given URI is absolute.
uri
- The URI to be resolved against this URINullPointerException
- If uri is nullpublic VFSURI resolve(String str)
This convenience method works as if invoking it were equivalent to
evaluating the expression resolve
(URI.create
(str)).
str
- The string to be parsed into a URINullPointerException
- If str is nullIllegalArgumentException
- If the given string violates RFC 2396public VFSURI relativize(VFSURI uri)
The relativization of the given URI against this URI is computed as follows:
uri
- The URI to be relativized against this URINullPointerException
- If uri is nullpublic URL toURL() throws MalformedURLException
This convenience method works as if invoking it were equivalent to evaluating the expression new URL(this.toString()) after first checking that this URI is absolute.
IllegalArgumentException
- If this URL is not absoluteMalformedURLException
- If a protocol handler for the URL could not be found,
or if some other error occurred while constructing the URLpublic String getScheme()
The scheme component of a URI, if defined, only contains characters in the alphanum category and in the string "-.+". A scheme always starts with an alpha character.
The scheme component of a URI cannot contain escaped octets, hence this method does not perform any decoding.
public boolean isAbsolute()
A URI is absolute if, and only if, it has a scheme component.
public boolean isOpaque()
A URI is opaque if, and only if, it is absolute and its scheme-specific part does not begin with a slash character ('/'). An opaque URI has a scheme, a scheme-specific part, and possibly a fragment; all other components are undefined.
public String getRawSchemeSpecificPart()
The scheme-specific part of a URI only contains legal URI characters.
public String getSchemeSpecificPart()
The string returned by this method is equal to that returned by the
getRawSchemeSpecificPart
method
except that all sequences of escaped octets are decoded.
public String getRawAuthority()
The authority component of a URI, if defined, only contains the commercial-at character ('@') and characters in the unreserved, punct, escaped, and other categories. If the authority is server-based then it is further constrained to have valid user-information, host, and port components.
public String getAuthority()
The string returned by this method is equal to that returned by the
getRawAuthority
method except that all
sequences of escaped octets are decoded.
public String getRawUserInfo()
The user-information component of a URI, if defined, only contains characters in the unreserved, punct, escaped, and other categories.
public String getUserInfo()
The string returned by this method is equal to that returned by the
getRawUserInfo
method except that all
sequences of escaped octets are decoded.
public String getHost()
The host component of a URI, if defined, will have one of the following forms:
The host component of a URI cannot contain escaped octets, hence this method does not perform any decoding.
public int getPort()
The port component of a URI, if defined, is a non-negative integer.
public String getRawPath()
The path component of a URI, if defined, only contains the slash character ('/'), the commercial-at character ('@'), and characters in the unreserved, punct, escaped, and other categories.
public String getPath()
The string returned by this method is equal to that returned by the
getRawPath
method except that all sequences of
escaped octets are decoded.
public String getRawQuery()
The query component of a URI, if defined, only contains legal URI characters.
public String getQuery()
The string returned by this method is equal to that returned by the
getRawQuery
method except that all sequences of
escaped octets are decoded.
public String getRawFragment()
The fragment component of a URI, if defined, only contains legal URI characters.
public String getFragment()
The string returned by this method is equal to that returned by the
getRawFragment
method except that all
sequences of escaped octets are decoded.
public boolean equals(Object ob)
If the given object is not a URI then this method immediately returns false.
For two URIs to be considered equal requires that either both are opaque or both are hierarchical. Their schemes must either both be undefined or else be equal without regard to case. Their fragments must either both be undefined or else be equal.
For two opaque URIs to be considered equal, their scheme-specific parts must be equal.
For two hierarchical URIs to be considered equal, their paths must be equal and their queries must either both be undefined or else be equal. Their authorities must either both be undefined, or both be registry-based, or both be server-based. If their authorities are defined and are registry-based, then they must be equal. If their authorities are defined and are server-based, then their hosts must be equal without regard to case, their port numbers must be equal, and their user-information components must be equal.
When testing the user-information, path, query, fragment, authority, or scheme-specific parts of two URIs for equality, the raw forms rather than the encoded forms of these components are compared and the hexadecimal digits of escaped octets are compared without regard to case.
This method satisfies the general contract of the Object.equals
method.
public int hashCode()
Object.hashCode
method.public int compareTo(VFSURI that)
When comparing corresponding components of two URIs, if one
component is undefined but the other is defined then the first is
considered to be less than the second. Unless otherwise noted, string
components are ordered according to their natural, case-sensitive
ordering as defined by the String.compareTo
method. String components that are subject to
encoding are compared by comparing their raw forms rather than their
encoded forms.
The ordering of URIs is defined as follows:
This method satisfies the general contract of the Comparable.compareTo
method.
compareTo
in interface Comparable<VFSURI>
that
- The object to which this URI is to be comparedClassCastException
- If the given object is not a URIpublic String toString()
If this URI was created by invoking one of the constructors in this class then a string equivalent to the original input string, or to the string computed from the originally-given components, as appropriate, is returned. Otherwise this URI was created by normalization, resolution, or relativization, and so a string is constructed from this URI's components according to the rules specified in RFC 2396, section 5.2, step 7.
public String toASCIIString()
If this URI does not contain any characters in the other
category then an invocation of this method will return the same value as
an invocation of the toString
method. Otherwise
this method works as if by invoking that method and then encoding the result.
public void setFileType(org.apache.commons.vfs2.FileType type)
type
- The VFS type (optional)public org.apache.commons.vfs2.FileType getFileType()
Copyright © 2005-2024 Leisenfels GmbH. All rights reserved.