public class DefaultUriBuilderFactory extends java.lang.Object implements UriBuilderFactory
UriBuilderFactory
that relies on UriComponentsBuilder
for
the actual building of the URI.
Provides options to create UriBuilder
instances with a common
base URI, alternative encoding mode strategies, among others.
UriComponentsBuilder
Modifier and Type | Class and Description |
---|---|
static class |
DefaultUriBuilderFactory.EncodingMode
Constants that represent different URI encoding strategies.
|
Constructor and Description |
---|
DefaultUriBuilderFactory()
Default constructor without a base URI.
|
DefaultUriBuilderFactory(java.lang.String baseUriTemplate)
Constructor with a base URI.
|
DefaultUriBuilderFactory(UriComponentsBuilder baseUri)
Variant of
DefaultUriBuilderFactory(String) with a
UriComponentsBuilder . |
Modifier and Type | Method and Description |
---|---|
UriBuilder |
builder()
Create a URI builder with default settings.
|
java.net.URI |
expand(java.lang.String uriTemplate,
java.util.Map<java.lang.String,?> uriVars)
Expand the given URI template with a map of URI variables.
|
java.net.URI |
expand(java.lang.String uriTemplate,
java.lang.Object... uriVars)
Expand the given URI template with an array of URI variables.
|
java.util.Map<java.lang.String,?> |
getDefaultUriVariables()
Return the configured default URI variable values.
|
DefaultUriBuilderFactory.EncodingMode |
getEncodingMode()
Return the configured encoding mode.
|
void |
setDefaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
Provide default URI variable values to use when expanding URI templates
with a Map of variables.
|
void |
setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode)
Specify the
EncodingMode to use when building URIs. |
void |
setParsePath(boolean parsePath)
Whether to parse the path into path segments for the URI string passed
into
uriString(String) or one of the expand methods. |
boolean |
shouldParsePath()
Whether the handler is configured to parse the path into path segments.
|
UriBuilder |
uriString(java.lang.String uriTemplate)
Initialize a builder with the given URI template.
|
public DefaultUriBuilderFactory()
The target address must be specified on each UriBuilder.
public DefaultUriBuilderFactory(java.lang.String baseUriTemplate)
The given URI template is parsed via
UriComponentsBuilder.fromUriString(java.lang.String)
and then applied as a base URI
to every UriBuilder via UriComponentsBuilder.uriComponents(org.springframework.web.util.UriComponents)
unless
the UriBuilder itself was created with a URI template that already has a
target address.
baseUriTemplate
- the URI template to use a base URLpublic DefaultUriBuilderFactory(UriComponentsBuilder baseUri)
DefaultUriBuilderFactory(String)
with a
UriComponentsBuilder
.public void setDefaultUriVariables(@Nullable java.util.Map<java.lang.String,?> defaultUriVariables)
defaultUriVariables
- default URI variable valuespublic java.util.Map<java.lang.String,?> getDefaultUriVariables()
public void setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode)
EncodingMode
to use when building URIs.
By default set to
EncodingMode.URI_COMPONENT
.
encodingMode
- the encoding mode to usepublic DefaultUriBuilderFactory.EncodingMode getEncodingMode()
public void setParsePath(boolean parsePath)
uriString(String)
or one of the expand methods.
Setting this property to true
ensures that URI variables
expanded into the path are subject to path segment encoding rules and
"/" characters are percent-encoded. If set to false
the path is
kept as a full path and expanded URI variables will have "/" characters
preserved.
By default this is set to true
.
parsePath
- whether to parse the path into path segmentspublic boolean shouldParsePath()
public java.net.URI expand(java.lang.String uriTemplate, java.util.Map<java.lang.String,?> uriVars)
UriTemplateHandler
expand
in interface UriTemplateHandler
uriTemplate
- the URI templateuriVars
- variable valuespublic java.net.URI expand(java.lang.String uriTemplate, java.lang.Object... uriVars)
UriTemplateHandler
expand
in interface UriTemplateHandler
uriTemplate
- the URI templateuriVars
- variable valuespublic UriBuilder uriString(java.lang.String uriTemplate)
UriBuilderFactory
uriString
in interface UriBuilderFactory
uriTemplate
- the URI template to usepublic UriBuilder builder()
UriBuilderFactory
builder
in interface UriBuilderFactory