forked from eclipse-lemminx/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix XML catalog with XSD files that have <xs:include />
Fixes eclipse-lemminx#914 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
6c048fd
commit e08f0b9
Showing
7 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...n/java/org/eclipse/lemminx/extensions/contentmodel/uriresolver/LSPXMLCatalogResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.eclipse.lemminx.extensions.contentmodel.uriresolver; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.xerces.impl.xs.XSDDescription; | ||
import org.apache.xerces.util.XMLCatalogResolver; | ||
import org.apache.xerces.xni.XMLResourceIdentifier; | ||
import org.apache.xerces.xni.XNIException; | ||
|
||
class LSPXMLCatalogResolver extends XMLCatalogResolver { | ||
|
||
public LSPXMLCatalogResolver(String[] catalogs) { | ||
super(catalogs); | ||
} | ||
|
||
@Override | ||
public String resolveIdentifier(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException { | ||
if (isXSDInclude(resourceIdentifier)) { | ||
return resourceIdentifier.getExpandedSystemId(); | ||
} | ||
return super.resolveIdentifier(resourceIdentifier); | ||
} | ||
|
||
private boolean isXSDInclude(XMLResourceIdentifier resourceIdentifier) { | ||
if (resourceIdentifier != null && resourceIdentifier instanceof XSDDescription | ||
&& resourceIdentifier.getNamespace() != null) { | ||
XSDDescription description = (XSDDescription) resourceIdentifier; | ||
int contextType = description.getContextType(); | ||
return contextType == XSDDescription.CONTEXT_INCLUDE || contextType == XSDDescription.CONTEXT_IMPORT; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
org.eclipse.lemminx/src/test/resources/catalogs/include/catalog-include.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> | ||
<uri | ||
name="http://foobar.com/test" | ||
uri="./test.xsd" /> | ||
</catalog> |
19 changes: 19 additions & 0 deletions
19
org.eclipse.lemminx/src/test/resources/catalogs/include/test-include.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://foobar.com/test" xmlns:test="http://foobar.com/test"> | ||
<xs:element name="document"> | ||
<xs:complexType> | ||
<xs:sequence> | ||
<xs:element maxOccurs="unbounded" ref="test:page"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:element> | ||
<xs:element name="page" type="test:page-content"/> | ||
<xs:complexType name="page-content"> | ||
<xs:sequence> | ||
<xs:element ref="test:title"/> | ||
<xs:element ref="test:content"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:element name="title" type="xs:string"/> | ||
<xs:element name="content" type="xs:string"/> | ||
</xs:schema> |
13 changes: 13 additions & 0 deletions
13
org.eclipse.lemminx/src/test/resources/catalogs/include/test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document xmlns="http://foobar.com/test"> | ||
<page> | ||
<title></title><content></content></page> | ||
<page> | ||
<title>Page 1</title> | ||
<content>Content for page 1</content> | ||
</page> | ||
<page> | ||
<title>Page 2</title> | ||
<content>Content for page 2</content> | ||
</page> | ||
</document> |
4 changes: 4 additions & 0 deletions
4
org.eclipse.lemminx/src/test/resources/catalogs/include/test.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://foobar.com/test" xmlns:test="http://foobar.com/test"> | ||
<xs:include schemaLocation="test-include.xsd"/> | ||
</xs:schema> |