Class UriTemplate
- Author:
- Paul.Sandoz@Sun.Com
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<UriTemplate> Order the templates according according to JAX-RS.static final UriTemplateThe empty URI template that matches the null or empty URI path -
Constructor Summary
ConstructorsModifierConstructorDescriptionUriTemplate(String template) Construct a new URI template.protectedUriTemplate(UriTemplateParser templateParser) Construct a new URI template. -
Method Summary
Modifier and TypeMethodDescriptionfinal StringCreate a URI by substituting any template variables for corresponding template values.final StringCreate a URI by substituting any template variables for corresponding template values.static StringcreateURI(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 StringcreateURI(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.static final StringcreateURI(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 StringcreateURI(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.final StringCreate a URI by substituting any template variables for corresponding template values.protected UriPatterncreateUriPattern(UriTemplateParser templateParser) Create the URI pattern from a URI template parser.static StringcreateURIWithStringValues(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 StringcreateURIWithStringValues(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.static StringcreateURIWithStringValues(String scheme, String authority, String userInfo, String host, String port, String path, String query, String fragment, Map<String, ?> values, boolean encode) Construct a URI from the component parts each of which may contain template variables.static final StringcreateURIWithStringValues(String scheme, String userInfo, String host, String port, String path, String query, String fragment, Map<String, ?> values, boolean encode) Construct a URI from the component parts each of which may contain template variables.destroy()final booleanfinal booleanEquality is calculated from the String of the regular expression generated from the templates.final intGet the number of characters in the regular expression not resulting from conversion of template variables.final intGet the number of explicit regexes declared in template variables.final intGet the number of template variables.final UriPatternGet the URI pattern.final StringGet the URI template as a String.Get the list of template variables for the template.final inthashCode()Hashcode is calculated from String of the regular expression generated from the template.final booleanAscertain if a template variable is a member of this template.final booleanmatch(CharSequence uri, List<String> groupValues) Match a URI against the template.final booleanmatch(CharSequence uri, Map<String, String> templateVariableToValue) Match a URI against the template.final StringtoString()
-
Field Details
-
COMPARATOR
Order the templates according according to JAX-RS.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.
-
EMPTY
The empty URI template that matches the null or empty URI path
-
-
Constructor Details
-
UriTemplate
Construct a new URI template.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.
- Parameters:
template- the template.- Throws:
PatternSyntaxException- if the specified regular expression could not be generatedIllegalArgumentException- if the template is null or an empty string.
-
UriTemplate
protected UriTemplate(UriTemplateParser templateParser) throws PatternSyntaxException, IllegalArgumentException Construct a new URI template.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.
- Parameters:
templateParser- the parser to parse the template.- Throws:
PatternSyntaxException- if the specified regular expression could not be generatedIllegalArgumentException- if the template is null or an empty string.
-
-
Method Details
-
destroy
-
createUriPattern
Create the URI pattern from a URI template parser.- Parameters:
templateParser- the URI template parser.- Returns:
- the URI pattern.
-
getTemplate
Get the URI template as a String.- Returns:
- the URI template.
-
getPattern
Get the URI pattern.- Returns:
- the URI pattern.
-
endsWithSlash
public final boolean endsWithSlash()- Returns:
- true if the template ends in a '/', otherwise false.
-
getTemplateVariables
Get the list of template variables for the template.- Returns:
- the list of template variables.
-
isTemplateVariablePresent
Ascertain if a template variable is a member of this template.- Parameters:
name- name The template variable.- Returns:
- true if the template variable is a member of the template, otherwise false.
-
getNumberOfExplicitRegexes
public final int getNumberOfExplicitRegexes()Get the number of explicit regexes declared in template variables.- Returns:
- the number of explicit regexes.
-
getNumberOfExplicitCharacters
public final int getNumberOfExplicitCharacters()Get the number of characters in the regular expression not resulting from conversion of template variables.- Returns:
- the number of explicit characters
-
getNumberOfTemplateVariables
public final int getNumberOfTemplateVariables()Get the number of template variables.- Returns:
- the number of template variables.
-
match
public final boolean match(CharSequence uri, Map<String, String> templateVariableToValue) throws IllegalArgumentExceptionMatch a URI against the template.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.
- Parameters:
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.- Returns:
- true if the URI matches the template, otherwise false.
- Throws:
IllegalArgumentException- if the uri or templateVariableToValue is null.
-
match
public final boolean match(CharSequence uri, List<String> groupValues) throws IllegalArgumentException Match a URI against the template.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.
- Parameters:
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.- Returns:
- true if the URI matches the template, otherwise false.
- Throws:
IllegalArgumentException- if the uri or templateVariableToValue is null.
-
createURI
Create a URI by substituting any template variables for corresponding template values.A URI template variable without a value will be substituted by the empty string.
- Parameters:
values- the map of template variables to template values.- Returns:
- the URI.
-
createURI
Create a URI by substituting any template variables for corresponding template values.A URI template varibale without a value will be substituted by the empty string.
- Parameters:
values- the array of template values. The values will be substituted in order of occurence of unique template variables.- Returns:
- the URI.
-
createURI
Create a URI by substituting any template variables for corresponding template values.A URI template variable without a value will be substituted by the empty string.
- Parameters:
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 array- Returns:
- the URI.
-
toString
-
hashCode
public final int hashCode()Hashcode is calculated from String of the regular expression generated from the template. -
equals
Equality is calculated from the String of the regular expression generated from the templates. -
createURI
public 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.A template values is an Object instance MUST support the toString() method to convert the template value to a String instance.
- Parameters:
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 value- Returns:
- a URI
-
createURI
public 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) Construct a URI from the component parts each of which may contain template variables.A template values is an Object instance MUST support the toString() method to convert the template value to a String instance.
- Parameters:
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 value- Returns:
- a URI
-
createURIWithStringValues
public static final String createURIWithStringValues(String scheme, String userInfo, String host, String port, String path, String query, String fragment, Map<String, ?> values, boolean encode) Construct a URI from the component parts each of which may contain template variables.A template value is an Object instance that MUST support the toString() method to convert the template value to a String instance.
- Parameters:
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 value- Returns:
- a URI
-
createURIWithStringValues
public static String createURIWithStringValues(String scheme, String authority, String userInfo, String host, String port, String path, String query, String fragment, Map<String, ?> values, boolean encode) Construct a URI from the component parts each of which may contain template variables.A template value is an Object instance that MUST support the toString() method to convert the template value to a String instance.
- Parameters:
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 value- Returns:
- a URI
-
createURI
public 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.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.
- Parameters:
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 value- Returns:
- a URI
-
createURI
public 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.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.
- Parameters:
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 value- Returns:
- a URI
-
createURIWithStringValues
public 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.- Parameters:
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 value- Returns:
- a URI
-
createURIWithStringValues
public 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.- Parameters:
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 value- Returns:
- a URI
-