Class DocumentMatcher

java.lang.Object
org.eclipse.lemminx.settings.PathPatternMatcher
org.eclipse.lemminx.settings.DocumentMatcher
Direct Known Subclasses:
FilePathMapping, XMLColors, XMLExcludedSymbolFile, XMLFormattingProfile, XMLGenerationSettings.GenerationProfile, XMLReferences, XMLSymbolFilter

public class DocumentMatcher extends PathPatternMatcher
Extends PathPatternMatcher with document-level matching criteria. While PathPatternMatcher matches only on the file URI (glob), DocumentMatcher can also match on the document's namespace URI, root element name, DOCTYPE (public/system ID), or resolved grammar URI.

All criteria are optional and combined with AND. Within each criterion, any matching entry is sufficient (OR). The inherited PathPatternMatcher.getPattern() field from PathPatternMatcher provides file path glob matching.

This class serves as the base for all per-document scoped settings:

  • xml.colors — color expressions per document type
  • xml.symbols.filters — symbol filters per document type
  • xml.references — reference expressions per document type
  • xml.filePathSupport — file path completions per document type
  • xml.format.profiles — format overrides per document type

Existing callers that use PathPatternMatcher.matches(String) (file URI only) continue to work unchanged. The new matches(DOMDocument) method checks all criteria including the file URI pattern.

Use case: match DocBook documents by namespace

 {
   "pattern": "**/*.xml",
   "namespaceURI": ["http://docbook.org/ns/docbook*"]
 }
 

Use case: match MyBatis mapper by DOCTYPE

 {
   "publicId": ["-//mybatis.org//DTD Mapper 3.0//EN"]
 }
 

Use case: match documents by xml-model processing instruction

 {
   "grammarURI": ["http://docbook.org/xml/5.0/rng/docbook.rng*"]
 }
 
See Also:
  • Constructor Details

    • DocumentMatcher

      public DocumentMatcher()
  • Method Details

    • matches

      public boolean matches(DOMDocument document)
      Returns true if this matcher matches the given document. Checks the file URI pattern (inherited from PathPatternMatcher) and all document-level criteria. All non-null criteria must match (AND).

      Use case: a matcher with both pattern="**/docs/**/*.xml" and namespaceURI=["http://docbook.org/ns/docbook"] matches only DocBook files inside a docs/ folder.

      Parameters:
      document - the XML document to check.
      Returns:
      true if all specified criteria match.
    • getNamespaceURI

      public List<String> getNamespaceURI()
      Returns the namespace URI glob patterns.

      Use case: ["http://docbook.org/ns/docbook*"] matches DocBook 5.x documents regardless of the minor version in the namespace.

      Returns:
      the namespace URI patterns, or null if not specified.
    • setNamespaceURI

      public void setNamespaceURI(List<String> namespaceURI)
      Sets the namespace URI glob patterns.
      Parameters:
      namespaceURI - the namespace URI patterns.
    • getRootElement

      public List<String> getRootElement()
      Returns the root element name glob patterns.

      Use case: ["mapper"] matches documents whose root element is <mapper>. ["project"] matches Maven POM files (<project>) — combine with namespaceURI or pattern to disambiguate from Ant's <project>.

      Returns:
      the root element name patterns, or null if not specified.
    • setRootElement

      public void setRootElement(List<String> rootElement)
      Sets the root element name glob patterns.
      Parameters:
      rootElement - the root element name patterns.
    • getPublicId

      public List<String> getPublicId()
      Returns the DOCTYPE public ID glob patterns.

      Use case: ["-//mybatis.org//DTD Mapper*"] matches any version of the MyBatis mapper DTD.

      Returns:
      the public ID patterns, or null if not specified.
    • setPublicId

      public void setPublicId(List<String> publicId)
      Sets the DOCTYPE public ID glob patterns.
      Parameters:
      publicId - the public ID patterns.
    • getSystemId

      public List<String> getSystemId()
      Returns the DOCTYPE system ID glob patterns.

      Use case: ["http://mybatis.org/dtd/*"] matches all MyBatis DTDs.

      Returns:
      the system ID patterns, or null if not specified.
    • setSystemId

      public void setSystemId(List<String> systemId)
      Sets the DOCTYPE system ID glob patterns.
      Parameters:
      systemId - the system ID patterns.
    • getGrammarURI

      public List<String> getGrammarURI()
      Returns the grammar URI glob patterns. Checked against all grammar sources: DOCTYPE systemId, <?xml-model?> href, file associations, and XML catalog.

      Use case: ["*docbook.rng*"] matches documents using a DocBook RelaxNG schema via any binding mechanism.

      Returns:
      the grammar URI patterns, or null if not specified.
    • setGrammarURI

      public void setGrammarURI(List<String> grammarURI)
      Sets the grammar URI glob patterns.
      Parameters:
      grammarURI - the grammar URI patterns.