public class PathTemplate extends Object implements Comparable<PathTemplate>
A path template for RESTful web services.
The path template can contain variables in curly brackets. The variable has the following syntax:
{<variable-name>[:<regular-expression>]}
If the regular expression is not specified then the default pattern is used: ([^/]+?) when matching this template with a path.
Examples of path expression
/customers/{id}
/customer/{name: [\w]+?}/address
This class implements comparable. Paths which are considered more specific are considered less then those more generic.
Constructor and Description |
---|
PathTemplate(String template)
Creates a new path template for a RESTful web service.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(PathTemplate o) |
Map<String,String> |
extractVariableValues(String path)
Extracts the template variable values from the path.
|
String |
getTemplate()
Gets a template string from which this path template was created.
|
Collection<String> |
getVariableNames()
Gets variable names extracted from the path template.
|
boolean |
matches(String path)
Tells whether or not this template matches the given path.
|
public PathTemplate(String template) throws InvalidPathTemplateException
template
- the path templateInvalidPathTemplateException
- if the template is not a valid path templatepublic boolean matches(String path)
path
- the path this template should be matched totrue
if this template matches the given path; otherwise false
.public Map<String,String> extractVariableValues(String path)
path
- the path to be matchedIllegalArgumentException
- if the path does not match this template.public Collection<String> getVariableNames()
public String getTemplate()
public int compareTo(PathTemplate o)
compareTo
in interface Comparable<PathTemplate>
Copyright © 2007-2020 Whitestein Technologies. All Rights Reserved.