16
16
17
17
package org .springframework .web .util .pattern ;
18
18
19
- /**
20
- * Parser for URI template patterns. It breaks the path pattern into a number
21
- * of {@link PathElement}s in a linked list.
22
- *
19
+ /**
20
+ * Parser for URI path patterns producing {@link PathPattern} instances that can
21
+ * then be matched to requests.
22
+ *
23
+ * <p>The {@link PathPatternParser} and {@link PathPattern} are specifically
24
+ * designed for use with HTTP URL paths in web applications where a large number
25
+ * of URI path patterns continuously matched against incoming requests motivates
26
+ * the need for pre-parsing and fast matching.
27
+ *
28
+ * <p>For details of the path pattern syntax see {@link PathPattern}.
29
+ *
23
30
* @author Andy Clement
24
31
* @since 5.0
25
32
*/
@@ -28,14 +35,10 @@ public class PathPatternParser {
28
35
public final static char DEFAULT_SEPARATOR = '/' ;
29
36
30
37
31
- // The expected path separator to split path elements during parsing.
32
38
private char separator = DEFAULT_SEPARATOR ;
33
-
34
- // Whether the PathPatterns produced by the parser will allow patterns that don't
35
- // have a trailing slash to match paths that may or may not have a trailing slash.
39
+
36
40
private boolean matchOptionalTrailingSlash = true ;
37
41
38
- // If the parser produces case-sensitive PathPattern matchers.
39
42
private boolean caseSensitive = true ;
40
43
41
44
@@ -58,17 +61,22 @@ public PathPatternParser(char separator) {
58
61
59
62
60
63
/**
61
- * Control behavior of the path patterns produced by this parser: if {@code true}
62
- * then PathPatterns without a trailing slash will match paths with or without
64
+ * Whether a {@link PathPattern} produced by this parser should should
65
+ * automatically match request paths with a trailing slash.
66
+ *
67
+ * <p>If set to {@code true} a {@code PathPattern} without a trailing slash
68
+ * will also match request paths with a trailing slash. If set to
69
+ * {@code false} a {@code PathPattern} will only match request paths with
63
70
* a trailing slash.
64
- * <p>The default is {@code true} but here this flag can be set to {@code false}.
71
+ *
72
+ * <p>The default is {@code true}.
65
73
*/
66
74
public void setMatchOptionalTrailingSlash (boolean matchOptionalTrailingSlash ) {
67
75
this .matchOptionalTrailingSlash = matchOptionalTrailingSlash ;
68
76
}
69
77
70
78
/**
71
- * Set whether path patterns are case-sensitive.
79
+ * Whether path pattern matching should be case-sensitive.
72
80
* <p>The default is {@code true}.
73
81
*/
74
82
public void setCaseSensitive (boolean caseSensitive ) {
@@ -83,13 +91,16 @@ public void setCaseSensitive(boolean caseSensitive) {
83
91
* against paths. Each invocation of this method delegates to a new instance of
84
92
* the {@link InternalPathPatternParser} because that class is not thread-safe.
85
93
* @param pathPattern the input path pattern, e.g. /foo/{bar}
86
- * @return a PathPattern for quickly matching paths against the specified path pattern
94
+ * @return a PathPattern for quickly matching paths against request paths
87
95
* @throws PatternParseException in case of parse errors
88
96
*/
89
97
public PathPattern parse (String pathPattern ) throws PatternParseException {
90
- InternalPathPatternParser parserDelegate =
91
- new InternalPathPatternParser (this .separator , this .caseSensitive , this .matchOptionalTrailingSlash );
92
- return parserDelegate .parse (pathPattern );
98
+ return createDelegate ().parse (pathPattern );
99
+ }
100
+
101
+ private InternalPathPatternParser createDelegate () {
102
+ return new InternalPathPatternParser (
103
+ this .separator , this .caseSensitive , this .matchOptionalTrailingSlash );
93
104
}
94
105
95
106
}
0 commit comments