expand(Map), expand(Object[]), or matched to a URL via
match(String). This class is designed to be thread-safe and
reusable, and allows any number of expand or match calls.Note
this class uses UriComponentsBuilder
internally to expand URI templates, and is merely a shortcut for already
prepared URI templates. For more dynamic preparation and extra flexibility,
e.g. around URI encoding, consider using UriComponentsBuilder or the
higher level DefaultUriBuilderFactory which adds several encoding
modes on top of UriComponentsBuilder. See the
reference docs
for further details.
| Modifier and Type | Class and Description |
|---|---|
| private static class | UriTemplate.TemplateInfo
Helper to extract variable names and regex for matching to actual URLs. |
| Modifier and Type | Field and Description |
|---|---|
| private final Pattern | |
| private final UriComponents | |
| private final String | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public | UriTemplate(String
the URI template string uriTemplate)Construct a new |
| Modifier and Type | Method and Description |
|---|---|
| public URI | |
| public URI | |
| public List | Returns: the template variable namesReturn the names of the variables in the template, in order. |
| public Map | |
| public boolean | |
| public String |
| matchPattern | back to summary |
|---|---|
| private final Pattern matchPattern | |
| uriComponents | back to summary |
|---|---|
| private final UriComponents uriComponents | |
| uriTemplate | back to summary |
|---|---|
| private final String uriTemplate | |
| variableNames | back to summary |
|---|---|
| private final List<String> variableNames | |
| UriTemplate | back to summary |
|---|---|
| public UriTemplate(String uriTemplate) Construct a new
| |
| expand | back to summary |
|---|---|
| public URI expand(Map<String, ?> uriVariables) Given the Map of variables, expands this template into a URI. The Map keys represent variable names, the Map values variable values. The order of variables is not significant. Example:
UriTemplate template = new UriTemplate("https://example.com/hotels/{hotel}/bookings/{booking}");
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("booking", "42");
uriVariables.put("hotel", "Rest & Relax");
System.out.println(template.expand(uriVariables));
will print:
| |
| expand | back to summary |
|---|---|
| public URI expand(Object... uriVariableValues) Given an array of variables, expand this template into a full URI. The array represent variable values. The order of variables is significant. Example:
UriTemplate template = new UriTemplate("https://example.com/hotels/{hotel}/bookings/{booking}");
System.out.println(template.expand("Rest & Relax", 42));
will print:
| |
| getVariableNames | back to summary |
|---|---|
| public List Return the names of the variables in the template, in order. | |
| match | back to summary |
|---|---|
| public Map Match the given URI to a map of variable values. Keys in the returned map are variable names, values are variable values, as occurred in the given URI. Example:
UriTemplate template = new UriTemplate("https://example.com/hotels/{hotel}/bookings/{booking}");
System.out.println(template.match("https://example.com/hotels/1/bookings/42"));
will print:
| |
| matches | back to summary |
|---|---|
| public boolean matches(String uri) Indicate whether the given URI matches this template.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| private final Pattern | |
| private final List |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Pattern | |
| public List | |
| public static UriTemplate. | |
| private static String |
| pattern | back to summary |
|---|---|
| private final Pattern pattern | |
| variableNames | back to summary |
|---|---|
| private final List<String> variableNames | |
| TemplateInfo | back to summary |
|---|---|
| private TemplateInfo(List<String> vars, Pattern pattern) | |
| getMatchPattern | back to summary |
|---|---|
| public Pattern getMatchPattern() | |
| getVariableNames | back to summary |
|---|---|
| public List | |
| parse | back to summary |
|---|---|
| public static UriTemplate. | |
| quote | back to summary |
|---|---|
| private static String quote(StringBuilder builder) | |