Skip to content

Commit

Permalink
xml catalog definition should be built-in
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Dec 8, 2020
1 parent 3bf5229 commit 2360097
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.xerces.xni.parser.XMLInputSource;
import org.eclipse.lemminx.dom.DOMDocument;
import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lemminx.uriresolver.CacheResourcesManager;
import org.eclipse.lemminx.uriresolver.CacheResourcesManager.ResourceToDeploy;
import org.eclipse.lemminx.uriresolver.URIResolverExtension;

/**
Expand All @@ -28,13 +30,15 @@
public class XMLCatalogURIResolverExtension implements URIResolverExtension {

/**
* The XSL namespace URI (=
* The XML Catalog namespace URI (=
* http://www.oasis-open.org/committees/entity/release/1.1/catalog.xsd)
*/
private static final String CATALOG_NAMESPACE_URI = "urn:oasis:names:tc:entity:xmlns:xml:catalog"; //$NON-NLS-1$

private static final String CATALOG_SYSTEM = "https://www.oasis-open.org/committees/entity/release/1.1/catalog.xsd";
private static final String CATALOG_SYSTEM = "http://www.oasis-open.org/committees/entity/release/1.1/catalog.xsd";

private static final ResourceToDeploy CATALOG_RESOURCE = new ResourceToDeploy(CATALOG_SYSTEM,
"schemas/catalog/catalog-1.1.xsd");
private final XMLExtensionsRegistry extensionsRegistry;

@Override
Expand All @@ -54,6 +58,11 @@ public String resolve(String baseLocation, String publicId, String systemId) {
if (hasDTDorXMLSchema(baseLocation)) {
return null;
}
try {
return CacheResourcesManager.getResourceCachePath(CATALOG_RESOURCE).toFile().toURI().toString();
} catch (Exception e) {
// Do nothing?
}
return CATALOG_SYSTEM;
}

Expand All @@ -64,7 +73,11 @@ public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) th
}
String publicId = resourceIdentifier.getNamespace();
if (CATALOG_NAMESPACE_URI.equals(publicId)) {
return new XMLInputSource(publicId, CATALOG_SYSTEM, CATALOG_SYSTEM);
String baseLocation = resourceIdentifier.getBaseSystemId();
String catalogFilePath = resolve(baseLocation, publicId, null);
if (catalogFilePath != null) {
return new XMLInputSource(publicId, catalogFilePath, catalogFilePath);
}
}
return null;
}
Expand Down
230 changes: 230 additions & 0 deletions org.eclipse.lemminx/src/main/resources/schemas/catalog/catalog-1.1.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:er="urn:oasis:names:tc:entity:xmlns:xml:catalog"
targetNamespace="urn:oasis:names:tc:entity:xmlns:xml:catalog"
elementFormDefault="qualified">

<!-- $Id: catalog.xsd,v 1.15 2005/10/07 13:27:08 ndw Exp $ -->

<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>

<xs:simpleType name="pubIdChars">
<!-- A string of the characters defined as pubIdChar in production 13
of the Second Edition of the XML 1.0 Recommendation. Does not include
the whitespace characters because they're normalized by XML parsing. -->
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9\-'\(\)+,./:=?;!*#@$_%]*"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="publicIdentifier">
<xs:restriction base="er:pubIdChars"/>
</xs:simpleType>

<xs:simpleType name="partialPublicIdentifier">
<xs:restriction base="er:pubIdChars"/>
</xs:simpleType>

<xs:simpleType name="systemOrPublic">
<xs:restriction base="xs:string">
<xs:enumeration value="system"/>
<xs:enumeration value="public"/>
</xs:restriction>
</xs:simpleType>

<!-- The global attribute xml:base is not explicitly declared; -->
<!-- it is allowed by the anyAttribute declarations. -->

<xs:complexType name="catalog">
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element ref="er:public"/>
<xs:element ref="er:system"/>
<xs:element ref="er:uri"/>
<xs:element ref="er:rewriteSystem"/>
<xs:element ref="er:rewriteURI"/>
<xs:element ref="er:uriSuffix"/>
<xs:element ref="er:systemSuffix"/>
<xs:element ref="er:delegatePublic"/>
<xs:element ref="er:delegateSystem"/>
<xs:element ref="er:delegateURI"/>
<xs:element ref="er:nextCatalog"/>
<xs:element ref="er:group"/>
<xs:any namespace="##other" processContents="skip"/>
</xs:choice>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="prefer" type="er:systemOrPublic"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>

<xs:complexType name="public">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="publicId" type="er:publicIdentifier"
use="required"/>
<xs:attribute name="uri" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="system">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="systemId" type="xs:string"
use="required"/>
<xs:attribute name="uri" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="uri">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="name" type="xs:anyURI"
use="required"/>
<xs:attribute name="uri" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="rewriteSystem">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="systemIdStartString"
type="xs:string"
use="required"/>
<xs:attribute name="rewritePrefix" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="rewriteURI">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="uriStartString"
type="xs:string"
use="required"/>
<xs:attribute name="rewritePrefix" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="systemSuffix">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="systemIdSuffix"
type="xs:string"
use="required"/>
<xs:attribute name="uri" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="uriSuffix">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="uriSuffix"
type="xs:string"
use="required"/>
<xs:attribute name="uri" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="delegatePublic">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="publicIdStartString"
type="er:partialPublicIdentifier"
use="required"/>
<xs:attribute name="catalog" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="delegateSystem">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="systemIdStartString"
type="xs:string"
use="required"/>
<xs:attribute name="catalog" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="delegateURI">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="uriStartString"
type="xs:string"
use="required"/>
<xs:attribute name="catalog" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="nextCatalog">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="catalog" type="xs:anyURI" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="group">
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element ref="er:public"/>
<xs:element ref="er:system"/>
<xs:element ref="er:uri"/>
<xs:element ref="er:rewriteSystem"/>
<xs:element ref="er:rewriteURI"/>
<xs:element ref="er:uriSuffix"/>
<xs:element ref="er:systemSuffix"/>
<xs:element ref="er:delegatePublic"/>
<xs:element ref="er:delegateSystem"/>
<xs:element ref="er:delegateURI"/>
<xs:element ref="er:nextCatalog"/>
<xs:any namespace="##other" processContents="skip"/>
</xs:choice>
<xs:attribute name="prefer" type="er:systemOrPublic"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>

<xs:element name="catalog" type="er:catalog"/>
<xs:element name="public" type="er:public"/>
<xs:element name="system" type="er:system"/>
<xs:element name="uri" type="er:uri"/>
<xs:element name="rewriteSystem" type="er:rewriteSystem"/>
<xs:element name="rewriteURI" type="er:rewriteURI"/>
<xs:element name="systemSuffix" type="er:systemSuffix"/>
<xs:element name="uriSuffix" type="er:uriSuffix"/>
<xs:element name="delegatePublic" type="er:delegatePublic"/>
<xs:element name="delegateSystem" type="er:delegateSystem"/>
<xs:element name="delegateURI" type="er:delegateURI"/>
<xs:element name="nextCatalog" type="er:nextCatalog"/>
<xs:element name="group" type="er:group"/>

</xs:schema>

0 comments on commit 2360097

Please sign in to comment.