Package org.springframework.web.util.pattern

# Class PathPatternParser

java.lang.Object
org.springframework.web.util.pattern.PathPatternParser

public class PathPatternParser extends Object
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`.

Since:
  5.0
Author:
  Andy Clement

## Field Summary

Fields
Modifier and Type
Field
Description
`static final PathPatternParser`
`defaultInstance`
Shared, read-only instance of `PathPatternParser`.

## Constructor Summary

Constructors
Constructor
Description
`PathPatternParser()`

## Method Summary

Modifier and Type
Method
Description
`PathContainer.Options`
`getPathOptions()`
Get the `configured` pattern parsing options.
`String`
`initFullPathPattern(String pattern)`
Prepare the given pattern for use in matching to full URL paths.
`boolean`
`isCaseSensitive()`
Whether case-sensitive pattern matching is enabled.
`boolean`
`isMatchOptionalTrailingSeparator()`
Deprecated.
as of 6.0 together with `setMatchOptionalTrailingSeparator(boolean)`.
`PathPattern`
`parse(String 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.
`void`
`setCaseSensitive(boolean caseSensitive)`
Configure whether path pattern matching should be case-sensitive.
`void`
`setMatchOptionalTrailingSeparator(boolean matchOptionalTrailingSeparator)`
Deprecated.
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.
`void`
`setPathOptions(PathContainer.Options pathOptions)`
Set options for parsing patterns.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### defaultInstance

public static final PathPatternParser defaultInstance
Shared, read-only instance of `PathPatternParser`.

Uses default settings:

- `matchOptionalTrailingSeparator = false`
- `caseSensitive = true`
- `pathOptions = PathContainer.Options.HTTP_PATH`

## Constructor Details

### PathPatternParser

public PathPatternParser()

## Method Details

### setMatchOptionalTrailingSeparator

@Deprecated(since="6.0") public void setMatchOptionalTrailingSeparator(boolean matchOptionalTrailingSeparator)
Deprecated.
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.

### isMatchOptionalTrailingSeparator

@Deprecated(since="6.0") public boolean isMatchOptionalTrailingSeparator()
Deprecated.
as of 6.0 together with `setMatchOptionalTrailingSeparator(boolean)`.
Whether optional trailing slashing match is enabled.

### setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)
Configure whether path pattern matching should be case-sensitive.

The default is `true`.

### isCaseSensitive

public boolean isCaseSensitive()
Whether case-sensitive pattern matching is enabled.

### setPathOptions

public void setPathOptions(PathContainer.Options pathOptions)
Set options for parsing patterns. These should be the same as the options used to parse input paths.

`PathContainer.Options.HTTP_PATH` is used by default.

Since:
  5.2

### getPathOptions

public PathContainer.Options getPathOptions()
Get the `configured` pattern parsing options.

Since:
  5.2

### initFullPathPattern

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` - the pattern to initialize
Returns:
  the updated pattern
Since:
  5.2.25

### parse

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` - the input path pattern, for example, /project/{name}
Returns:
  a PathPattern for quickly matching paths against request paths
Throws:
  `PatternParseException` - in case of parse errors