Package io.muserver.rest
Class UriPattern
- java.lang.Object
-
- io.muserver.rest.UriPattern
-
public class UriPattern extends java.lang.Object
A pattern representing a URI template, such as/fruit
or/fruit/{name}
etc. To create a new pattern, call the staticuriTemplateToRegex(String)
method.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
int
hashCode()
PathMatch
matcher(java.lang.String rawPath)
Matches the given raw path against this pattern.PathMatch
matcher(java.net.URI input)
Matches the given URI against this pattern.java.util.List<java.lang.String>
namedGroups()
java.lang.String
pattern()
java.lang.String
toString()
static UriPattern
uriTemplateToRegex(java.lang.String template)
Converts a URI Template to a regular expression, following the JAX-RS: Java™ API for RESTful Web Services specification Version 2.0 section3.7.3
-
-
-
Method Detail
-
pattern
public java.lang.String pattern()
- Returns:
- Returns the regular expression used to do the matching
-
namedGroups
public java.util.List<java.lang.String> namedGroups()
- Returns:
- Returns the read-only set of path parameters in this pattern in the order they first appeared
-
matcher
public PathMatch matcher(java.net.URI input)
Matches the given URI against this pattern.- Parameters:
input
- The URI to check against.- Returns:
- Returns a
PathMatch
wherePathMatch.prefixMatches()
istrue
if the URI matches and otherwisefalse
.
-
matcher
public PathMatch matcher(java.lang.String rawPath)
Matches the given raw path against this pattern.- Parameters:
rawPath
- The URL-encoded path to match, for example/example/some%20path
- Returns:
- Returns a
PathMatch
wherePathMatch.prefixMatches()
istrue
if the URI matches and otherwisefalse
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
uriTemplateToRegex
public static UriPattern uriTemplateToRegex(java.lang.String template) throws java.lang.IllegalArgumentException
Converts a URI Template to a regular expression, following the JAX-RS: Java™ API for RESTful Web Services specification Version 2.0 section3.7.3
- Parameters:
template
- A string as passed to aPath
annotation, such as/fruit/{name}
- Returns:
- Returns a compiled regex Pattern for the given template that will match relevant URI paths, for example
/\Qfruit\E/(?<name>[ˆ/]+?)(/.*)?
- Throws:
java.lang.IllegalArgumentException
- If the template contains invalid regular expression, or template is null, or other errors
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-