public class NamedVariablePatternMatcher extends Object implements PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>
{VARIABLE_NAME}
syntax and will match any characters that aren't '/'. Internally, the pattern is
converted into a regular expression where the named wildcard will be translated into ([^/]+)
so that
at least one character must match in order for the wildcard to be matched successfully. Matched values will be
available in the variable map, indexed by the name they were given in the pattern.
For example, the following patterns will be processed as so:
Pattern | Example | Variable Map Contents |
---|---|---|
/animals/{animal} |
/animals/dog |
{animal -> dog} |
/animals/{animal}/tag/No{id} |
/animals/dog/tag/No23 |
{animal -> dog, id -> 23} |
/{language} |
/en |
{language -> en} |
Excaping hasn't been implemented since the intended use of these patterns will be in matching URLs.
Modifier and Type | Class and Description |
---|---|
static class |
NamedVariablePatternMatcher.CompiledPattern
Stores the compiled pattern and the variable names matches will correspond to.
|
Constructor and Description |
---|
NamedVariablePatternMatcher() |
Modifier and Type | Method and Description |
---|---|
NamedVariablePatternMatcher.CompiledPattern |
compilePattern(String data)
Compiles the pattern.
|
boolean |
isLiteral(String pattern)
Determines if the pattern is a simple literal string or contains wildcards that will need to be processed
|
boolean |
match(Map<String,String> map,
String data,
NamedVariablePatternMatcher.CompiledPattern expr)
Tries to process the data against the compiled expression.
|
public boolean isLiteral(String pattern)
PatternMatcher
isLiteral
in interface PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>
pattern
- The string patternpublic NamedVariablePatternMatcher.CompiledPattern compilePattern(String data)
compilePattern
in interface PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>
data
- The pattern, must not be null or emptypublic boolean match(Map<String,String> map, String data, NamedVariablePatternMatcher.CompiledPattern expr)
match
in interface PatternMatcher<NamedVariablePatternMatcher.CompiledPattern>
map
- The map of variablesdata
- The data to matchexpr
- The compiled patternCopyright © 2000–2020 Apache Software Foundation. All rights reserved.