public abstract class UriUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.net.URI |
buildUri(java.net.URI baseUri,
java.lang.String... pathSegments)
Create a new
URI out of the components. |
static java.util.Stack<java.net.URI> |
explode(java.net.URI baseUri,
java.net.URI uri)
Explode the given
URI into its component parts, as compared to the base URI . |
static <V> V |
foreach(java.net.URI baseUri,
java.net.URI uri,
Handler<java.net.URI,V> handler)
Execute the given
Handler for each segment in the URI . |
static java.net.URI |
merge(java.net.URI baseUri,
java.net.URI... uris)
Merge the components of these
URI s into a single URI. |
static java.lang.String |
path(java.net.URI uri)
Just the path portion of the
URI , but with any trailing slash "/" removed. |
static java.net.URI |
tail(java.net.URI baseUri,
java.net.URI uri)
The very last segment of the
URI . |
static boolean |
validBaseUri(java.net.URI baseUri,
java.net.URI uri)
Is the given
URI based on the "base" URI ? |
public static boolean validBaseUri(java.net.URI baseUri, java.net.URI uri)
URI
based on the "base" URI
?
e.g. given a base URI of http://localhost:8080/data and a URI of http://localhost:8080/data/person
, this method would report the baseUri being a valid base of the given URI.
baseUri
- URI
to check.uri
- URI
against which to compare the base.URI
, false otherwise.public static <V> V foreach(java.net.URI baseUri, java.net.URI uri, Handler<java.net.URI,V> handler)
Handler
for each segment in the URI
.
e.g. given a URI of http://localhost:8080/data/person/1 and a base URI of http://localhost:8080/data
, this method will explode the URI into it's components, as compared to the base URI.
The result would be: the given handler gets called twice, once passing a relative URI
of "person" and a
second time passing a relative URI
of "1".
V
- Return type of the handler.baseUri
- base URI
uri
- URI
to explode and iteratre over.handler
- Handler
to call for each segment of the URI's path.public static java.util.Stack<java.net.URI> explode(java.net.URI baseUri, java.net.URI uri)
URI
into its component parts, as compared to the base URI
.
Given a base URI of http://localhost:8080/data, exploding the URI http://localhost:8080/data/person/1
strips the first part of the URI, leaving person/1. This results
in
a Stack
of relative URI
s of size 2--one for "person" and one for "1".
baseUri
- base URI
uri
- URI
to explodeStack
of relative URI
s.public static java.net.URI merge(java.net.URI baseUri, java.net.URI... uris)
URI
s into a single URI. Useful for combining a relative URI with a base URI
and coming up with a full absolute URI.
e.g. merging base URI http://localhost:8080/data and relative uri person/1?name=John+Doe would result in an absolute URI of http://localhost:8080/data/person/1?name=John+Doe
baseUri
- base URI
uris
- URI
s to mergeURI
that is the combination of all the given (possibly relative, possibly absolute) URIs.public static java.lang.String path(java.net.URI uri)
URI
, but with any trailing slash "/" removed.uri
- public static java.net.URI tail(java.net.URI baseUri, java.net.URI uri)
URI
.baseUri
- base URI
uri
- URI
to explodeURI
that is the last segment of the path for the given URI.public static java.net.URI buildUri(java.net.URI baseUri, java.lang.String... pathSegments)
URI
out of the components.baseUri
- pathSegments
-