22
22
*/
23
23
package common .jdkcatalog ;
24
24
25
- import static jaxp .library .JAXPTestUtilities .SRC_DIR ;
26
- import static jaxp .library .JAXPTestUtilities .isWindows ;
27
-
28
25
import java .io .StringReader ;
26
+ import java .net .URI ;
29
27
import java .nio .file .Files ;
30
28
import java .nio .file .Path ;
31
29
import java .nio .file .Paths ;
32
30
import java .util .stream .Collectors ;
33
31
import javax .xml .XMLConstants ;
34
32
import javax .xml .catalog .Catalog ;
35
33
import javax .xml .catalog .CatalogFeatures ;
34
+ import javax .xml .catalog .CatalogManager ;
36
35
import javax .xml .parsers .SAXParserFactory ;
37
36
import javax .xml .transform .sax .SAXSource ;
38
37
import javax .xml .validation .SchemaFactory ;
39
38
import javax .xml .validation .Validator ;
40
- import jdk . xml . internal . JdkCatalog ;
39
+ import jaxp . library . JAXPTestUtilities ;
41
40
import org .testng .Assert ;
42
41
import org .testng .Assert .ThrowingRunnable ;
43
42
import org .testng .annotations .DataProvider ;
50
49
/*
51
50
* @test
52
51
* @bug 8344800 8345353 8351969
53
- * @modules java.xml/jdk.xml.internal
54
52
* @library /javax/xml/jaxp/libs
55
53
* @run testng/othervm common.jdkcatalog.JDKCatalogTest
56
54
* @summary Verifies the W3C DTDs and XSDs in the JDK built-in catalog.
@@ -62,11 +60,9 @@ public class JDKCatalogTest {
62
60
private static final String XSD_LOCATION = "{{SCHEMA_LOCATION}}" ;
63
61
private static final String TARGET_NAMESPACE = "{{targetNamespace}}" ;
64
62
private static final String ROOT_ELEMENT = "{{rootElement}}" ;
65
- private static final Catalog JDKCATALOG ;
66
- static {
67
- JdkCatalog .init ("continue" );
68
- JDKCATALOG = JdkCatalog .catalog ;
69
- }
63
+ private static final String JDKCATALOG_URL = "jrt:/java.xml/jdk/xml/internal/jdkcatalog/JDKCatalog.xml" ;
64
+
65
+ private Catalog catalog = CatalogManager .catalog (CatalogFeatures .defaults (), URI .create (JDKCATALOG_URL ));
70
66
71
67
/*
72
68
* DataProvider: DTDs in the JDK built-in Catalog
@@ -139,8 +135,8 @@ public Object[][] getXSD() throws Exception {
139
135
*/
140
136
@ Test (dataProvider = "DTDsInJDKCatalog" )
141
137
public void testDTDsInJDKCatalog (String publicId , String systemId ) {
142
- String matchingPubId = JDKCATALOG .matchPublic (publicId );
143
- String matchingSysId = JDKCATALOG .matchSystem (systemId );
138
+ String matchingPubId = catalog .matchPublic (publicId );
139
+ String matchingSysId = catalog .matchSystem (systemId );
144
140
Assert .assertEquals (matchingPubId , matchingSysId );
145
141
}
146
142
@@ -184,10 +180,10 @@ public void testExternalDTD(String publicId, String systemId, Class<Throwable> e
184
180
public void testXSD (String xmlTemplate , String xsdLocation , String targetNS , String rootElement , String catalog ,
185
181
Class <Throwable > expectedThrow )
186
182
throws Exception {
187
- String xmlSrcPath = SRC_DIR + "/" + xmlTemplate ;
183
+ String xmlSrcPath = JAXPTestUtilities . SRC_DIR + "/" + xmlTemplate ;
188
184
final String xmlSrcId = getSysId (xmlSrcPath );
189
185
190
- final String customCatalog = getSysId ((catalog != null ) ? SRC_DIR + "/" + catalog : null );
186
+ final String customCatalog = getSysId ((catalog != null ) ? JAXPTestUtilities . SRC_DIR + "/" + catalog : null );
191
187
192
188
final String xmlString = generateXMLWithXSDRef (xmlSrcPath , xsdLocation ,
193
189
targetNS , rootElement );
@@ -245,7 +241,7 @@ public void parseWithResolveStrict(String xml)
245
241
*/
246
242
private String generateXMLWithDTDRef (String publicId , String systemId )
247
243
throws Exception {
248
- Path path = Paths .get (SRC_DIR + "/dtdtest.xml" );
244
+ Path path = Paths .get (JAXPTestUtilities . SRC_DIR + "/dtdtest.xml" );
249
245
String xmlString = Files .lines (path ).map (line -> {
250
246
line = line .replace (PUBLIC_ID , publicId );
251
247
line = line .replace (SYSTEM_ID , systemId );
@@ -287,7 +283,7 @@ private String generateXMLWithXSDRef(String xmlSrcPath, String xsd,
287
283
private String getSysId (String path ) {
288
284
if (path == null ) return null ;
289
285
String xmlSysId = "file://" + path ;
290
- if (isWindows ) {
286
+ if (JAXPTestUtilities . isWindows ) {
291
287
path = path .replace ('\\' , '/' );
292
288
xmlSysId = "file:///" + path ;
293
289
}
0 commit comments