public interface PathMatcher
URI Path Matcher.
It is primary intended for use in Routing implementation.
Matched URI path is always decoded, normalized
and
with removed single ended slash (if any).
Web Server Path Pattern
While user can implement this interface to implement any specific needs the primary construction method iscreate(String)
factory method. The method accepts Web Server Path Pattern format.
Construct Example | Description |
---|---|
/foo/bar/b,a+z |
Exact canonical path match. (Including decoded characters.) |
/foo/{var} |
Named regular expression segment.
Name is var and regexp segment is ([^/]+) . Use PathMatcher.Result.param(String) method to get value
of the segment. |
/foo/{} |
Nameless regular expression segment. Regexp segment is ([^/]+) |
/foo/{var:\d+} |
Named regular expression segment with specified expression. |
/foo/{:\d+} |
Nameless regular expression segment with specified expression. |
/foo/{+var} |
A convenience shortcut for /foo/{var:.+} . |
/foo/{+} |
A convenience shortcut for /foo/{:.+} . |
/foo[/bar] |
A optional section. Translated to regexp: /foo(/bar)? |
/* or /foo* |
Wildcard character can be matched with any number of characters. |
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
The result of prefix matching aPathMatcher
to a given URI path.static interface
The result of matching aPathMatcher
to a given URI path. -
Method Summary
Modifier and TypeMethodDescriptionstatic PathMatcher
Creates new instance from provided Web Server path pattern.match
(CharSequence path) Matches this matcher against a URI path.prefixMatch
(CharSequence path) Matches this matcher against a left part (prefix) of URI path with granularity on the path segment.
-
Method Details
-
create
static PathMatcher create(String pathPattern) throws NullPointerException, IllegalPathPatternException Creates new instance from provided Web Server path pattern. See class level javadoc for the path pattern description.- Parameters:
pathPattern
- Web Server path pattern.- Returns:
- new instance.
- Throws:
NullPointerException
- if parameterpathPattern
isnull
.IllegalPathPatternException
- if provided pattern is not valid Web Server path pattern.
-
match
Matches this matcher against a URI path.- Parameters:
path
- resolved and normalized URI path to test against.- Returns:
- a
PathMatcher.Result
of the test. - Throws:
NullPointerException
- in case thatpath
parameter isnull
.
-
prefixMatch
Matches this matcher against a left part (prefix) of URI path with granularity on the path segment. It means that accepted 'prefix' cannot break path segment and 'remaining-part' MUST start with slash '/' character.- Parameters:
path
- resolved and normalized URI path to test against.- Returns:
- a
PathMatcher.Result
of the test. - Throws:
NullPointerException
- in case thatpath
parameter isnull
.
-