public class PathPattern extends java.lang.Object implements java.lang.Comparable<PathPattern>
PathPatterns match URL paths using the following rules:
?
matches one character*
matches zero or more characters within a path segment**
matches zero or more path segments until the end of the path{spring}
matches a path segment and captures it as a variable named "spring"{spring:[a-z]+}
matches the regexp [a-z]+
as a path variable named "spring"{*spring}
matches zero or more path segments until the end of the path
and captures it as a variable named "spring"/pages/t?st.html
— matches /pages/test.html
but also
/pages/tast.html
but not /pages/toast.html
/resources/*.png
— matches all .png
files in the
resources
directory/resources/**
— matches all files
underneath the /resources/
path, including /resources/image.png
and /resources/css/spring.css
/resources/{*path}
— matches all files
underneath the /resources/
path and captures their relative path in
a variable named "path"; /resources/image.png
will match with
"spring" -> "/image.png", and /resources/css/spring.css
will match
with "spring" -> "/css/spring.css"/resources/{filename:\\w+}.dat
will match /resources/spring.dat
and assign the value "spring"
to the filename
variableModifier and Type | Class and Description |
---|---|
(package private) class |
PathPattern.MatchingContext
Encapsulates context when attempting a match.
|
Modifier and Type | Field and Description |
---|---|
private int |
capturedVariableCount
How many variables are captured in this pattern
|
private boolean |
caseSensitive
Will this match candidates in a case sensitive way? (case sensitivity at parse time)
|
(package private) boolean |
endsWithSeparatorWildcard
Does the pattern end with '<separator>*'
|
private PathElement |
head
First path element in the parsed chain of path elements for this pattern
|
private boolean |
isCatchAll
Does the pattern end with {*...}
|
private static java.util.Map<java.lang.String,java.lang.String> |
NO_VARIABLES_MAP |
(package private) int |
normalizedLength
The normalized length is trying to measure the 'active' part of the pattern.
|
private java.lang.String |
patternString
The text of the parsed pattern
|
private int |
score
Score is used to quickly compare patterns.
|
private char |
separator
The separator used when parsing the pattern
|
Constructor and Description |
---|
PathPattern(java.lang.String patternText,
PathElement head,
char separator,
boolean caseSensitive) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
combine(java.lang.String pattern2string)
Combine this pattern with another.
|
int |
compareTo(PathPattern p)
Compare this pattern with a supplied pattern.
|
private java.lang.String |
concat(java.lang.String path1,
java.lang.String path2)
Join two paths together including a separator if necessary.
|
boolean |
equals(java.lang.Object o) |
java.lang.String |
extractPathWithinPattern(java.lang.String path)
Given a full path, determine the pattern-mapped part.
|
int |
getCapturedVariableCount() |
PathElement |
getHeadSection() |
int |
getNormalizedLength()
The normalized length is trying to measure the 'active' part of the pattern.
|
java.lang.String |
getPatternString() |
int |
getScore() |
char |
getSeparator() |
int |
hashCode() |
boolean |
isCatchAll() |
java.util.Map<java.lang.String,java.lang.String> |
matchAndExtract(java.lang.String path) |
boolean |
matches(java.lang.String path) |
boolean |
matchStart(java.lang.String path) |
java.lang.String |
toChainString() |
java.lang.String |
toString() |
private static final java.util.Map<java.lang.String,java.lang.String> NO_VARIABLES_MAP
private PathElement head
private java.lang.String patternString
private char separator
private boolean caseSensitive
private int capturedVariableCount
int normalizedLength
boolean endsWithSeparatorWildcard
private int score
private boolean isCatchAll
public PathPattern(java.lang.String patternText, PathElement head, char separator, boolean caseSensitive)
public boolean matches(java.lang.String path)
path
- the candidate path to attempt to match against this patternpublic boolean matchStart(java.lang.String path)
path
- the path to check against the patternpublic java.util.Map<java.lang.String,java.lang.String> matchAndExtract(java.lang.String path)
path
- a path to match against this patternpublic java.lang.String getPatternString()
public PathElement getHeadSection()
public java.lang.String extractPathWithinPattern(java.lang.String path)
For example:
/docs/cvs/commit.html
' and '/docs/cvs/commit.html
-> ''/docs/*
' and '/docs/cvs/commit
-> 'cvs/commit
'/docs/cvs/*.html
' and '/docs/cvs/commit.html
-> 'commit.html
'/docs/**
' and '/docs/cvs/commit
-> 'cvs/commit
'Note: Assumes that matches(java.lang.String)
returns true
for 'pattern
' and 'path
', but
does not enforce this. As per the contract on PathMatcher
, this
method will trim leading/trailing separators. It will also remove duplicate separators in
the returned path.
path
- a path that matches this patternpublic int compareTo(PathPattern p)
compareTo
in interface java.lang.Comparable<PathPattern>
public int getScore()
public boolean isCatchAll()
public int getNormalizedLength()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toChainString()
public char getSeparator()
public int getCapturedVariableCount()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String combine(java.lang.String pattern2string)
private java.lang.String concat(java.lang.String path1, java.lang.String path2)
path1
- First pathpath2
- Second path