Apache CXF API

org.apache.cxf.jaxrs.model
Class URITemplate

java.lang.Object
  extended by org.apache.cxf.jaxrs.model.URITemplate

public final class URITemplate
extends Object


Field Summary
static String FINAL_MATCH_GROUP
           
static String LIMITED_REGEX_SUFFIX
           
static String TEMPLATE_PARAMETERS
           
 
Constructor Summary
URITemplate(String theTemplate)
           
 
Method Summary
static int compareTemplates(URITemplate t1, URITemplate t2)
           
static URITemplate createTemplate(javax.ws.rs.Path path)
           
static URITemplate createTemplate(String pathValue)
           
 String encodeLiteralCharacters()
          Encoded literal characters surrounding template variables, ex.
 List<String> getCustomVariables()
          List of variables with patterns (regexps).
 String getLiteralChars()
           
 String getValue()
           
 List<String> getVariables()
          List of all variables in order of appearance in template.
 boolean match(String uri, javax.ws.rs.core.MultivaluedMap<String,String> templateVariableToValue)
           
 String substitute(List<String> values)
          Substitutes template variables with listed values.
 String substitute(Map<String,? extends Object> valuesMap)
          Substitutes template variables with mapped values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMPLATE_PARAMETERS

public static final String TEMPLATE_PARAMETERS
See Also:
Constant Field Values

LIMITED_REGEX_SUFFIX

public static final String LIMITED_REGEX_SUFFIX
See Also:
Constant Field Values

FINAL_MATCH_GROUP

public static final String FINAL_MATCH_GROUP
See Also:
Constant Field Values
Constructor Detail

URITemplate

public URITemplate(String theTemplate)
Method Detail

getLiteralChars

public String getLiteralChars()

getValue

public String getValue()

getVariables

public List<String> getVariables()
List of all variables in order of appearance in template.

Returns:
unmodifiable list of variable names w/o patterns, e.g. for "/foo/{v1:\\d}/{v2}" returned list is ["v1","v2"].

getCustomVariables

public List<String> getCustomVariables()
List of variables with patterns (regexps). List is subset of elements from getVariables().

Returns:
unmodifiable list of variables names w/o patterns.

match

public boolean match(String uri,
                     javax.ws.rs.core.MultivaluedMap<String,String> templateVariableToValue)

substitute

public String substitute(List<String> values)
                  throws IllegalArgumentException
Substitutes template variables with listed values. List of values is counterpart for list of variables. When list of value is shorter than variables substitution is partial. When variable has pattern, value must fit to pattern, otherwise IllegalArgumentException is thrown.

Example1: for template "/{a}/{b}/{a}" getVariables() returns "[a, b, a]"; providing here list of value "[foo, bar, baz]" results with "/foo/bar/baz".

Example2: for template "/{a}/{b}/{a}" providing list of values "[foo]" results with "/foo/{b}/{a}".

Parameters:
values - values for variables
Returns:
template with bound variables.
Throws:
IllegalArgumentException - when values is null, any value does not match pattern etc.

substitute

public String substitute(Map<String,? extends Object> valuesMap)
                  throws IllegalArgumentException
Substitutes template variables with mapped values. Variables are mapped to values; if not all variables are bound result will still contain variables. Note that all variables with the same name are replaced by one value.

Example: for template "/{a}/{b}/{a}" getVariables() returns "[a, b, a]"; providing here mapping "[a: foo, b: bar]" results with "/foo/bar/foo" (full substitution) and for mapping "[b: baz]" result is "{a}/baz/{a}" (partial substitution).

Parameters:
valuesMap - map variables to their values; on each value Object.toString() is called.
Returns:
template with bound variables.
Throws:
IllegalArgumentException

encodeLiteralCharacters

public String encodeLiteralCharacters()
Encoded literal characters surrounding template variables, ex. "a {id} b" will be encoded to "a%20{id}%20b"

Returns:
encoded value

createTemplate

public static URITemplate createTemplate(javax.ws.rs.Path path)

createTemplate

public static URITemplate createTemplate(String pathValue)

compareTemplates

public static int compareTemplates(URITemplate t1,
                                   URITemplate t2)

Apache CXF API

Apache CXF