Class ResourcePattern
A pattern looks
similar to a URI (scheme://host:port/path
) with the
following differences:
-
The scheme may be a single protocol name or a list of protocol names separated by commas, or an asterisk, which is matched by URIs with any scheme. The scheme part (scheme://) is optional in a pattern. Omitting it is equivalent to specifying an asterisk.
-
The host may be a host name or an IP address or an asterisk. Unless the value is an asterisk, filtered URIs must match the value literally.
-
The port may be a number or an asterisk. Unless the value is an asterisk, filtered URIs must match it.
-
Specifying a port (:port) is optional. If omitted, it is equivalent to specifying an asterisk.
-
If the scheme part is omitted, the host:port part may completely be left out as well, which is equivalent to specifying an asterisk for both host and port.
-
The optional path part consist of one or more path separated by commas.
Each path consists of a sequence of names and asterisks separated by slashes or a vertical bar (“|”). A name must be matched by the corresponding path element of filtered URIs, an asterisk is matched by any corresponding path element (which, however, must exist in the filtered URI). The final element in the path of a pattern may be two asterisks (**), which matches any remaining path elements in the filtered URI.
Using a vertical bar instead of a slash separates the path in a prefix part and the rest. The number of prefix segments is the value returned by the match methods.
If a path ends with a vertical bar and the URI matched with the path does not end with a slash, a slash is appended to the URI before matching. This causes both
/foo
and/foo/
to match a path/foo|
. This is usually intended. If you do want to treat/foo
as a leaf, specify/foo,/foo|
in your pattern.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Returns the segments of the path. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
host()
static boolean
Matches the given pattern against the given resource URI.static boolean
Matches the given pattern against the given resource URI, comparing at most the given number of path segments.int
Matches the given resource URI against the pattern.int
Matches the given resource URI against the pattern, comparing at most the given number of path segments.path()
pathRemainder
(URI resource) If the URI matches, returns the path without prefix as specified by the matched pattern (seesplit(String, int)
).pattern()
port()
protocol()
static String
removeSegments
(String path, int segments) Removes the given number of segments (and their trailing slashes) from the beginning of the path.static String[]
Splits the given path in a prefix with the given number of segments and the rest.If the URI matches, returns the path split according to the matched pattern (seesplit(String, int)
).toString()
-
Constructor Details
-
ResourcePattern
Creates a new resource pattern.- Parameters:
pattern
- the pattern to be used for matching- Throws:
ParseException
- if an invalid pattern is specified
-
-
Method Details
-
pattern
- Returns:
- the pattern (string) that was used to create this resource pattern.
-
protocol
- Returns:
- the protocol value specified in the pattern or null
-
host
- Returns:
- the host value specified in the pattern or null
-
port
- Returns:
- the port value specified in the pattern or null
-
path
- Returns:
- the path value specified in the pattern or null
-
matches
Matches the given resource URI against the pattern.- Parameters:
resource
- the URI specifying the resource to match- Returns:
- -1 if the resource does not match, else the number of prefix segments (which may be 0)
-
matches
Matches the given resource URI against the pattern, comparing at most the given number of path segments.- Parameters:
resource
- the URI specifying the resource to matchpathSegs
- the maximum number of path segments to compare- Returns:
- -1 if the resource does not match, else the number of prefix segments (which may be 0)
-
matches
Matches the given pattern against the given resource URI.- Parameters:
pattern
- the pattern to matchresource
- the URI specifying the resource to match- Returns:
- true if the resource URI matches
- Throws:
ParseException
- if an invalid pattern is specified
-
matches
Matches the given pattern against the given resource URI, comparing at most the given number of path segments.- Parameters:
pattern
- the pattern to matchresource
- the URI specifying the resource to matchpathSegments
- the maximum number of path segments to compare- Returns:
- true if the resource URI matches
- Throws:
ParseException
- if an invalid pattern is specified
-
removeSegments
Removes the given number of segments (and their trailing slashes) from the beginning of the path.Segments may be empty. This implies that invoking this method with a path that starts with a slash, the first removed segment is the empty segment preceding the slash and the starting slash. Put differently, invoking this method with an absolute path and 1 makes the path relative.
- Parameters:
path
- the pathsegments
- the number of segments to remove- Returns:
- the result
-
split
Splits the given path in a prefix with the given number of segments and the rest.Like {
removeSegments(String, int)
but additionally returning the removed segments.- Parameters:
path
- the pathsegments
- the number of segments in the prefi- Returns:
- the prefix and the rest
-
splitPath
If the URI matches, returns the path split according to the matched pattern (seesplit(String, int)
).- Parameters:
resource
- the resource- Returns:
- the result.
-
pathRemainder
If the URI matches, returns the path without prefix as specified by the matched pattern (seesplit(String, int)
).- Parameters:
resource
- the resource- Returns:
- the result.
-
toString
-
hashCode
-
equals
-