Class GlobMatcher

java.lang.Object
org.eclipse.lemminx.settings.GlobMatcher

public final class GlobMatcher extends Object
Simple textual glob matching utility for non-file-path strings such as namespace URIs, DOCTYPE public/system IDs, and grammar URIs.

Java NIO PathMatcher only works for file-system paths. This class provides lightweight glob matching for arbitrary text strings using two wildcards:

  • * — matches any sequence of characters (including empty)
  • ? — matches exactly one character

Use case: match DocBook namespace with trailing wildcard

 GlobMatcher.match("http://docbook.org/ns/docbook*", "http://docbook.org/ns/docbook");     // true
 GlobMatcher.match("http://docbook.org/ns/docbook*", "http://docbook.org/ns/docbook/5.1"); // true
 

Use case: match any MyBatis DTD version

 GlobMatcher.match("-//mybatis.org//DTD Mapper*", "-//mybatis.org//DTD Mapper 3.0//EN"); // true
 
See Also:
  • Method Details

    • match

      public static boolean match(String pattern, String text)
      Matches a glob pattern against a text string.

      Supports path-glob **/ sequences: when ** appears as a complete path component (at the start of the pattern or after /), it matches zero or more path segments. Any non-empty prefix consumed by ** must end at a / boundary.

      Use case:

      • **/my-schema.dtd matches my-schema.dtd and path/to/my-schema.dtd
      • **/my-schema.dtd does not match other-my-schema.dtd
      Parameters:
      pattern - the glob pattern (supports *, ?, and **/).
      text - the text to match.
      Returns:
      true if the text matches the pattern.
    • matchPath

      public static boolean matchPath(String pattern, String text)
      Path-aware glob matching. Behaves like match(String, String) but also tries matching against the filename portion of the text (after the last /) when the pattern contains no /.

      Use this for values that are typically paths or URIs with path structure — such as DOCTYPE system IDs, grammar URIs, and xml-model hrefs — where a bare filename pattern like my-schema.dtd should match path/to/my-schema.dtd.

      Do not use this for namespace URIs or public IDs, where a pattern like docbook must not accidentally match http://example.com/ns/docbook.

      Parameters:
      pattern - the glob pattern.
      text - the text to match.
      Returns:
      true if the text matches the pattern.
    • matchAny

      public static boolean matchAny(List<String> patterns, String value)
      Checks if any glob pattern in the list matches the given value using full-text matching (match(String, String)).

      Use case: check if a document's namespace URI or public ID matches any of the configured patterns (OR semantics).

      Parameters:
      patterns - the list of glob patterns.
      value - the value to match, or null.
      Returns:
      true if any pattern matches the value; false if the value is null or no pattern matches.
    • matchPathAny

      public static boolean matchPathAny(List<String> patterns, String value)
      Checks if any glob pattern in the list matches the given value using path-aware matching (matchPath(String, String)).

      Use case: check if a document's system ID or grammar URI matches any of the configured patterns (OR semantics), allowing bare filename patterns to match path-like values.

      Parameters:
      patterns - the list of glob patterns.
      value - the value to match, or null.
      Returns:
      true if any pattern matches the value; false if the value is null or no pattern matches.