Class RegexPathSpec

java.lang.Object
org.eclipse.jetty.http.pathmap.AbstractPathSpec
org.eclipse.jetty.http.pathmap.RegexPathSpec
All Implemented Interfaces:
Comparable<PathSpec>, PathSpec

public class RegexPathSpec extends AbstractPathSpec

RegexPathSpec is a PathSpec implementation for a PathMappings instance.

Supports the standard Java regex found in Pattern.

Supports PathSpecGroup for PathSpecGroup.EXACT, PathSpecGroup.PREFIX_GLOB, PathSpecGroup.MIDDLE_GLOB, and PathSpecGroup.SUFFIX_GLOB. This is done by evaluating the signature or the provided regex pattern for what is a literal vs a glob (of any kind).

The use of regex capture groups, regex character classes, regex quantifiers, and regex special contructs will be identified as a glob (for signature determination), all other characters are identified as literal. The regex ^ beginning of line, and regex $ end of line are ignored.

Support for MatchedPath and PathMatch vs PathInfo

There's a few steps in evaluating the matched input path for determining where the split in the input path should occur for MatchedPath.getPathMatch() and MatchedPath.getPathInfo().

  1. If there are no regex capturing groups, the entire path is returned in MatchedPath.getPathMatch(), and a null returned for MatchedPath.getPathInfo()
  2. If both the named regex capturing groups name and info are present, then the name group is returned in MatchedPath.getPathMatch() and the info group is returned in MatchedPath.getPathInfo()
  3. If there is only 1 regex capturing group If the split on pathMatch ends with / AND the pathInfo doesn't start with / then the slash is moved from pathMatch to pathInfo.
  4. All other RegexPathSpec signatures will return the entire path in MatchedPath.getPathMatch(), and a null returned for MatchedPath.getPathInfo()
  • Constructor Details

    • RegexPathSpec

      public RegexPathSpec(String regex)
  • Method Details

    • getMatcher

      protected Matcher getMatcher(String path)
    • getSpecLength

      public int getSpecLength()
      Description copied from interface: PathSpec
      The length of the spec.
      Returns:
      the length of the spec.
    • getGroup

      public PathSpecGroup getGroup()
      Description copied from interface: PathSpec
      The spec group.
      Returns:
      the spec group.
    • getPathDepth

      public int getPathDepth()
      Description copied from interface: PathSpec
      Get the number of path elements that this path spec declares.

      This is used to determine longest match logic.

      Returns:
      the depth of the path segments that this spec declares
    • getPathInfo

      public String getPathInfo(String path)
      Description copied from interface: PathSpec
      Return the portion of the path that is after the path spec.
      Parameters:
      path - the path to match against
      Returns:
      the path info portion of the string
    • getPathMatch

      public String getPathMatch(String path)
      Description copied from interface: PathSpec
      Return the portion of the path that matches a path spec.
      Parameters:
      path - the path to match against
      Returns:
      the match, or null if no match at all
    • getDeclaration

      public String getDeclaration()
      Description copied from interface: PathSpec
      The as-provided path spec.
      Returns:
      the as-provided path spec
    • getPrefix

      public String getPrefix()
      Description copied from interface: PathSpec
      A simple prefix match for the pathspec or null
      Returns:
      A simple prefix match for the pathspec or null
    • getSuffix

      public String getSuffix()
      Description copied from interface: PathSpec
      A simple suffix match for the pathspec or null
      Returns:
      A simple suffix match for the pathspec or null
    • getPattern

      public Pattern getPattern()
    • matches

      public boolean matches(String path)
      Description copied from interface: PathSpec
      Test to see if the provided path matches this path spec. This can be more efficient that PathSpec.matched(String) if the details of the match are not required.
      Parameters:
      path - the path to test
      Returns:
      true if the path matches this path spec, false otherwise
      See Also:
    • matched

      public MatchedPath matched(String path)
      Description copied from interface: PathSpec
      Get the complete matched details of the provided path.
      Parameters:
      path - the path to test
      Returns:
      the matched details, if a match was possible, or null if not able to be matched.
      See Also: