Skip to content

Commit 1794f1c

Browse files
committed
Polish path pattern parsing javadoc
Emphasize specific purpose for URL path matching.
1 parent b1440b6 commit 1794f1c

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import org.springframework.util.StringUtils;
3232

3333
/**
34-
* Represents a parsed path pattern. Includes a chain of path elements
34+
* Representation of a parsed path pattern. Includes a chain of path elements
3535
* for fast matching and accumulates computed state for quick comparison of
3636
* patterns.
3737
*
38-
* <p>PathPatterns match URL paths using the following rules:<br>
38+
* <p>{@code PathPattern} matches URL paths using the following rules:<br>
3939
* <ul>
4040
* <li>{@code ?} matches one character</li>
4141
* <li>{@code *} matches zero or more characters within a path segment</li>

spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternParser.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616

1717
package org.springframework.web.util.pattern;
1818

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+
*
2330
* @author Andy Clement
2431
* @since 5.0
2532
*/
@@ -28,14 +35,10 @@ public class PathPatternParser {
2835
public final static char DEFAULT_SEPARATOR = '/';
2936

3037

31-
// The expected path separator to split path elements during parsing.
3238
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+
3640
private boolean matchOptionalTrailingSlash = true;
3741

38-
// If the parser produces case-sensitive PathPattern matchers.
3942
private boolean caseSensitive = true;
4043

4144

@@ -58,17 +61,22 @@ public PathPatternParser(char separator) {
5861

5962

6063
/**
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
6370
* 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}.
6573
*/
6674
public void setMatchOptionalTrailingSlash(boolean matchOptionalTrailingSlash) {
6775
this.matchOptionalTrailingSlash = matchOptionalTrailingSlash;
6876
}
6977

7078
/**
71-
* Set whether path patterns are case-sensitive.
79+
* Whether path pattern matching should be case-sensitive.
7280
* <p>The default is {@code true}.
7381
*/
7482
public void setCaseSensitive(boolean caseSensitive) {
@@ -83,13 +91,16 @@ public void setCaseSensitive(boolean caseSensitive) {
8391
* against paths. Each invocation of this method delegates to a new instance of
8492
* the {@link InternalPathPatternParser} because that class is not thread-safe.
8593
* @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
8795
* @throws PatternParseException in case of parse errors
8896
*/
8997
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);
93104
}
94105

95106
}

spring-web/src/main/java/org/springframework/web/util/pattern/package-info.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/**
2-
* Spring's path pattern parser/matcher.
2+
* Dedicated support for matching HTTP request paths.
3+
*
4+
* <p>{@link org.springframework.web.util.pattern.PathPatternParser} is used to
5+
* parse URI path patterns into
6+
* {@link org.springframework.web.util.pattern.PathPattern}s that can then be
7+
* used for matching purposes at request time.
38
*/
49
@NonNullApi
510
package org.springframework.web.util.pattern;

0 commit comments

Comments
 (0)