Top Description Fields Constructors Methods
org.springframework.web.util.pattern

public Class PathPatternParser

extends Object
Class Inheritance
Imports
org.springframework.http.server.PathContainer, org.springframework.util.StringUtils

Parser for URI path patterns producing PathPattern instances that can then be matched to requests.

The PathPatternParser and PathPattern are specifically designed for use with HTTP URL paths in web applications where a large number of URI path patterns, continuously matched against incoming requests, motivates the need for efficient matching.

For details of the path pattern syntax see PathPattern.

Author
Andy Clement
Since
5.0

Field Summary

Modifier and TypeField and Description
private boolean
public static final PathPatternParser
defaultInstance

Shared, read-only instance of PathPatternParser.

private boolean
private PathContainer.Options

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public PathContainer.Options
getPathOptions()

Get the configured pattern parsing options.

public String

Returns:

the updated pattern
initFullPathPattern
(String
the pattern to initialize
pattern
)

Prepare the given pattern for use in matching to full URL paths.

public boolean
isCaseSensitive()

Whether case-sensitive pattern matching is enabled.

public boolean
isMatchOptionalTrailingSeparator()
Deprecated since 6.0. as of 6.0 together with setMatchOptionalTrailingSeparator(boolean).

Whether optional trailing slashing match is enabled.

public PathPattern

Returns:

a PathPattern for quickly matching paths against request paths
parse
(String
the input path pattern, e.g. /project/{name}
pathPattern
)

Process the path pattern content, a character at a time, breaking it into path elements around separator boundaries and verifying the structure at each stage.

public void
setCaseSensitive(boolean caseSensitive)

Configure whether path pattern matching should be case-sensitive.

public void
setMatchOptionalTrailingSeparator(boolean matchOptionalTrailingSeparator)
Deprecated since 6.0. transparent support for trailing slashes is deprecated as of 6.0 in favor of configuring explicit redirects through a proxy, Servlet/web filter, or a controller.

Configure whether a PathPattern produced by this parser should automatically match request paths with a trailing slash.

public void
setPathOptions(PathContainer.Options pathOptions)

Set options for parsing patterns.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

caseSensitiveback to summary
private boolean caseSensitive
defaultInstanceback to summary
public static final PathPatternParser defaultInstance

Shared, read-only instance of PathPatternParser.

Uses default settings:

  • matchOptionalTrailingSeparator = false
  • caseSensitive = true
  • pathOptions = PathContainer.Options.HTTP_PATH
matchOptionalTrailingSeparatorback to summary
private boolean matchOptionalTrailingSeparator
pathOptionsback to summary
private PathContainer.Options pathOptions

Constructor Detail

PathPatternParserback to summary
public PathPatternParser()

Method Detail

getPathOptionsback to summary
public PathContainer.Options getPathOptions()

Get the configured pattern parsing options.

Since
5.2
initFullPathPatternback to summary
public String initFullPathPattern(String pattern)

Prepare the given pattern for use in matching to full URL paths.

By default, prepend a leading slash if needed for non-empty patterns.

Parameters
pattern:String

the pattern to initialize

Returns:String

the updated pattern

Since
5.2.25
isCaseSensitiveback to summary
public boolean isCaseSensitive()

Whether case-sensitive pattern matching is enabled.

isMatchOptionalTrailingSeparatorback to summary
public boolean isMatchOptionalTrailingSeparator()

Deprecated

since 6.0.

as of 6.0 together with setMatchOptionalTrailingSeparator(boolean).

Whether optional trailing slashing match is enabled.

Annotations
@Deprecated
since:6.0
parseback to summary
public PathPattern parse(String pathPattern) throws PatternParseException

Process the path pattern content, a character at a time, breaking it into path elements around separator boundaries and verifying the structure at each stage. Produces a PathPattern object that can be used for fast matching against paths. Each invocation of this method delegates to a new instance of the InternalPathPatternParser because that class is not thread-safe.

Parameters
pathPattern:String

the input path pattern, e.g. /project/{name}

Returns:PathPattern

a PathPattern for quickly matching paths against request paths

Exceptions
PatternParseException:
in case of parse errors
setCaseSensitiveback to summary
public void setCaseSensitive(boolean caseSensitive)

Configure whether path pattern matching should be case-sensitive.

The default is true.

setMatchOptionalTrailingSeparatorback to summary
public void setMatchOptionalTrailingSeparator(boolean matchOptionalTrailingSeparator)

Deprecated

since 6.0.

transparent support for trailing slashes is deprecated as of 6.0 in favor of configuring explicit redirects through a proxy, Servlet/web filter, or a controller.

Configure whether a PathPattern produced by this parser should automatically match request paths with a trailing slash.

If set to true a PathPattern without a trailing slash will also match request paths with a trailing slash. If set to false a PathPattern will only match request paths with a trailing slash.

The default was changed in 6.0 from true to false in order to support the deprecation of the property.

Annotations
@Deprecated
since:6.0
setPathOptionsback to summary
public void setPathOptions(PathContainer.Options pathOptions)

Set options for parsing patterns. These should be the same as the options used to parse input paths.

org.springframework.http.server.PathContainer.Options#HTTP_PATH is used by default.

Since
5.2