public class PathTemplate extends java.lang.Object implements java.lang.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(java.lang.String template)
Creates a new path template for a RESTful web service.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(PathTemplate o) |
java.util.Map<java.lang.String,java.lang.String> |
extractVariableValues(java.lang.String path)
Extracts the template variable values from the path.
|
java.lang.String |
getTemplate()
Gets a template string from which this path template was created.
|
java.util.Collection<java.lang.String> |
getVariableNames()
Gets variable names extracted from the path template.
|
boolean |
matches(java.lang.String path)
Tells whether or not this template matches the given path.
|
public PathTemplate(java.lang.String template) throws InvalidPathTemplateException
template
- the path templateInvalidPathTemplateException
- if the template is not a valid path templatepublic boolean matches(java.lang.String path)
path
- the path this template should be matched totrue
if this template matches the given path; otherwise false
.public java.util.Map<java.lang.String,java.lang.String> extractVariableValues(java.lang.String path)
path
- the path to be matchedjava.lang.IllegalArgumentException
- if the path does not match this template.public java.util.Collection<java.lang.String> getVariableNames()
public java.lang.String getTemplate()
public int compareTo(PathTemplate o)
compareTo
in interface java.lang.Comparable<PathTemplate>
Copyright © 2007-2020 Whitestein Technologies. All Rights Reserved.