Package org.apache.cxf.jaxrs.model
Class URITemplate
- java.lang.Object
-
- org.apache.cxf.jaxrs.model.URITemplate
-
public final class URITemplate extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringFINAL_MATCH_GROUPstatic StringLIMITED_REGEX_SUFFIXstatic StringTEMPLATE_PARAMETERSstatic StringURI_TEMPLATE
-
Constructor Summary
Constructors Constructor Description URITemplate(String theTemplate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intcompareTemplates(URITemplate t1, URITemplate t2)static URITemplatecreateExactTemplate(String pathValue)static URITemplatecreateTemplate(String pathValue)static URITemplatecreateTemplate(javax.ws.rs.Path path)StringencodeLiteralCharacters(boolean isQuery)Encoded literal characters surrounding template variables, ex.List<String>getCustomVariables()List of variables with patterns (regexps).StringgetLiteralChars()StringgetPatternValue()StringgetValue()List<String>getVariables()List of all variables in order of appearance in template.booleanmatch(String uri, javax.ws.rs.core.MultivaluedMap<String,String> templateVariableToValue)Stringsubstitute(List<String> values)Substitutes template variables with listed values.Stringsubstitute(Map<String,? extends Object> valuesMap, Set<String> encodePathSlashVars, boolean allowUnresolved)Substitutes template variables with mapped values.
-
-
-
Field Detail
-
TEMPLATE_PARAMETERS
public static final String TEMPLATE_PARAMETERS
- See Also:
- Constant Field Values
-
URI_TEMPLATE
public static final String URI_TEMPLATE
- 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()
-
getPatternValue
public String getPatternValue()
-
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 fromgetVariables().- 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 forlist of variables. When list of value is shorter than variables substitution is partial. When variable has pattern, value must fit to pattern, otherwiseIllegalArgumentExceptionis 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, Set<String> encodePathSlashVars, boolean allowUnresolved) 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(boolean isQuery)
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)
-
createExactTemplate
public static URITemplate createExactTemplate(String pathValue)
-
compareTemplates
public static int compareTemplates(URITemplate t1, URITemplate t2)
-
-