Class DocumentMatcher
- Direct Known Subclasses:
FilePathMapping,XMLColors,XMLExcludedSymbolFile,XMLFormattingProfile,XMLGenerationSettings.GenerationProfile,XMLReferences,XMLSymbolFilter
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 typexml.symbols.filters— symbol filters per document typexml.references— reference expressions per document typexml.filePathSupport— file path completions per document typexml.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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the grammar URI glob patterns.Returns the namespace URI glob patterns.Returns the DOCTYPE public ID glob patterns.Returns the root element name glob patterns.Returns the DOCTYPE system ID glob patterns.booleanmatches(DOMDocument document) Returnstrueif this matcher matches the given document.voidsetGrammarURI(List<String> grammarURI) Sets the grammar URI glob patterns.voidsetNamespaceURI(List<String> namespaceURI) Sets the namespace URI glob patterns.voidsetPublicId(List<String> publicId) Sets the DOCTYPE public ID glob patterns.voidsetRootElement(List<String> rootElement) Sets the root element name glob patterns.voidsetSystemId(List<String> systemId) Sets the DOCTYPE system ID glob patterns.Methods inherited from class org.eclipse.lemminx.settings.PathPatternMatcher
createGlobMatcher, equals, getPathMatcher, getPattern, matches, matches, setPathMatcher, setPattern
-
Constructor Details
-
DocumentMatcher
public DocumentMatcher()
-
-
Method Details
-
matches
Returnstrueif this matcher matches the given document. Checks the file URI pattern (inherited fromPathPatternMatcher) and all document-level criteria. All non-null criteria must match (AND).Use case: a matcher with both
pattern="**/docs/**/*.xml"andnamespaceURI=["http://docbook.org/ns/docbook"]matches only DocBook files inside adocs/folder.- Parameters:
document- the XML document to check.- Returns:
trueif all specified criteria match.
-
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
nullif not specified.
-
setNamespaceURI
Sets the namespace URI glob patterns.- Parameters:
namespaceURI- the namespace URI patterns.
-
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 withnamespaceURIorpatternto disambiguate from Ant's<project>.- Returns:
- the root element name patterns, or
nullif not specified.
-
setRootElement
Sets the root element name glob patterns.- Parameters:
rootElement- the root element name patterns.
-
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
nullif not specified.
-
setPublicId
Sets the DOCTYPE public ID glob patterns.- Parameters:
publicId- the public ID patterns.
-
getSystemId
Returns the DOCTYPE system ID glob patterns.Use case:
["http://mybatis.org/dtd/*"]matches all MyBatis DTDs.- Returns:
- the system ID patterns, or
nullif not specified.
-
setSystemId
Sets the DOCTYPE system ID glob patterns.- Parameters:
systemId- the system ID patterns.
-
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
nullif not specified.
-
setGrammarURI
Sets the grammar URI glob patterns.- Parameters:
grammarURI- the grammar URI patterns.
-