From c423ef992e0fe9cbaea6538e572734764770751d Mon Sep 17 00:00:00 2001 From: JoeWang-Java Date: Thu, 13 Mar 2025 18:52:37 +0000 Subject: [PATCH 1/3] 8351969: Add Public Identifiers to the JDK built-in Catalog --- .../xml/internal/jdkcatalog/JDKCatalog.xml | 15 +- .../jdkcatalog/w3c/dtd/schema10/XMLSchema.dtd | 247 +++++------------- .../jdkcatalog/w3c/dtd/schema10/datatypes.dtd | 41 +-- .../common/jdkcatalog/JDKCatalogTest.java | 57 +++- 4 files changed, 144 insertions(+), 216 deletions(-) diff --git a/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/JDKCatalog.xml b/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/JDKCatalog.xml index 74ba003250150..65aa754c38b97 100644 --- a/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/JDKCatalog.xml +++ b/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/JDKCatalog.xml @@ -1,7 +1,7 @@ + @@ -81,8 +82,11 @@ - + + + + @@ -97,11 +101,12 @@ - + + - + diff --git a/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/XMLSchema.dtd b/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/XMLSchema.dtd index 64aa2d9701924..3481ba68d2402 100644 --- a/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/XMLSchema.dtd +++ b/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/XMLSchema.dtd @@ -1,21 +1,23 @@ - - + + + + + + + declaration of the XML Schema namespace is almost certainly not + a valid schema. --> - - + are defined in XML Schema: Part 2: Datatypes --> + - - - - @@ -49,10 +48,7 @@ - - - @@ -61,14 +57,11 @@ + anyAttribute='##other' in the schema for schemas --> - - @@ -85,12 +78,9 @@ - - - @@ -102,7 +92,6 @@ - @@ -110,20 +99,16 @@ - - - + - + %xs-datatypes; - - - + - - - @@ -170,17 +145,17 @@ %particleAndAttrs;))> - + @@ -191,12 +166,6 @@ id ID #IMPLIED %complexContentAttrs;> - - - @@ -205,14 +174,13 @@ id ID #IMPLIED %simpleContentAttrs;> - @@ -239,25 +206,15 @@ default CDATA #IMPLIED fixed CDATA #IMPLIED form %formValues; #IMPLIED - targetNamespace %URIref; #IMPLIED %elementAttrs;> + substitutionGroup, if any, else the ur-type, i.e. unconstrained --> - - - - - - + @@ -289,12 +246,15 @@ + + + - - - + @@ -371,48 +318,34 @@ - - - - - - - - + name %NCName; #REQUIRED + id ID #IMPLIED + public CDATA #REQUIRED + system %URIref; #IMPLIED + %notationAttrs;> diff --git a/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/datatypes.dtd b/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/datatypes.dtd index f9352bae1c4f7..ed07e4e9493d7 100644 --- a/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/datatypes.dtd +++ b/src/java.xml/share/classes/jdk/xml/internal/jdkcatalog/w3c/dtd/schema10/datatypes.dtd @@ -1,8 +1,10 @@ @@ -53,12 +49,9 @@ - - - @@ -82,20 +75,18 @@ length, maxLength, minLength within datatype, and the min- and max- variants of Inclusive and Exclusive are mutually exclusive. On the other hand, pattern and - enumeration and assertion may repeat. + enumeration may repeat. --> - + - - - + + @@ -210,13 +201,3 @@ - - - - - - diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java index 0f4c0aec2deb9..db2bcedfe78c4 100644 --- a/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java +++ b/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,13 +28,16 @@ import java.nio.file.Paths; import java.util.stream.Collectors; import javax.xml.XMLConstants; +import javax.xml.catalog.Catalog; import javax.xml.catalog.CatalogFeatures; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.sax.SAXSource; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; +import jdk.xml.internal.JdkCatalog; import org.testng.Assert; import org.testng.Assert.ThrowingRunnable; +import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.xml.sax.InputSource; @@ -44,7 +47,8 @@ /* * @test - * @bug 8344800 8345353 + * @bug 8344800 8345353 8351969 + * @modules java.xml/jdk.xml.internal * @run testng/othervm common.jdkcatalog.JDKCatalogTest * @summary Verifies the W3C DTDs and XSDs in the JDK built-in catalog. */ @@ -64,6 +68,29 @@ public class JDKCatalogTest { static final String TARGET_NAMESPACE = "{{targetNamespace}}"; static final String ROOT_ELEMENT = "{{rootElement}}"; + Catalog jdkCatalog; + + /* + * DataProvider: DTDs in the JDK built-in Catalog + * Data provided: public and system Ids, see test testDTDsInJDKCatalog + */ + @DataProvider(name = "DTDsInJDKCatalog") + public Object[][] getDTDsInJDKCatalog() throws Exception { + return new Object[][]{ + // Schema 1.0 + {"-//W3C//DTD XMLSCHEMA 200102//EN", "http://www.w3.org/2001/XMLSchema.dtd"}, + {"datatypes", "http://www.w3.org/2001/datatypes.dtd"}, + // XHTML 1.0 + {"-//W3C//DTD XHTML 1.0 Frameset//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"}, + {"-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"}, + {"-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"}, + // XHTML 1.1 + {"-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"}, + // DTD for W3C specifications + {"-//W3C//DTD Specification V2.10//EN", "http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd"}, + }; + } + /* * DataProvider: for verifying DTDs in the JDKCatalog * Data provided: see test testExternalDTD @@ -106,6 +133,32 @@ public Object[][] getXSD() throws Exception { }; } + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + // initialize JDKCatalog + JdkCatalog.init("continue"); + jdkCatalog = JdkCatalog.catalog; + } + + /** + * Verifies that the JDK built-in Catalog supports both the Public and System + * identifiers for DTDs. + * @param publicId the public Id + * @param systemId the system Id + * @throws Exception if test fails unexpectedly + */ + @Test(dataProvider = "DTDsInJDKCatalog") + public void testDTDsInJDKCatalog(String publicId, String systemId) + throws Exception { + String matchingPubId = jdkCatalog.matchPublic(publicId); + String matchingSysId = jdkCatalog.matchSystem(systemId); + + Assert.assertEquals(matchingPubId, matchingSysId); + } + /** * Verifies that references to the W3C DTDs are resolved by the JDK built-in * catalog. From 4482d59005d739ef85196505f5503af002882e6c Mon Sep 17 00:00:00 2001 From: JoeWang-Java Date: Fri, 14 Mar 2025 18:32:33 +0000 Subject: [PATCH 2/3] update the test: change variables and etc. --- .../common/jdkcatalog/JDKCatalogTest.java | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java index db2bcedfe78c4..a035629d066fd 100644 --- a/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java +++ b/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java @@ -22,6 +22,9 @@ */ package common.jdkcatalog; +import static jaxp.library.JAXPTestUtilities.SRC_DIR; +import static jaxp.library.JAXPTestUtilities.isWindows; + import java.io.StringReader; import java.nio.file.Files; import java.nio.file.Path; @@ -37,7 +40,6 @@ import jdk.xml.internal.JdkCatalog; import org.testng.Assert; import org.testng.Assert.ThrowingRunnable; -import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.xml.sax.InputSource; @@ -49,33 +51,29 @@ * @test * @bug 8344800 8345353 8351969 * @modules java.xml/jdk.xml.internal + * @library /javax/xml/jaxp/libs * @run testng/othervm common.jdkcatalog.JDKCatalogTest * @summary Verifies the W3C DTDs and XSDs in the JDK built-in catalog. */ public class JDKCatalogTest { - static String CLS_DIR = System.getProperty("test.classes"); - static String SRC_DIR = System.getProperty("test.src"); - public static boolean isWindows = false; + private static final String JDKCATALOG_RESOLVE = "jdk.xml.jdkcatalog.resolve"; + private static final String PUBLIC_ID = "{{publicId}}"; + private static final String SYSTEM_ID = "{{systemId}}"; + private static final String XSD_LOCATION = "{{SCHEMA_LOCATION}}"; + private static final String TARGET_NAMESPACE = "{{targetNamespace}}"; + private static final String ROOT_ELEMENT = "{{rootElement}}"; + private static final Catalog JDKCATALOG; static { - if (System.getProperty("os.name").contains("Windows")) { - isWindows = true; - } - }; - public static final String JDKCATALOG_RESOLVE = "jdk.xml.jdkcatalog.resolve"; - static final String PUBLIC_ID = "{{publicId}}"; - static final String SYSTEM_ID = "{{systemId}}"; - static final String XSD_LOCATION = "{{SCHEMA_LOCATION}}"; - static final String TARGET_NAMESPACE = "{{targetNamespace}}"; - static final String ROOT_ELEMENT = "{{rootElement}}"; - - Catalog jdkCatalog; + JdkCatalog.init("continue"); + JDKCATALOG = JdkCatalog.catalog; + } /* * DataProvider: DTDs in the JDK built-in Catalog * Data provided: public and system Ids, see test testDTDsInJDKCatalog */ @DataProvider(name = "DTDsInJDKCatalog") - public Object[][] getDTDsInJDKCatalog() throws Exception { + public Object[][] getDTDsInJDKCatalog() { return new Object[][]{ // Schema 1.0 {"-//W3C//DTD XMLSCHEMA 200102//EN", "http://www.w3.org/2001/XMLSchema.dtd"}, @@ -133,29 +131,16 @@ public Object[][] getXSD() throws Exception { }; } - /* - * Initializing fields - */ - @BeforeClass - public void setUpClass() throws Exception { - // initialize JDKCatalog - JdkCatalog.init("continue"); - jdkCatalog = JdkCatalog.catalog; - } - /** * Verifies that the JDK built-in Catalog supports both the Public and System * identifiers for DTDs. * @param publicId the public Id * @param systemId the system Id - * @throws Exception if test fails unexpectedly */ @Test(dataProvider = "DTDsInJDKCatalog") - public void testDTDsInJDKCatalog(String publicId, String systemId) - throws Exception { - String matchingPubId = jdkCatalog.matchPublic(publicId); - String matchingSysId = jdkCatalog.matchSystem(systemId); - + public void testDTDsInJDKCatalog(String publicId, String systemId) { + String matchingPubId = JDKCATALOG.matchPublic(publicId); + String matchingSysId = JDKCATALOG.matchSystem(systemId); Assert.assertEquals(matchingPubId, matchingSysId); } From 0b5a1cc47afa2a881b36bd82d84c1dc8137edc23 Mon Sep 17 00:00:00 2001 From: JoeWang-Java Date: Wed, 19 Mar 2025 00:38:53 +0000 Subject: [PATCH 3/3] replace JDK Catalog in the java.xml module with public API --- .../common/jdkcatalog/JDKCatalogTest.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java index a035629d066fd..ffc2f313e893b 100644 --- a/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java +++ b/test/jaxp/javax/xml/jaxp/unittest/common/jdkcatalog/JDKCatalogTest.java @@ -22,10 +22,8 @@ */ package common.jdkcatalog; -import static jaxp.library.JAXPTestUtilities.SRC_DIR; -import static jaxp.library.JAXPTestUtilities.isWindows; - import java.io.StringReader; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -33,11 +31,12 @@ import javax.xml.XMLConstants; import javax.xml.catalog.Catalog; import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogManager; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.sax.SAXSource; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; -import jdk.xml.internal.JdkCatalog; +import jaxp.library.JAXPTestUtilities; import org.testng.Assert; import org.testng.Assert.ThrowingRunnable; import org.testng.annotations.DataProvider; @@ -50,7 +49,6 @@ /* * @test * @bug 8344800 8345353 8351969 - * @modules java.xml/jdk.xml.internal * @library /javax/xml/jaxp/libs * @run testng/othervm common.jdkcatalog.JDKCatalogTest * @summary Verifies the W3C DTDs and XSDs in the JDK built-in catalog. @@ -62,11 +60,9 @@ public class JDKCatalogTest { private static final String XSD_LOCATION = "{{SCHEMA_LOCATION}}"; private static final String TARGET_NAMESPACE = "{{targetNamespace}}"; private static final String ROOT_ELEMENT = "{{rootElement}}"; - private static final Catalog JDKCATALOG; - static { - JdkCatalog.init("continue"); - JDKCATALOG = JdkCatalog.catalog; - } + private static final String JDKCATALOG_URL = "jrt:/java.xml/jdk/xml/internal/jdkcatalog/JDKCatalog.xml"; + + private Catalog catalog = CatalogManager.catalog(CatalogFeatures.defaults(), URI.create(JDKCATALOG_URL)); /* * DataProvider: DTDs in the JDK built-in Catalog @@ -139,8 +135,8 @@ public Object[][] getXSD() throws Exception { */ @Test(dataProvider = "DTDsInJDKCatalog") public void testDTDsInJDKCatalog(String publicId, String systemId) { - String matchingPubId = JDKCATALOG.matchPublic(publicId); - String matchingSysId = JDKCATALOG.matchSystem(systemId); + String matchingPubId = catalog.matchPublic(publicId); + String matchingSysId = catalog.matchSystem(systemId); Assert.assertEquals(matchingPubId, matchingSysId); } @@ -184,10 +180,10 @@ public void testExternalDTD(String publicId, String systemId, Class e public void testXSD(String xmlTemplate, String xsdLocation, String targetNS, String rootElement, String catalog, Class expectedThrow) throws Exception { - String xmlSrcPath = SRC_DIR + "/" + xmlTemplate; + String xmlSrcPath = JAXPTestUtilities.SRC_DIR + "/" + xmlTemplate; final String xmlSrcId = getSysId(xmlSrcPath); - final String customCatalog = getSysId((catalog != null) ? SRC_DIR + "/" + catalog : null); + final String customCatalog = getSysId((catalog != null) ? JAXPTestUtilities.SRC_DIR + "/" + catalog : null); final String xmlString = generateXMLWithXSDRef(xmlSrcPath, xsdLocation, targetNS, rootElement); @@ -245,7 +241,7 @@ public void parseWithResolveStrict(String xml) */ private String generateXMLWithDTDRef(String publicId, String systemId) throws Exception { - Path path = Paths.get(SRC_DIR + "/dtdtest.xml"); + Path path = Paths.get(JAXPTestUtilities.SRC_DIR + "/dtdtest.xml"); String xmlString = Files.lines(path).map(line -> { line = line.replace(PUBLIC_ID, publicId); line = line.replace(SYSTEM_ID, systemId); @@ -287,7 +283,7 @@ private String generateXMLWithXSDRef(String xmlSrcPath, String xsd, private String getSysId(String path) { if (path == null) return null; String xmlSysId = "file://" + path; - if (isWindows) { + if (JAXPTestUtilities.isWindows) { path = path.replace('\\', '/'); xmlSysId = "file:///" + path; }