public class DefaultUriBuilderFactory extends java.lang.Object implements UriBuilderFactory
UriBuilderFactory
providing options to
pre-configure all UriBuilder instances with common properties such as a base
URI, encoding mode, and default URI variables.
Uses UriComponentsBuilder
for URI building.
UriComponentsBuilder
Modifier and Type | Class and Description |
---|---|
static class |
DefaultUriBuilderFactory.EncodingMode |
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 builder with default settings.
|
java.net.URI |
expand(java.lang.String uriTemplate,
java.util.Map<java.lang.String,?> uriVars)
Expand the given URI template from a map of URI variables.
|
java.net.URI |
expand(java.lang.String uriTemplate,
java.lang.Object... uriVars)
Expand the given URI template from 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 encoding mode to use when building URIs:
URI_COMPONENT -- expand the URI variables first and then encode all URI
component (e.g.
|
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)
Create a builder from the given URI template string.
|
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)
By default this is set to "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 template stringuriVars
- the URI variablespublic java.net.URI expand(java.lang.String uriTemplate, java.lang.Object... uriVars)
UriTemplateHandler
expand
in interface UriTemplateHandler
uriTemplate
- the URI template stringuriVars
- the URI 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