Class UriResolver
Combines a UriContext instance with rules for resolution (UriResolution and relativity
(UriRelativity) to define simple resolve(Object) and append(Appendable, Object) methods.
Three special protocols are used to represent context-root-relative, servlet-relative, and request-path-relative
URIs:
The following list shows the protocols of URLs that can be resolved with this class:
"foo://foo" - Absolute URI."/foo" - Root-relative URI."/" - Root URI."context:/foo" - Context-root-relative URI with path."context:/" - Context-root URI."context:?foo=bar" - Context-root URI with query string."servlet:/foo" - Servlet-path-relative URI with path."servlet:/" - Servlet-path URI."servlet:?foo=bar" - Servlet-path URI with query string."request:/foo" - Request-path-relative URI with path."request:/" - Request-path URI."request:?foo=bar" - Request-path URI with query string."foo" - Path-info-relative URI."" - Path-info URI.
-
Constructor Summary
ConstructorsConstructorDescriptionUriResolver(UriResolution resolution, UriRelativity relativity, UriContext uriContext) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionappend(Appendable a, Object o) Same asresolve(Object)except appends result to the specified appendable.static UriResolverof(UriResolution resolution, UriRelativity relativity, UriContext uriContext) Static creator.relativize(Object relativeTo, Object uri) Relativizes a URI.Converts the specified URI to absolute form based on values in this context.
-
Constructor Details
-
UriResolver
Constructor.- Parameters:
resolution- Rule on how URIs should be resolved.relativity- Rule on what relative URIs are relative to.uriContext- Current URI context (i.e. the current URI 'location').
-
-
Method Details
-
of
public static UriResolver of(UriResolution resolution, UriRelativity relativity, UriContext uriContext) Static creator.- Parameters:
resolution- Rule on how URIs should be resolved.relativity- Rule on what relative URIs are relative to.uriContext- Current URI context (i.e. the current URI 'location').- Returns:
- A new
UriResolverobject.
-
append
Same asresolve(Object)except appends result to the specified appendable.- Parameters:
a- The appendable to append the URL to.o- The URI to convert to absolute form.- Returns:
- The same appendable passed in.
-
relativize
Relativizes a URI.Similar to
URI.relativize(URI), except supports special protocols (e.g."servlet:/" ) for both therelativeTo anduri parameters.For example, to relativize a URI to its servlet-relative form:
// relativeUri == "path/foo" StringrelativeUri =resolver .relativize("servlet:/" ,"/context/servlet/path/foo" );- Parameters:
relativeTo- The URI to relativize against.uri- The URI to relativize.- Returns:
- The relativized URI.
-
resolve
Converts the specified URI to absolute form based on values in this context.- Parameters:
uri- The URI to convert to absolute form. Can be any of the following: URI can be any of the following forms:"foo://foo" - Absolute URI."/foo" - Root-relative URI."/" - Root URI."context:/foo" - Context-root-relative URI with path."context:/" - Context-root URI."context:?foo=bar" - Context-root URI with query string."servlet:/foo" - Servlet-path-relative URI with path."servlet:/" - Servlet-path URI."servlet:?foo=bar" - Servlet-path URI with query string."request:/foo" - Request-path-relative URI with path."request:/" - Request-path URI."request:?foo=bar" - Request-path URI with query string."foo" - Path-info-relative URI."" - Path-info URI.
- Returns:
- The converted URI.
-