PathPattern matches 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]+ against a path segment
and captures it 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"Note
In contrast to
org., ** is supported only
at the end of a pattern. For example /pages/{**} is valid but
/pages/{**}/details is not. The same applies also to the capturing
variant {*spring}. The aim is to eliminate ambiguity when
comparing patterns for specificity.
/pages/t?st.html — matches /pages/test.html as well as
/pages/tXst.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/, as well as /resources, and captures
their relative path in a variable named "path"; /resources/image.png
will match with "path" → "/image.png", and /resources/css/spring.css
will match with "path" → "/css/spring.css"/resources/{filename:\\w+}.dat will match /resources/spring.dat
and assign the value "spring" to the filename variablePathContainer
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | PathPattern.
Encapsulates context when attempting a match. |
| public static class | PathPattern.
Holder for URI variables and path parameters (matrix variables) extracted based on the pattern for a given matched path. |
| public static class | PathPattern.
Holder for the result of a match on the start of a pattern. |
| Modifier and Type | Field and Description |
|---|---|
| private int | capturedVariableCount
How many variables are captured in this pattern. |
| private final boolean | caseSensitive
Will this match candidates in a case-sensitive way? |
| private boolean | catchAll
Does the pattern end with {*...}. |
| private static final PathContainer | |
| private boolean | endsWithSeparatorWildcard
Does the pattern end with '<separator>'. |
| private final PathElement | head
First path element in the parsed chain of path elements for this pattern. |
| private final boolean | matchOptionalTrailingSeparator
If this pattern has no trailing slash, allow candidates to include one and still match successfully. |
| private int | normalizedLength
The normalized length is trying to measure the 'active' part of the pattern. |
| private final PathPatternParser | parser
The parser used to construct this pattern. |
| private final PathContainer. | pathOptions
The options to use to parse a pattern. |
| private final String | patternString
The text of the parsed pattern. |
| private int | score
Score is used to quickly compare patterns. |
| public static final Comparator | SPECIFICITY_COMPARATOR
Comparator that sorts patterns by specificity as follows:
|
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public PathPattern | |
| public int | compareTo(PathPattern
the object to be compared. otherPattern)Implements java. Compare this pattern with a supplied pattern: return -1,0,+1 if this pattern is more specific, the same or less specific than the supplied pattern. |
| pack-priv String | Returns: the string form of the patternReturn the string form of the pattern built from walking the path element chain. |
| private String | |
| public boolean | equals(Object
the reference object with which to compare. other)Overrides java. Indicates whether some other object is "equal to" this one. |
| public PathContainer | Returns: the subset of the path that is matched by pattern or "" if none of it is matched by pattern elementsa path that matches this pattern path)Determine the pattern-mapped part for the given path. |
| pack-priv int | |
| pack-priv PathElement | |
| pack-priv int | |
| public String | |
| pack-priv int | |
| pack-priv char | |
| public int | |
| private boolean | Returns: true has more than zero elementsa path container container)Return if the container is not null and has more than zero elements. |
| public boolean | hasPatternSyntax()
Whether the pattern string contains pattern syntax that would require
use of |
| pack-priv boolean | |
| public PathPattern. | Returns: info object with the extracted variables, ornull for no matchthe candidate path to attempt to match against pathContainer)Match this pattern to the given URI path and return extracted URI template variables as well as path parameters (matrix variables). |
| public boolean | Returns: true if the path matches this patternthe candidate path to attempt to match against pathContainer)Whether this pattern matches the given path. |
| public PathPattern. | Returns: info object with the match result ornull for no matchthe candidate path to attempt to match against pathContainer)Match the beginning of the given path and return the remaining portion not covered by this pattern. |
| private boolean | |
| private static int | |
| pack-priv String | |
| public String |
| capturedVariableCount | back to summary |
|---|---|
| private int capturedVariableCount How many variables are captured in this pattern. | |
| caseSensitive | back to summary |
|---|---|
| private final boolean caseSensitive Will this match candidates in a case-sensitive way? (case sensitivity at parse time). | |
| catchAll | back to summary |
|---|---|
| private boolean catchAll Does the pattern end with {*...}. | |
| EMPTY_PATH | back to summary |
|---|---|
| private static final PathContainer EMPTY_PATH | |
| endsWithSeparatorWildcard | back to summary |
|---|---|
| private boolean endsWithSeparatorWildcard Does the pattern end with '<separator>'. | |
| head | back to summary |
|---|---|
| private final PathElement head First path element in the parsed chain of path elements for this pattern. | |
| matchOptionalTrailingSeparator | back to summary |
|---|---|
| private final boolean matchOptionalTrailingSeparator If this pattern has no trailing slash, allow candidates to include one and still match successfully. | |
| normalizedLength | back to summary |
|---|---|
| private int normalizedLength The normalized length is trying to measure the 'active' part of the pattern. It is computed by assuming all captured variables have a normalized length of 1. Effectively this means changing your variable name lengths isn't going to change the length of the active part of the pattern. Useful when comparing two patterns. | |
| parser | back to summary |
|---|---|
| private final PathPatternParser parser The parser used to construct this pattern. | |
| pathOptions | back to summary |
|---|---|
| private final PathContainer. The options to use to parse a pattern. | |
| patternString | back to summary |
|---|---|
| private final String patternString The text of the parsed pattern. | |
| score | back to summary |
|---|---|
| private int score Score is used to quickly compare patterns. Different pattern components are given different weights. A 'lower score' is more specific. Current weights:
| |
| SPECIFICITY_COMPARATOR | back to summary |
|---|---|
| public static final Comparator<PathPattern> SPECIFICITY_COMPARATOR Comparator that sorts patterns by specificity as follows:
| |
| PathPattern | back to summary |
|---|---|
pack-priv PathPattern(String patternText, PathPatternParser parser, PathElement head)
| |
| combine | back to summary |
|---|---|
| public PathPattern combine(PathPattern pattern2string) Combine this pattern with another. | |
| compareTo | back to summary |
|---|---|
| public int compareTo(PathPattern otherPattern) Implements java. Compare this pattern with a supplied pattern: return -1,0,+1 if this pattern is more specific, the same or less specific than the supplied pattern. The aim is to sort more specific patterns first.
| |
| computePatternString | back to summary |
|---|---|
| pack-priv String computePatternString() Return the string form of the pattern built from walking the path element chain.
| |
| concat | back to summary |
|---|---|
| private String concat(String path1, String path2) Join two paths together including a separator if necessary. Extraneous separators are removed (if the first path ends with one and the second path starts with one). | |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| extractPathWithinPattern | back to summary |
|---|---|
| public PathContainer extractPathWithinPattern(PathContainer path) Determine the pattern-mapped part for the given path. For example:
Notes:
| |
| getCapturedVariableCount | back to summary |
|---|---|
| pack-priv int getCapturedVariableCount() | |
| getHeadSection | back to summary |
|---|---|
pack-priv PathElement getHeadSection()
| |
| getNormalizedLength | back to summary |
|---|---|
| pack-priv int getNormalizedLength() The normalized length is trying to measure the 'active' part of the pattern. It is computed by assuming all capture variables have a normalized length of 1. Effectively this means changing your variable name lengths isn't going to change the length of the active part of the pattern. Useful when comparing two patterns. | |
| getPatternString | back to summary |
|---|---|
| public String getPatternString() Return the original String that was parsed to create this PathPattern. | |
| getScore | back to summary |
|---|---|
| pack-priv int getScore() | |
| getSeparator | back to summary |
|---|---|
| pack-priv char getSeparator() | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| hasLength | back to summary |
|---|---|
| private boolean hasLength(PathContainer container) Return if the container is not null and has more than zero elements.
| |
| hasPatternSyntax | back to summary |
|---|---|
| public boolean hasPatternSyntax() Whether the pattern string contains pattern syntax that would require
use of
| |
| isCatchAll | back to summary |
|---|---|
| pack-priv boolean isCatchAll() | |
| matchAndExtract | back to summary |
|---|---|
| public PathPattern. Match this pattern to the given URI path and return extracted URI template variables as well as path parameters (matrix variables).
| |
| matches | back to summary |
|---|---|
| public boolean matches(PathContainer pathContainer) Whether this pattern matches the given path.
| |
| matchStartOfPath | back to summary |
|---|---|
| public PathPattern. Match the beginning of the given path and return the remaining portion not covered by this pattern. This is useful for matching nested routes where the path is matched incrementally at each level.
| |
| pathContainerIsJustSeparator | back to summary |
|---|---|
| private boolean pathContainerIsJustSeparator(PathContainer pathContainer) | |
| scoreByNormalizedLength | back to summary |
|---|---|
| private static int scoreByNormalizedLength(PathPattern pattern) | |
| toChainString | back to summary |
|---|---|
| pack-priv String toChainString() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final PathContainer | |
| pack-priv boolean | |
| private Map | |
| private Map | |
| pack-priv boolean | |
| pack-priv final List | |
| pack-priv final int | |
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public PathPattern. | |
| public boolean | |
| pack-priv boolean | Returns: true if element is a separatorpossible index of a separator pathIndex)Return if element at specified index is a separator. |
| pack-priv String | Returns: the decoded valuepath element index pathIndex)Return the decoded value of the specified element. |
| public void | |
| public void |
| candidate | back to summary |
|---|---|
| pack-priv final PathContainer candidate | |
| determineRemainingPath | back to summary |
|---|---|
| pack-priv boolean determineRemainingPath | |
| extractedMatrixVariables | back to summary |
|---|---|
| private Map<String, MultiValueMap<String, String>> extractedMatrixVariables
| |
| extractedUriVariables | back to summary |
|---|---|
| private Map<String, String> extractedUriVariables
| |
| extractingVariables | back to summary |
|---|---|
| pack-priv boolean extractingVariables | |
| pathElements | back to summary |
|---|---|
| pack-priv final List<PathContainer. | |
| pathLength | back to summary |
|---|---|
| pack-priv final int pathLength | |
| remainingPathIndex | back to summary |
|---|---|
| pack-priv int remainingPathIndex | |
| MatchingContext | back to summary |
|---|---|
| public MatchingContext(PathContainer pathContainer, boolean extractVariables) | |
| getPathMatchResult | back to summary |
|---|---|
| public PathPattern. | |
| isMatchOptionalTrailingSeparator | back to summary |
|---|---|
| public boolean isMatchOptionalTrailingSeparator() | |
| isSeparator | back to summary |
|---|---|
| pack-priv boolean isSeparator(int pathIndex) Return if element at specified index is a separator.
| |
| pathElementValue | back to summary |
|---|---|
| pack-priv String pathElementValue(int pathIndex) Return the decoded value of the specified element.
| |
| set | back to summary |
|---|---|
| public void set(String key, String value, MultiValueMap<String, String> parameters) | |
| setMatchAllowExtraPath | back to summary |
|---|---|
| public void setMatchAllowExtraPath() | |
| Modifier and Type | Field and Description |
|---|---|
| private static final PathPattern. | |
| private final Map | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Map | getMatrixVariables()
Return maps of matrix variables per path segment, keyed off by URI variable name. |
| public Map | |
| public String |
| EMPTY | back to summary |
|---|---|
| private static final PathPattern. | |
| matrixVariables | back to summary |
|---|---|
| private final Map<String, MultiValueMap<String, String>> matrixVariables | |
| uriVariables | back to summary |
|---|---|
| private final Map<String, String> uriVariables | |
| PathMatchInfo | back to summary |
|---|---|
| pack-priv PathMatchInfo(Map<String, String> uriVars, Map<String, MultiValueMap<String, String>> matrixVars) | |
| getMatrixVariables | back to summary |
|---|---|
| public Map Return maps of matrix variables per path segment, keyed off by URI variable name. | |
| getUriVariables | back to summary |
|---|---|
| public Map Return the extracted URI variables. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| private final PathContainer | |
| private final PathPattern. | |
| private final PathContainer |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining, PathPattern.
|
| Modifier and Type | Method and Description |
|---|---|
| public Map | |
| public PathContainer | |
| public PathContainer | |
| public Map | getUriVariables()
Return variables that were bound in the part of the path that was successfully matched or an empty map. |
| pathMatched | back to summary |
|---|---|
| private final PathContainer pathMatched | |
| pathMatchInfo | back to summary |
|---|---|
| private final PathPattern. | |
| pathRemaining | back to summary |
|---|---|
| private final PathContainer pathRemaining | |
| PathRemainingMatchInfo | back to summary |
|---|---|
| pack-priv PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining) | |
| PathRemainingMatchInfo | back to summary |
|---|---|
| pack-priv PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining, PathPattern. | |
| getMatrixVariables | back to summary |
|---|---|
| public Map Return the path parameters for each bound variable. | |
| getPathMatched | back to summary |
|---|---|
| public PathContainer getPathMatched() Return the part of a path that was matched by a pattern.
| |
| getPathRemaining | back to summary |
|---|---|
| public PathContainer getPathRemaining() Return the part of a path that was not matched by a pattern. | |
| getUriVariables | back to summary |
|---|---|
| public Map Return variables that were bound in the part of the path that was successfully matched or an empty map. | |