public class URIPathDescriptor extends Object
Constructor and Description |
---|
URIPathDescriptor(String baseURI,
String link)
A URIPathDescriptor consists of a base URI and a link.
|
Modifier and Type | Method and Description |
---|---|
URI |
getBaseURI()
Return the base of this URIPathDescriptor as a URI.
|
URI |
getLink()
Return the link of this URIPathDescriptor as a URI.
|
URI |
rebaseLink(String newBase)
Calculate the link as viewed from a different base.
|
URI |
relativizeLink()
Calculate the relative link with respect to the base.
|
URI |
resolveLink()
Resolve the link to the base.
|
boolean |
sameSite(URI uri)
Check if this URIPathDescriptor lives on the same site as the given URI.
|
String |
toString()
Construct a string representation of this URIPathDescriptor.
|
public URIPathDescriptor(String baseURI, String link)
URI.isAbsolute()
.
Before being parsed to URI
s, the arguments are modified to catch
some common bad practices: first all Windows-style backslashes '\' are replaced by
forward slashes '/'.
If the baseURI does not end with '/', a slash is appended.
If the link starts with a '/', the first character is stripped.baseURI
- The base URI. Has to be a valid absolute URI.
In addition, the path of the URI should not have any file part,
ie http://maven.apache.org/
is valid,
http://maven.apache.org/index.html
is not.
Even though the latter form is accepted without warning,
the methods in this class will not return what is probably expected,
because a slash is appended during construction, as noted above.link
- the link. This may be a relative link or an absolute link.
Note that URIs that start with a "/", ie don't specify a scheme, are considered relative.IllegalArgumentException
- if either argument is not parsable as a URI,
or if baseURI is not absolute.public URI getBaseURI()
normalized
.public URI getLink()
normalized
.public URI resolveLink()
getBaseURI()
.resolve
( getLink()
).public URI relativizeLink()
same site
.public URI rebaseLink(String newBase)
resolveLink()
if either
newBase == null,
or newBase is not parsable as a URI,
or newBase and this getBaseURI()
do not share the
same site
.newBase
- the new base URI. Has to be parsable as a URI.
.resolved
,
i.e. as an absolute link, if the link cannot be re-based.public boolean sameSite(URI uri)
uri
- a URI to compare with.
May be null, in which case false is returned.getBaseURI()
shares the same scheme, host and port with the given URI
where null values are allowed.public String toString()
resolveLink()
.toString().Copyright © 2005–2024 The Apache Software Foundation. All rights reserved.