public class UriPattern extends Object implements Comparable<UriPattern>
This class holds a regular expression designed so that it only matches certain URI
s. The constructor of
this class accepts a simplified pattern string, and turns that into something that can be used to quickly match
against URIs. This class also implements Comparable
in such a way that stricter patterns order before looser
patterns.
Here are some examples of ordering:
http://host/path
evaluated before *://host/path
http://host/path
evaluated before http://*/path
http://a.host/path
evaluated before http://*.host/path
http://*.host/path
evaluated before http://host/path
http://host.a/path
evaluated before http://host.*/path
http://host.*/path
evaluated before http://host/path
http://host:80/path
evaluated before http://host:*/path
http://host/path
evaluated before http://host/*
http://host/path/*
evaluated before http://host/path
Modifier and Type | Class and Description |
---|---|
static class |
UriPattern.Match
This class holds the result of a
match(URI) operation. |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PRIORITY |
private GlobPattern |
host |
private GlobPattern |
path |
private String |
pattern |
private static Pattern |
PATTERN |
private int |
port |
private int |
priority |
private GlobPattern |
scheme |
Constructor and Description |
---|
UriPattern(String uri)
Creates a new instance of this class that represents the given pattern string, with a priority of 0.
|
UriPattern(String uri,
int priority)
Creates a new instance of this class that represents the given pattern string, with the given priority.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(UriPattern rhs) |
boolean |
equals(Object obj) |
int |
hashCode() |
UriPattern.Match |
match(URI uri)
Attempts to match the given
URI to this pattern. |
private static String |
resolvePatternComponent(String val) |
private static int |
resolvePortPattern(String str) |
private static String |
resolveUriComponent(String str) |
String |
toString() |
public static final int DEFAULT_PRIORITY
private static final Pattern PATTERN
private final String pattern
private final GlobPattern scheme
private final GlobPattern host
private final int port
private final GlobPattern path
private final int priority
public UriPattern(String uri)
Creates a new instance of this class that represents the given pattern string, with a priority of 0.
The input string must be on the form <scheme>://<host>[:<port>]<path>
, where
'*' can be used as a wildcard character at any position.
uri
- The pattern to parse.IllegalArgumentException
- If the pattern could not be parsed.public UriPattern(String uri, int priority)
Creates a new instance of this class that represents the given pattern string, with the given priority. The
input string must be on the form <scheme>://<host>[:<port>]<path>
, where
'*' can be used as a wildcard character at any position.
uri
- The pattern to parse.priority
- The priority of this pattern.IllegalArgumentException
- If the pattern could not be parsed.public UriPattern.Match match(URI uri)
Attempts to match the given URI
to this pattern. Note that only the scheme, host, port, and path
components of the URI are used. Any query or fragment part is simply ignored.
uri
- The URI to match.UriPattern.Match
object describing the match found, or null if not found.public int compareTo(UriPattern rhs)
compareTo
in interface Comparable<UriPattern>
private static int resolvePortPattern(String str)
Copyright © 2018. All rights reserved.