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."context:/" - Context-root URI."servlet:/foo" - Servlet-path-relative URI."servlet:/" - Servlet-path URI."request:/foo" - Request-path-relative URI."request:/" - Request-path URI."foo" - Path-info-relative URI."" - Path-info URI.
See Also:
-
Constructor Summary
ConstructorDescriptionUriResolver
(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 UriResolver
of
(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
UriResolver
object.
-
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."context:/" - Context-root URI."servlet:/foo" - Servlet-path-relative URI."servlet:/" - Servlet-path URI."request:/foo" - Request-path-relative URI."request:/" - Request-path URI."foo" - Path-info-relative URI."" - Path-info URI.
- Returns:
- The converted URI.
-
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.
-
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.
-