Class UriTemplate (1.42.3)

public class UriTemplate

Expands URI Templates.

This Class supports Level 1 templates and all Level 4 composite templates as described in: RFC 6570.

Specifically, for the variables: var := "value" list := ["red", "green", "blue"] keys := [("semi", ";"),("dot", "."),("comma", ",")]

The following templates results in the following expansions: {var} -> value {list} -> red,green,blue {list} -> red,green,blue {keys} -> semi,%3B,dot,.,comma,%2C {keys} -> semi=%3B,dot=.,comma=%2C {+list} -> red,green,blue {+list} -> red,green,blue {+keys} -> semi,;,dot,.,comma,, {+keys} -> semi=;,dot=.,comma=, {#list} -> #red,green,blue {#list*} ->

red,green,blue {#keys} -> #semi,;,dot,.,comma,, {#keys*} -> #semi=;,dot=.,comma=, X{.list} ->

X.red,green,blue X{.list} -> X.red.green.blue X{.keys} -> X.semi,%3B,dot,.,comma,%2C X{.keys} -> X.semi=%3B.dot=..comma=%2C {/list} -> /red,green,blue {/list} -> /red/green/blue {/keys} -> /semi,%3B,dot,.,comma,%2C {/keys} -> /semi=%3B/dot=./comma=%2C {;list} -> ;list=red,green,blue {;list} -> ;list=red;list=green;list=blue {;keys} -> ;keys=semi,%3B,dot,.,comma,%2C {;keys} -> ;semi=%3B;dot=.;comma=%2C {?list} -> ?list=red,green,blue {?list} -> ?list=red&list=green&list=blue {?keys} -> ?keys=semi,%3B,dot,.,comma,%2C {?keys} -> ?semi=%3B&dot=.&comma=%2C {&list} -> &list=red,green,blue {&list} -> &list=red&list=green&list=blue {&keys} -> &keys=semi,%3B,dot,.,comma,%2C {&keys} -> &semi=%3B&dot=.&comma=%2C {?var,list} -> ?var=value&list=red,green,blue

Inheritance

Object > UriTemplate

Static Methods

expand(String pathUri, Object parameters, boolean addUnusedParamsAsQueryParams)

public static String expand(String pathUri, Object parameters, boolean addUnusedParamsAsQueryParams)

Expands templates in a URI.

Supports Level 1 templates and all Level 4 composite templates as described in: RFC 6570.

Parameters
NameDescription
pathUriString

URI component. It may contain one or more sequences of the form "{name}", where "name" must be a key in variableMap

parametersObject

an object with parameters designated by Key annotations. If the template has no variable references, parameters may be null.

addUnusedParamsAsQueryParamsboolean

If true then parameters that do not match the template are appended to the expanded template as query parameters.

Returns
TypeDescription
String

The expanded template

expand(String baseUrl, String uriTemplate, Object parameters, boolean addUnusedParamsAsQueryParams)

public static String expand(String baseUrl, String uriTemplate, Object parameters, boolean addUnusedParamsAsQueryParams)

Expands templates in a URI template that is relative to a base URL.

If the URI template starts with a "/" the raw path from the base URL is stripped out. If the URI template is a full URL then it is used instead of the base URL.

Supports Level 1 templates and all Level 4 composite templates as described in: RFC 6570.

Parameters
NameDescription
baseUrlString

The base URL which the URI component is relative to.

uriTemplateString

URI component. It may contain one or more sequences of the form "{name}", where "name" must be a key in variableMap.

parametersObject

an object with parameters designated by Key annotations. If the template has no variable references, parameters may be null.

addUnusedParamsAsQueryParamsboolean

If true then parameters that do not match the template are appended to the expanded template as query parameters.

Returns
TypeDescription
String

The expanded template

Constructors

UriTemplate()

public UriTemplate()