public abstract class UriComponents
extends java.lang.Object
implements java.io.Serializable
URI
, but with more powerful encoding options and support for
URI template variables.UriComponentsBuilder
,
Serialized FormModifier and Type | Class and Description |
---|---|
private static class |
UriComponents.MapTemplateVariables
URI template variables backed by a map.
|
static interface |
UriComponents.UriTemplateVariables
Defines the contract for URI Template variables.
|
private static class |
UriComponents.VarArgsTemplateVariables
URI template variables backed by a variable argument array.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
fragment |
private static java.util.regex.Pattern |
NAMES_PATTERN
Captures URI template variable names.
|
private java.lang.String |
scheme |
Modifier | Constructor and Description |
---|---|
protected |
UriComponents(java.lang.String scheme,
java.lang.String fragment) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
copyToUriComponentsBuilder(UriComponentsBuilder builder)
Set all components of the given UriComponentsBuilder.
|
UriComponents |
encode()
Invoke this after expanding URI variables to encode the
resulting URI component values.
|
abstract UriComponents |
encode(java.nio.charset.Charset charset)
A variant of
encode() with a charset other than "UTF-8". |
UriComponents |
expand(java.util.Map<java.lang.String,?> uriVariables)
Replace all URI template variables with the values from a given map.
|
UriComponents |
expand(java.lang.Object... uriVariableValues)
Replace all URI template variables with the values from a given array.
|
UriComponents |
expand(UriComponents.UriTemplateVariables uriVariables)
Replace all URI template variables with the values from the given
UriComponents.UriTemplateVariables . |
(package private) abstract UriComponents |
expandInternal(UriComponents.UriTemplateVariables uriVariables)
Replace all URI template variables with the values from the given
UriComponents.UriTemplateVariables . |
(package private) static java.lang.String |
expandUriComponent(java.lang.String source,
UriComponents.UriTemplateVariables uriVariables) |
(package private) static java.lang.String |
expandUriComponent(java.lang.String source,
UriComponents.UriTemplateVariables uriVariables,
java.util.function.UnaryOperator<java.lang.String> encoder) |
java.lang.String |
getFragment()
Return the fragment.
|
abstract java.lang.String |
getHost()
Return the host.
|
abstract java.lang.String |
getPath()
Return the path.
|
abstract java.util.List<java.lang.String> |
getPathSegments()
Return the list of path segments.
|
abstract int |
getPort()
Return the port.
|
abstract java.lang.String |
getQuery()
Return the query.
|
abstract MultiValueMap<java.lang.String,java.lang.String> |
getQueryParams()
Return the map of query parameters.
|
java.lang.String |
getScheme()
Return the scheme.
|
abstract java.lang.String |
getSchemeSpecificPart()
Return the scheme specific part.
|
abstract java.lang.String |
getUserInfo()
Return the user info.
|
private static java.lang.String |
getVariableName(java.lang.String match) |
private static java.lang.String |
getVariableValueAsString(java.lang.Object variableValue) |
abstract UriComponents |
normalize()
Normalize the path removing sequences like "path/..".
|
private static java.lang.String |
sanitizeSource(java.lang.String source)
Remove nested "{}" such as in URI vars with regular expressions.
|
java.lang.String |
toString()
A simple pass-through to
toUriString() . |
abstract java.net.URI |
toUri()
Create a
URI from this instance as follows: |
abstract java.lang.String |
toUriString()
Concatenate all URI components to return the fully formed URI String.
|
private static final java.util.regex.Pattern NAMES_PATTERN
@Nullable private final java.lang.String scheme
@Nullable private final java.lang.String fragment
@Nullable public final java.lang.String getScheme()
null
.@Nullable public final java.lang.String getFragment()
null
.@Nullable public abstract java.lang.String getSchemeSpecificPart()
null
.@Nullable public abstract java.lang.String getUserInfo()
null
.@Nullable public abstract java.lang.String getHost()
null
.public abstract int getPort()
-1
if no port has been set.@Nullable public abstract java.lang.String getPath()
null
.public abstract java.util.List<java.lang.String> getPathSegments()
@Nullable public abstract java.lang.String getQuery()
null
.public abstract MultiValueMap<java.lang.String,java.lang.String> getQueryParams()
public final UriComponents encode()
In comparison to UriComponentsBuilder.encode()
, this method
only replaces non-ASCII and illegal (within a given URI
component type) characters, but not characters with reserved meaning.
For most cases, UriComponentsBuilder.encode()
is more likely
to give the expected result.
UriComponentsBuilder.encode()
public abstract UriComponents encode(java.nio.charset.Charset charset)
encode()
with a charset other than "UTF-8".charset
- the charset to use for encodingUriComponentsBuilder.encode(Charset)
public final UriComponents expand(java.util.Map<java.lang.String,?> uriVariables)
The given map keys represent variable names; the corresponding values represent variable values. The order of variables is not significant.
uriVariables
- the map of URI variablespublic final UriComponents expand(java.lang.Object... uriVariableValues)
The given array represents variable values. The order of variables is significant.
uriVariableValues
- the URI variable valuespublic final UriComponents expand(UriComponents.UriTemplateVariables uriVariables)
UriComponents.UriTemplateVariables
.uriVariables
- the URI template valuesabstract UriComponents expandInternal(UriComponents.UriTemplateVariables uriVariables)
UriComponents.UriTemplateVariables
.uriVariables
- the URI template valuespublic abstract UriComponents normalize()
StringUtils.cleanPath(String)
public abstract java.lang.String toUriString()
This method does nothing more than a simple concatenation based on
current values. That means it could produce different results if invoked
before vs after methods that can change individual values such as
encode
, expand
, or normalize
.
public abstract java.net.URI toUri()
URI
from this instance as follows:
If the current instance is encoded
, form the full
URI String via toUriString()
, and then pass it to the single
argument URI
constructor which preserves percent encoding.
If not yet encoded, pass individual URI component values to the
multi-argument URI
constructor which quotes illegal characters
that cannot appear in their respective URI component.
public final java.lang.String toString()
toUriString()
.toString
in class java.lang.Object
protected abstract void copyToUriComponentsBuilder(UriComponentsBuilder builder)
@Nullable static java.lang.String expandUriComponent(@Nullable java.lang.String source, UriComponents.UriTemplateVariables uriVariables)
@Nullable static java.lang.String expandUriComponent(@Nullable java.lang.String source, UriComponents.UriTemplateVariables uriVariables, @Nullable java.util.function.UnaryOperator<java.lang.String> encoder)
private static java.lang.String sanitizeSource(java.lang.String source)
private static java.lang.String getVariableName(java.lang.String match)
private static java.lang.String getVariableValueAsString(@Nullable java.lang.Object variableValue)