public class UriTemplate extends Object
Modifier and Type | Field and Description |
---|---|
static Comparator<UriTemplate> |
COMPARATOR
Order the templates according according to JAX-RS.
|
static UriTemplate |
EMPTY
The empty URI template that matches the null or empty URI path
|
Modifier | Constructor and Description |
---|---|
|
UriTemplate(String template)
Construct a new URI template.
|
protected |
UriTemplate(UriTemplateParser templateParser)
Construct a new URI template.
|
Modifier and Type | Method and Description |
---|---|
String |
createURI(Map<String,String> values)
Create a URI by substituting any template variables
for corresponding template values.
|
String |
createURI(String... values)
Create a URI by substituting any template variables
for corresponding template values.
|
String |
createURI(String[] values,
int offset,
int length)
Create a URI by substituting any template variables
for corresponding template values.
|
static String |
createURI(String scheme,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
Map<String,? extends Object> values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
static String |
createURI(String scheme,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
Object[] values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
static String |
createURI(String scheme,
String authority,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
Map<String,? extends Object> values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
static String |
createURI(String scheme,
String authority,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
Object[] values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
protected UriPattern |
createUriPattern(UriTemplateParser templateParser)
Create the URI pattern from a URI template parser.
|
static String |
createURIWithStringValues(String scheme,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
Map<String,? extends Object> values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
static String |
createURIWithStringValues(String scheme,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
String[] values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
static String |
createURIWithStringValues(String scheme,
String authority,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
Map<String,? extends Object> values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
static String |
createURIWithStringValues(String scheme,
String authority,
String userInfo,
String host,
String port,
String path,
String query,
String fragment,
String[] values,
boolean encode)
Construct a URI from the component parts each of which may contain
template variables.
|
UriTemplate |
destroy() |
boolean |
endsWithSlash() |
boolean |
equals(Object o)
Equality is calculated from the String of the regular expression
generated from the templates.
|
int |
getNumberOfExplicitCharacters()
Get the number of characters in the regular expression not resulting
from conversion of template variables.
|
int |
getNumberOfExplicitRegexes()
Get the number of explicit regexes declared in template variables.
|
int |
getNumberOfTemplateVariables()
Get the number of template variables.
|
UriPattern |
getPattern()
Get the URI pattern.
|
String |
getTemplate()
Get the URI template as a String.
|
List<String> |
getTemplateVariables()
Get the list of template variables for the template.
|
int |
hashCode()
Hashcode is calculated from String of the regular expression
generated from the template.
|
boolean |
isTemplateVariablePresent(String name)
Ascertain if a template variable is a member of this
template.
|
boolean |
match(CharSequence uri,
List<String> groupValues)
Match a URI against the template.
|
boolean |
match(CharSequence uri,
Map<String,String> templateVariableToValue)
Match a URI against the template.
|
String |
toString() |
public static final Comparator<UriTemplate> COMPARATOR
Sort the set of matching resource classes using the number of characters in the regular expression not resulting from template variables as the primary key, the number of matching groups as a secondary key, and the number of explicit regular expression declarations as the tertiary key.
public static final UriTemplate EMPTY
public UriTemplate(String template) throws PatternSyntaxException, IllegalArgumentException
The template will be parsed to extract template variables.
A specific regular expression will be generated from the template to match URIs according to the template and map template variables to template values.
template
- the template.PatternSyntaxException
- if the specified
regular expression could not be generatedIllegalArgumentException
- if the template is null or
an empty string.protected UriTemplate(UriTemplateParser templateParser) throws PatternSyntaxException, IllegalArgumentException
The template will be parsed to extract template variables.
A specific regular expression will be generated from the template to match URIs according to the template and map template variables to template values.
templateParser
- the parser to parse the template.PatternSyntaxException
- if the specified
regular expression could not be generatedIllegalArgumentException
- if the template is null or
an empty string.public UriTemplate destroy()
protected UriPattern createUriPattern(UriTemplateParser templateParser)
templateParser
- the URI template parser.public final String getTemplate()
public final UriPattern getPattern()
public final boolean endsWithSlash()
public final List<String> getTemplateVariables()
public final boolean isTemplateVariablePresent(String name)
name
- name The template variable.public final int getNumberOfExplicitRegexes()
public final int getNumberOfExplicitCharacters()
public final int getNumberOfTemplateVariables()
public final boolean match(CharSequence uri, Map<String,String> templateVariableToValue) throws IllegalArgumentException
If the URI matches against the pattern then the template variable to value map will be filled with template variables as keys and template values as values.
uri
- the uri to match against the template.templateVariableToValue
- the map where to put template variables (as keys)
and template values (as values). The map is cleared before any
entries are put.IllegalArgumentException
- if the uri or
templateVariableToValue is null.public final boolean match(CharSequence uri, List<String> groupValues) throws IllegalArgumentException
If the URI matches against the pattern then the template variable to value map will be filled with template variables as keys and template values as values.
uri
- the uri to match against the template.groupValues
- the list to store the values of a pattern's
capturing groups is matching is successful. The values are stored
in the same order as the pattern's capturing groups.IllegalArgumentException
- if the uri or
templateVariableToValue is null.public final String createURI(Map<String,String> values)
A URI template variable without a value will be substituted by the empty string.
values
- the map of template variables to template values.public final String createURI(String... values)
A URI template varibale without a value will be substituted by the empty string.
values
- the array of template values. The values will be
substituted in order of occurence of unique template variables.public final String createURI(String[] values, int offset, int length)
A URI template variable without a value will be substituted by the empty string.
values
- the array of template values. The values will be
substituted in order of occurence of unique template variables.offset
- the offset into the arraylength
- the length of the arraypublic final int hashCode()
public final boolean equals(Object o)
public static final String createURI(String scheme, String userInfo, String host, String port, String path, String query, String fragment, Map<String,? extends Object> values, boolean encode)
A template values is an Object instance MUST support the toString() method to convert the template value to a String instance.
scheme
- the URI scheme componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the template variable to value mapencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valuepublic static final String createURI(String scheme, String authority, String userInfo, String host, String port, String path, String query, String fragment, Map<String,? extends Object> values, boolean encode)
A template values is an Object instance MUST support the toString() method to convert the template value to a String instance.
scheme
- the URI scheme componentauthority
- the URI authority componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the template variable to value mapencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valuepublic static final String createURIWithStringValues(String scheme, String userInfo, String host, String port, String path, String query, String fragment, Map<String,? extends Object> values, boolean encode)
A template value is an Object instance that MUST support the toString() method to convert the template value to a String instance.
scheme
- the URI scheme componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the template variable to value mapencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valuepublic static final String createURIWithStringValues(String scheme, String authority, String userInfo, String host, String port, String path, String query, String fragment, Map<String,? extends Object> values, boolean encode)
A template value is an Object instance that MUST support the toString() method to convert the template value to a String instance.
scheme
- the URI scheme componentauthority
- the URI authority info componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the template variable to value mapencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valuepublic static final String createURI(String scheme, String userInfo, String host, String port, String path, String query, String fragment, Object[] values, boolean encode)
The template values are an array of Object and each Object instance MUST support the toString() method to convert the template value to a String instance.
scheme
- the URI scheme componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the array of template valuesencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valuepublic static final String createURI(String scheme, String authority, String userInfo, String host, String port, String path, String query, String fragment, Object[] values, boolean encode)
The template values are an array of Object and each Object instance MUST support the toString() method to convert the template value to a String instance.
scheme
- the URI scheme componentauthority
- the URI authority componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the array of template valuesencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valuepublic static final String createURIWithStringValues(String scheme, String userInfo, String host, String port, String path, String query, String fragment, String[] values, boolean encode)
scheme
- the URI scheme componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the array of template valuesencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valuepublic static final String createURIWithStringValues(String scheme, String authority, String userInfo, String host, String port, String path, String query, String fragment, String[] values, boolean encode)
scheme
- the URI scheme componentauthority
- the URI authority componentuserInfo
- the URI user info componenthost
- the URI host componentport
- the URI port componentpath
- the URI path componentquery
- the URI query componnetfragment
- the URI fragment componentvalues
- the array of template valuesencode
- if true encode a template value according to the correspond
component type of the associated template variable, otherwise
contextually encode the template valueCopyright © 2016. All rights reserved.