Package org.atmosphere.util.uri
Class UriPattern
java.lang.Object
org.atmosphere.util.uri.UriPattern
A URI pattern for matching a URI against a regular expression
and returning capturing group values for any capturing groups present in
the expression.
- Author:
- Paul.Sandoz@Sun.Com
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UriPatternThe empty URI pattern that matches the null or empty URI path -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstruct an empty pattern.UriPattern(String regex) Construct a new URI pattern.UriPattern(String regex, int[] groupIndexes) Construct a new URI pattern.UriPattern(Pattern regexPattern) Construct a new URI pattern.UriPattern(Pattern regexPattern, int[] groupIndexes) Construct a new URI pattern. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanfinal int[]Get the group indexes.final StringgetRegex()Get the regular expression.final inthashCode()final MatchResultmatch(CharSequence uri) Match a URI against the pattern.final booleanmatch(CharSequence uri, List<String> groupValues) Match a URI against the pattern.final booleanMatch a URI against the pattern.final StringtoString()
-
Field Details
-
EMPTY
The empty URI pattern that matches the null or empty URI path
-
-
Constructor Details
-
UriPattern
protected UriPattern()Construct an empty pattern. -
UriPattern
Construct a new URI pattern.- Parameters:
regex- the regular expression. If the expression is null or an empty string then the pattern will only match a null or empty URI path.- Throws:
PatternSyntaxException- if the regular expression could not be compiled
-
UriPattern
Construct a new URI pattern.- Parameters:
regex- the regular expression. If the expression is null or an empty string then the pattern will only match a null or empty URI path.groupIndexes- the array of group indexes to capturing groups.- Throws:
PatternSyntaxException- if the regular expression could not be compiled
-
UriPattern
Construct a new URI pattern.- Parameters:
regexPattern- the regular expression pattern- Throws:
IllegalArgumentException- if the regexPattern is null.
-
UriPattern
Construct a new URI pattern.- Parameters:
regexPattern- the regular expression patterngroupIndexes- the array of group indexes to capturing groups.- Throws:
IllegalArgumentException- if the regexPattern is null.
-
-
Method Details
-
getRegex
Get the regular expression.- Returns:
- the regular expression.
-
getGroupIndexes
public final int[] getGroupIndexes()Get the group indexes.- Returns:
- the group indexes.
-
match
Match a URI against the pattern.- Parameters:
uri- the uri to match against the template.- Returns:
- the match result, otherwise null if no match occurs.
-
match
Match a URI against the pattern.If the URI matches against the pattern then the capturing group values (if any) will be added to a list passed in as parameter.
- Parameters:
uri- the uri to match against the template.groupValues- the list to add the values of a pattern's capturing groups if matching is successful. The values are added in the same order as the pattern's capturing groups. The list is cleared before values are added.- Returns:
- true if the URI matches the pattern, otherwise false.
- Throws:
IllegalArgumentException- if the uri or capturingGroupValues is null.
-
match
public final boolean match(CharSequence uri, List<String> groupNames, Map<String, String> groupValues) Match a URI against the pattern.If the URI matches against the pattern then the capturing group values (if any) will be added to a map passed in as parameter.
- Parameters:
uri- the uri to match against the template.groupNames- the list names associated with a pattern's capturing groups. The names MUST be in the same order as the pattern's capturing groups and the size MUST be equal to or less than the number of capturing groups.groupValues- the map to add the values of a pattern's capturing groups if matching is successful. A values is put into the map using the group name associated with the capturing group. The map is cleared before values are added.- Returns:
- true if the URI matches the pattern, otherwise false.
- Throws:
IllegalArgumentException- if the uri or capturingGroupValues is null.
-
hashCode
public final int hashCode() -
equals
-
toString
-