public class UriTemplate extends Object implements Serializable
{, }), which can be expanded to produce an actual URI.
See expand(Map), expand(Object[]), and match(String) for example usages.
| Constructor and Description |
|---|
UriTemplate(String uriTemplate)
Construct a new
UriTemplate with the given URI String. |
| Modifier and Type | Method and Description |
|---|---|
protected URI |
encodeUri(String uri)
Encodes the given String as URL.
|
URI |
expand(Map<String,?> uriVariables)
Given the Map of variables, expands this template into a URI.
|
URI |
expand(Object... uriVariableValues)
Given an array of variables, expand this template into a full URI.
|
String |
expandString(Map<String,?> uriVariables) |
String |
expandString(Object... uriVariableValues) |
List<String> |
getVariableNames()
Return the names of the variables in the template, in order.
|
Map<String,String> |
match(String uri)
Match the given URI to a map of variable values.
|
boolean |
matches(String uri)
Indicate whether the given URI matches this template.
|
String |
toString() |
public UriTemplate(String uriTemplate)
UriTemplate with the given URI String.uriTemplate - the URI template stringprotected URI encodeUri(String uri)
Defaults to UriUtils.encodeUri(String, String).
uri - the URI to encodepublic URI expand(Map<String,?> uriVariables)
Example:
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("booking", "42");
uriVariables.put("hotel", "1");
System.out.println(template.expand(uriVariables));
will print: http://example.com/hotels/1/bookings/42uriVariables - the map of URI variablesIllegalArgumentException - if uriVariables is null;
or if it does not contain values for all the variable namespublic URI expand(Object... uriVariableValues)
Example:
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
System.out.println(template.expand("1", "42));
will print: http://example.com/hotels/1/bookings/42uriVariableValues - the array of URI variablesIllegalArgumentException - if uriVariables is null
or if it does not contain sufficient variablespublic List<String> getVariableNames()
public Map<String,String> match(String uri)
Example:
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
System.out.println(template.match("http://example.com/hotels/1/bookings/42"));
will print: {hotel=1, booking=42}uri - the URI to match topublic boolean matches(String uri)
uri - the URI to match totrue if it matches; false otherwiseCopyright © 2015 Revolution Systems Inc.. All rights reserved.