spring-framework / org.springframework.web.util / DefaultUriBuilderFactory

DefaultUriBuilderFactory

open class DefaultUriBuilderFactory : UriBuilderFactory

Default implementation of 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.

Author
Rossen Stoyanchev

Since
5.0

See Also
UriComponentsBuilder

Constructors

<init>

DefaultUriBuilderFactory()

Default constructor without a base URI.

The target address must be specified on each UriBuilder.

DefaultUriBuilderFactory(baseUriTemplate: String)

Constructor with a base URI.

The given URI template is parsed via UriComponentsBuilder#fromUriString and then applied as a base URI to every UriBuilder via UriComponentsBuilder#uriComponents unless the UriBuilder itself was created with a URI template that already has a target address.

DefaultUriBuilderFactory(baseUri: UriComponentsBuilder)

Variant of #DefaultUriBuilderFactory(String) with a UriComponentsBuilder.

Functions

builder

open fun builder(): UriBuilder

expand

open fun expand(uriTemplate: String, uriVars: MutableMap<String, *>): URI
open fun expand(uriTemplate: String, vararg uriVars: Any): URI

getDefaultUriVariables

open fun getDefaultUriVariables(): MutableMap<String, *>

Return the configured default URI variable values.

getEncodingMode

open fun getEncodingMode(): EncodingMode

Return the configured encoding mode.

setDefaultUriVariables

open fun setDefaultUriVariables(defaultUriVariables: MutableMap<String, *>): Unit

Provide default URI variable values to use when expanding URI templates with a Map of variables.

setEncodingMode

open fun setEncodingMode(encodingMode: EncodingMode): Unit

Specify the encoding mode to use when building URIs:

  • URI_COMPONENT -- expand the URI variables first and then encode all URI component (e.g. host, path, query, etc) according to the encoding rules for each individual component.
  • VALUES_ONLY -- encode URI variable values only, prior to expanding them, using a "strict" encoding mode, i.e. encoding all characters outside the unreserved set as defined in RFC 3986 Section 2. This ensures a URI variable value will not contain any characters with a reserved purpose.
  • NONE -- in this mode no encoding is performed.

By default this is set to "URI_COMPONENT".

setParsePath

open fun setParsePath(parsePath: Boolean): Unit

Whether to parse the path into path segments for the URI string passed into #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.

shouldParsePath

open fun shouldParsePath(): Boolean

Whether the handler is configured to parse the path into path segments.

uriString

open fun uriString(uriTemplate: String): UriBuilder