author | joehw |
Wed, 11 Jan 2017 13:06:04 -0800 | |
changeset 43121 | e73af7b6ce47 |
parent 41847 | e444f2f9dc8a |
child 44380 | 0197177795e9 |
permissions | -rw-r--r-- |
33542 | 1 |
/* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
33542 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package catalog; |
|
24 |
||
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
25 |
import java.io.File; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
26 |
import java.io.FileInputStream; |
33542 | 27 |
import java.io.IOException; |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
28 |
import java.io.InputStream; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
29 |
import java.io.StringReader; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
30 |
import java.io.StringWriter; |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
31 |
import java.net.URI; |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
32 |
import java.nio.file.Paths; |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
33 |
import javax.xml.XMLConstants; |
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
34 |
import javax.xml.catalog.Catalog; |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
35 |
import javax.xml.catalog.CatalogException; |
33542 | 36 |
import javax.xml.catalog.CatalogFeatures; |
37 |
import javax.xml.catalog.CatalogFeatures.Feature; |
|
38 |
import javax.xml.catalog.CatalogManager; |
|
39 |
import javax.xml.catalog.CatalogResolver; |
|
40 |
import javax.xml.parsers.ParserConfigurationException; |
|
41 |
import javax.xml.parsers.SAXParser; |
|
42 |
import javax.xml.parsers.SAXParserFactory; |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
43 |
import javax.xml.stream.XMLInputFactory; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
44 |
import javax.xml.stream.XMLStreamConstants; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
45 |
import javax.xml.stream.XMLStreamReader; |
38497 | 46 |
import javax.xml.transform.Source; |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
47 |
import javax.xml.transform.Transformer; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
48 |
import javax.xml.transform.TransformerFactory; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
49 |
import javax.xml.transform.sax.SAXSource; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
50 |
import javax.xml.transform.stream.StreamResult; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
51 |
import javax.xml.transform.stream.StreamSource; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
52 |
import javax.xml.validation.Schema; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
53 |
import javax.xml.validation.SchemaFactory; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
54 |
import javax.xml.validation.Validator; |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
55 |
import static jaxp.library.JAXPTestUtilities.clearSystemProperty; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
56 |
import static jaxp.library.JAXPTestUtilities.setSystemProperty; |
33542 | 57 |
import org.testng.Assert; |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
58 |
import org.testng.annotations.BeforeClass; |
33542 | 59 |
import org.testng.annotations.DataProvider; |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
60 |
import org.testng.annotations.Listeners; |
33542 | 61 |
import org.testng.annotations.Test; |
62 |
import org.xml.sax.Attributes; |
|
63 |
import org.xml.sax.ErrorHandler; |
|
37384
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
64 |
import org.xml.sax.InputSource; |
33542 | 65 |
import org.xml.sax.SAXException; |
66 |
import org.xml.sax.XMLReader; |
|
67 |
import org.xml.sax.ext.DefaultHandler2; |
|
68 |
||
69 |
/* |
|
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
70 |
* @test |
41847 | 71 |
* @bug 8081248 8144966 8146606 8146237 8150969 8151162 8152527 8154220 8163232 |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
72 |
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest |
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
73 |
* @run testng/othervm -DrunSecMngr=true catalog.CatalogTest |
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
74 |
* @run testng/othervm catalog.CatalogTest |
33542 | 75 |
* @summary Tests basic Catalog functions. |
76 |
*/ |
|
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
77 |
@Listeners({jaxp.library.FilePolicy.class}) |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
78 |
public class CatalogTest extends CatalogSupportBase { |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
79 |
static final String KEY_FILES = "javax.xml.catalog.files"; |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
80 |
|
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
81 |
|
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
82 |
/* |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
83 |
* Initializing fields |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
84 |
*/ |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
85 |
@BeforeClass |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
86 |
public void setUpClass() throws Exception { |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
87 |
super.setUp(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
88 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
89 |
|
40753
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
90 |
/* |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
91 |
* @bug 8162431 |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
92 |
* Verifies that circular references are caught and |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
93 |
* CatalogException is thrown. |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
94 |
*/ |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
95 |
@Test(dataProvider = "getFeatures", expectedExceptions = CatalogException.class) |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
96 |
public void testCircularRef(CatalogFeatures cf, String xml) throws Exception { |
40753
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
97 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver( |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
98 |
cf, |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
99 |
getClass().getResource(xml).toURI()); |
40753
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
100 |
catalogResolver.resolve("anyuri", ""); |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
101 |
} |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
102 |
|
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
103 |
/* |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
104 |
DataProvider: used to verify circular reference |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
105 |
Data columns: CatalogFeatures, catalog |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
106 |
*/ |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
107 |
@DataProvider(name = "getFeatures") |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
108 |
public Object[][] getFeatures() { |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
109 |
String self = "catalogReferCircle-itself.xml"; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
110 |
String left = "catalogReferCircle-left.xml"; |
40753
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
111 |
return new Object[][]{ |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
112 |
{CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "false").build(), self}, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
113 |
{CatalogFeatures.defaults(), self}, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
114 |
{CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "false").build(), left}, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
115 |
{CatalogFeatures.defaults(), left} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
116 |
}; |
40753
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
117 |
} |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
118 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
119 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
120 |
* @bug 8163232 |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
121 |
* Verifies that the CatalogResolver supports the following XML Resolvers: |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
122 |
javax.xml.stream.XMLResolver |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
123 |
javax.xml.transform.URIResolver |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
124 |
org.w3c.dom.ls.LSResourceResolver |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
125 |
org.xml.sax.EntityResolver |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
126 |
* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
127 |
* Plus, system and uri entries can equally be used. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
128 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
129 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
130 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
131 |
* Verifies the support for org.xml.sax.EntityResolver. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
132 |
* Expected: the parser returns the expected string. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
133 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
134 |
@Test(dataProvider = "supportXMLResolver") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
135 |
public void supportEntityResolver(URI catalogFile, String xml, String expected) throws Exception { |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
136 |
String xmlSource = getClass().getResource(xml).getFile(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
137 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
138 |
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
139 |
MyCatalogHandler handler = new MyCatalogHandler(cr, elementInSystem); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
140 |
SAXParser parser = getSAXParser(false, true, null); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
141 |
parser.parse(xmlSource, handler); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
142 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
143 |
Assert.assertEquals(handler.getResult().trim(), expected); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
144 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
145 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
146 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
147 |
* Verifies the support for javax.xml.stream.XMLResolver. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
148 |
* Expected: the parser returns the expected string. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
149 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
150 |
@Test(dataProvider = "supportXMLResolver") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
151 |
public void supportXMLResolver(URI catalogFile, String xml, String expected) throws Exception { |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
152 |
String xmlSource = getClass().getResource(xml).getFile(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
153 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
154 |
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
155 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
156 |
XMLInputFactory xifactory = XMLInputFactory.newInstance(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
157 |
xifactory.setProperty(XMLInputFactory.IS_COALESCING, true); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
158 |
xifactory.setProperty(XMLInputFactory.RESOLVER, cr); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
159 |
File file = new File(xmlSource); |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
160 |
String systemId = file.toURI().toASCIIString(); |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
161 |
InputStream entityxml = new FileInputStream(file); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
162 |
XMLStreamReader streamReader = xifactory.createXMLStreamReader(systemId, entityxml); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
163 |
String result = null; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
164 |
while (streamReader.hasNext()) { |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
165 |
int eventType = streamReader.next(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
166 |
if (eventType == XMLStreamConstants.START_ELEMENT) { |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
167 |
eventType = streamReader.next(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
168 |
if (eventType == XMLStreamConstants.CHARACTERS) { |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
169 |
result = streamReader.getText(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
170 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
171 |
} |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
172 |
} |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
173 |
System.out.println(": expected [" + expected + "] <> actual [" + result.trim() + "]"); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
174 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
175 |
Assert.assertEquals(result.trim(), expected); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
176 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
177 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
178 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
179 |
* Verifies the support for org.w3c.dom.ls.LSResourceResolver by ShemaFactory. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
180 |
* Success: parsing goes through with no error |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
181 |
* Fail: throws Exception if references are not resolved (by the CatalogResolver) |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
182 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
183 |
@Test(dataProvider = "supportLSResourceResolver") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
184 |
public void supportLSResourceResolver(URI catalogFile, Source schemaSource) throws SAXException { |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
185 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
186 |
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
187 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
188 |
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
189 |
factory.setResourceResolver(cr); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
190 |
Schema schema = factory.newSchema(schemaSource); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
191 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
192 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
193 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
194 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
195 |
* Verifies the support for org.w3c.dom.ls.LSResourceResolver by Validator. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
196 |
* Success: parsing goes through with no error |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
197 |
* Fail: throws Exception if references are not resolved (by the CatalogResolver) |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
198 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
199 |
@Test(dataProvider = "supportLSResourceResolver1") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
200 |
public void supportLSResourceResolver1(URI catalogFile, Source source) throws Exception { |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
201 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
202 |
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
203 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
204 |
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
205 |
Validator validator = factory.newSchema().newValidator(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
206 |
validator.setResourceResolver(cr); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
207 |
validator.validate(source); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
208 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
209 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
210 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
211 |
* Verifies the support for javax.xml.transform.URIResolver. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
212 |
* Success: parsing goes through with no error |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
213 |
* Fail: throws Exception if references are not resolved (by the CatalogResolver) |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
214 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
215 |
@Test(dataProvider = "supportURIResolver") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
216 |
public void supportURIResolver(URI catalogFile, Source xsl, Source xml, String expected) throws Exception { |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
217 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
218 |
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
219 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
220 |
TransformerFactory factory = TransformerFactory.newInstance(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
221 |
factory.setURIResolver(cr); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
222 |
Transformer transformer = factory.newTransformer(xsl); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
223 |
StringWriter out = new StringWriter(); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
224 |
transformer.transform(xml, new StreamResult(out)); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
225 |
if (expected != null) { |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
226 |
Assert.assertTrue(out.toString().contains(expected), "supportURIResolver"); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
227 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
228 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
229 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
230 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
231 |
DataProvider: used to verify the support of XML Resolvers. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
232 |
Data columns: |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
233 |
catalog filepath, xml source file, expected result |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
234 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
235 |
@DataProvider(name = "supportXMLResolver") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
236 |
public Object[][] supportXMLResolver() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
237 |
URI catalogFile = getClass().getResource("catalog.xml").toURI(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
238 |
URI catalogFileUri = getClass().getResource("catalog_uri.xml").toURI(); |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
239 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
240 |
return new Object[][]{ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
241 |
{catalogFile, "system.xml", "Test system entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
242 |
{catalogFile, "rewritesystem.xml", "Test rewritesystem entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
243 |
{catalogFile, "rewritesystem1.xml", "Test rewritesystem entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
244 |
{catalogFile, "systemsuffix.xml", "Test systemsuffix entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
245 |
{catalogFile, "delegatesystem.xml", "Test delegatesystem entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
246 |
{catalogFile, "public.xml", "Test public entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
247 |
{catalogFile, "delegatepublic.xml", "Test delegatepublic entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
248 |
// using uri entries |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
249 |
{catalogFileUri, "system.xml", "Test system entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
250 |
{catalogFileUri, "rewritesystem.xml", "Test rewritesystem entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
251 |
{catalogFileUri, "rewritesystem1.xml", "Test rewritesystem entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
252 |
{catalogFileUri, "systemsuffix.xml", "Test systemsuffix entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
253 |
{catalogFileUri, "delegateuri.xml", "Test delegateuri entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
254 |
{catalogFileUri, "public.xml", "Test public entry"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
255 |
}; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
256 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
257 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
258 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
259 |
DataProvider: used to verify the support of LSResourceResolver by SchemaFactory. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
260 |
Data columns: |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
261 |
catalog filepath, schema source file |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
262 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
263 |
@DataProvider(name = "supportLSResourceResolver") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
264 |
public Object[][] supportLSResourceResolver() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
265 |
URI catalogFile = getClass().getResource("CatalogSupport.xml").toURI(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
266 |
URI catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").toURI(); |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
267 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
268 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
269 |
* XMLSchema.xsd has a reference to XMLSchema.dtd which in turn refers to |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
270 |
* datatypes.dtd |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
271 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
272 |
return new Object[][]{ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
273 |
{catalogFile, new StreamSource(new StringReader(xsd_xmlSchema))}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
274 |
{catalogFile, new StreamSource(new StringReader(xsd_xmlSchema_import))}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
275 |
{catalogFile, new StreamSource(new StringReader(xsd_include_company))}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
276 |
{catalogFileUri, new StreamSource(new StringReader(xsd_xmlSchema))}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
277 |
{catalogFileUri, new StreamSource(new StringReader(xsd_xmlSchema_import))}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
278 |
{catalogFileUri, new StreamSource(new StringReader(xsd_include_company))}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
279 |
}; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
280 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
281 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
282 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
283 |
DataProvider: used to verify the support of LSResourceResolver by Validator. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
284 |
Data columns: |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
285 |
catalog filepath, source file |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
286 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
287 |
@DataProvider(name = "supportLSResourceResolver1") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
288 |
public Object[][] supportLSResourceResolver1() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
289 |
URI catalogFile = getClass().getResource("CatalogSupport.xml").toURI(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
290 |
URI catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").toURI(); |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
291 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
292 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
293 |
* val_test.xml has a reference to system.dtd and val_test.xsd |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
294 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
295 |
SAXSource ss = new SAXSource(new InputSource(xml_val_test)); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
296 |
ss.setSystemId(xml_val_test_id); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
297 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
298 |
return new Object[][]{ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
299 |
{catalogFile, ss}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
300 |
{catalogFileUri, ss}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
301 |
}; |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
302 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
303 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
304 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
305 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
306 |
DataProvider: used to verify the support of LSResourceResolver by Validator. |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
307 |
Data columns: |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
308 |
catalog filepath, xsl source, xml source file |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
309 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
310 |
@DataProvider(name = "supportURIResolver") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
311 |
public Object[][] supportURIResolver() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
312 |
URI catalogFile = getClass().getResource("CatalogSupport.xml").toURI(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
313 |
URI catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").toURI(); |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
314 |
SAXSource xslSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
315 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
316 |
/* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
317 |
* val_test.xml has a reference to system.dtd and val_test.xsd |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
318 |
*/ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
319 |
SAXSource ss = new SAXSource(new InputSource(xml_val_test)); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
320 |
ss.setSystemId(xml_val_test_id); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
321 |
|
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
322 |
return new Object[][]{ |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
323 |
{catalogFile, new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())), |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
324 |
new StreamSource(new File(xml_doc)), "Resolved by a catalog"}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
325 |
{catalogFileUri, new SAXSource(new InputSource(new StringReader(xsl_include))), |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
326 |
new StreamSource(new StringReader(xml_xsl)), null}, |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
327 |
}; |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
328 |
} |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
329 |
|
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
330 |
/* |
38818
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
331 |
* @bug 8150187 |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
332 |
* NPE is expected if the systemId is null. The specification for systemId |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
333 |
* is as follows: |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
334 |
* A system identifier is required on all external entities. XML |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
335 |
* requires a system identifier on all external entities, so this value is |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
336 |
* always specified. |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
337 |
*/ |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
338 |
@Test(expectedExceptions = NullPointerException.class) |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
339 |
public void sysIdCantBeNull() { |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
340 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults()); |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
341 |
InputSource is = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", null); |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
342 |
} |
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
343 |
|
57f451f8c235
8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents:
38497
diff
changeset
|
344 |
/* |
38497 | 345 |
* @bug 8156845 |
346 |
* Verifies that an URI reference with a urn:publicid is correctly resolved |
|
347 |
* with an uri entry with a publicId. |
|
348 |
* |
|
349 |
* @param expectedFile is not used in this test, it's kept since we're |
|
350 |
* copying the JCK test and its dataProvider. This test may be reused for |
|
351 |
* other cases in that test. |
|
352 |
*/ |
|
353 |
@Test(dataProvider = "resolveUri") |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
354 |
public void testMatch1(String cFile, String href, String expectedFile, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
355 |
String expectedUri, String msg) throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
356 |
URI catalogFile = getClass().getResource(cFile).toURI(); |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
357 |
CatalogResolver cur = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); |
38497 | 358 |
Source source = cur.resolve(href, null); |
359 |
Assert.assertNotNull(source, "Source returned is null"); |
|
360 |
Assert.assertEquals(expectedUri, source.getSystemId(), msg); |
|
361 |
} |
|
362 |
||
363 |
/* |
|
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
364 |
* @bug 8154220 |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
365 |
* Verifies that the file input is validated properly. Valid input includes |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
366 |
* multiple file paths separated by semicolon. |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
367 |
*/ |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
368 |
@Test(dataProvider = "hierarchyOfCatFilesData") |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
369 |
public void hierarchyOfCatFiles2(String systemId, String expectedUri) { |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
370 |
String file1 = getClass().getResource("first_cat.xml").toExternalForm(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
371 |
String file2 = getClass().getResource("second_cat.xml").toExternalForm(); |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
372 |
String files = file1 + ";" + file2; |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
373 |
|
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
374 |
try { |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
375 |
setSystemProperty(KEY_FILES, files); |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
376 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults()); |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
377 |
String sysId = catalogResolver.resolveEntity(null, systemId).getSystemId(); |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
378 |
Assert.assertEquals(sysId, Paths.get(filepath + expectedUri).toUri().toString().replace("///", "/"), |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
379 |
"System ID match not right"); |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
380 |
} finally { |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
381 |
clearSystemProperty(KEY_FILES); |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
382 |
} |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
383 |
|
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
384 |
} |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
385 |
|
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
386 |
/* |
37384
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
387 |
* @bug 8152527 |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
388 |
* This test is the same as the JDK test ResolveEntityTests:testMatch1. |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
389 |
* Verifies that the CatalogResolver resolves a publicId and/or systemId as |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
390 |
* expected. |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
391 |
*/ |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
392 |
@Test(dataProvider = "resolveEntity") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
393 |
public void testMatch1(String cfile, String prefer, String sysId, String pubId, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
394 |
String expectedUri, String expectedFile, String msg) throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
395 |
URI catalogFile = getClass().getResource(cfile).toURI(); |
37384
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
396 |
CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build(); |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
397 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver(features, catalogFile); |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
398 |
InputSource is = catalogResolver.resolveEntity(pubId, sysId); |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
399 |
Assert.assertNotNull(is, msg); |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
400 |
String expected = (expectedUri == null) ? expectedFile : expectedUri; |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
401 |
Assert.assertEquals(expected, is.getSystemId(), msg); |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
402 |
} |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
403 |
|
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
404 |
/* |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
405 |
* @bug 8151162 |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
406 |
* Verifies that the Catalog matches specified publicId or systemId and returns |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
407 |
* results as expected. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
408 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
409 |
@Test(dataProvider = "matchWithPrefer") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
410 |
public void matchWithPrefer(String prefer, String cfile, String publicId, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
411 |
String systemId, String expected) throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
412 |
URI catalogFile = getClass().getResource(cfile).toURI(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
413 |
Catalog c = CatalogManager.catalog( |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
414 |
CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build(), |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
415 |
catalogFile); |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
416 |
String result; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
417 |
if (publicId != null && publicId.length() > 0) { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
418 |
result = c.matchPublic(publicId); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
419 |
} else { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
420 |
result = c.matchSystem(systemId); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
421 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
422 |
Assert.assertEquals(expected, result); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
423 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
424 |
|
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
425 |
/* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
426 |
* @bug 8151162 |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
427 |
* Verifies that the CatalogResolver resolves specified publicId or systemId |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
428 |
* in accordance with the prefer setting. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
429 |
* prefer "system": resolves with a system entry. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
430 |
* Exception: use the public entry when the catalog contains |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
431 |
* only public entry and only publicId is specified. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
432 |
* prefer "public": attempts to resolve with a system entry; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
433 |
* attempts to resolve with a public entry if no matching |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
434 |
* system entry is found. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
435 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
436 |
@Test(dataProvider = "resolveWithPrefer") |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
437 |
public void resolveWithPrefer(String prefer, String cfile, String publicId, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
438 |
String systemId, String expected) throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
439 |
URI catalogFile = getClass().getResource(cfile).toURI(); |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
440 |
CatalogFeatures f = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).with(CatalogFeatures.Feature.RESOLVE, "ignore").build(); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
441 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver(f, catalogFile); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
442 |
String result = catalogResolver.resolveEntity(publicId, systemId).getSystemId(); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
443 |
Assert.assertEquals(expected, result); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
444 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
445 |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
446 |
/** |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
447 |
* @bug 8150969 |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
448 |
* Verifies that the defer attribute set in the catalog file takes precedence |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
449 |
* over other settings, in which case, whether next and delegate Catalogs will |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
450 |
* be loaded is determined by the defer attribute. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
451 |
*/ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
452 |
@Test(dataProvider = "invalidAltCatalogs", expectedExceptions = CatalogException.class) |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
453 |
public void testDeferAltCatalogs(String file) throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
454 |
URI catalogFile = getClass().getResource(file).toURI(); |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
455 |
CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "true").build(); |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
456 |
/* |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
457 |
Since the defer attribute is set to false in the specified catalog file, |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
458 |
the parent catalog will try to load the alt catalog, which will fail |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
459 |
since it points to an invalid catalog. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
460 |
*/ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
461 |
Catalog catalog = CatalogManager.catalog(features, catalogFile); |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
462 |
} |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
463 |
|
33542 | 464 |
|
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
465 |
/** |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
466 |
* @bug 8146237 |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
467 |
* PREFER from Features API taking precedence over catalog file |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
468 |
*/ |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
469 |
@Test |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
470 |
public void testJDK8146237() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
471 |
URI catalogFile = getClass().getResource("JDK8146237_catalog.xml").toURI(); |
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
472 |
|
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
473 |
try { |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
474 |
CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, "system").build(); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
475 |
Catalog catalog = CatalogManager.catalog(features, catalogFile); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
476 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver(catalog); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
477 |
String actualSystemId = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", "http://www.oracle.com/alt1sys.dtd").getSystemId(); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
478 |
Assert.assertTrue(actualSystemId.contains("dummy.dtd"), "Resulting id should contain dummy.dtd, indicating a match by publicId"); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
479 |
|
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
480 |
} catch (Exception e) { |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
481 |
Assert.fail(e.getMessage()); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
482 |
} |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
483 |
} |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
484 |
|
33542 | 485 |
/* |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
486 |
@bug 8146606 |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
487 |
Verifies that the resulting systemId does not contain duplicate slashes |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
488 |
*/ |
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
489 |
@Test |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
490 |
public void testRewriteSystem() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
491 |
URI catalog = getClass().getResource("rewriteCatalog.xml").toURI(); |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
492 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
493 |
try { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
494 |
CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
495 |
String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId(); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
496 |
Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes"); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
497 |
} catch (Exception e) { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
498 |
Assert.fail(e.getMessage()); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
499 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
500 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
501 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
502 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
503 |
/* |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
504 |
@bug 8146606 |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
505 |
Verifies that the resulting systemId does not contain duplicate slashes |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
506 |
*/ |
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
507 |
@Test |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
508 |
public void testRewriteUri() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
509 |
URI catalog = getClass().getResource("rewriteCatalog.xml").toURI(); |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
510 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
511 |
try { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
512 |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
513 |
CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
514 |
String actualSystemId = resolver.resolve("http://remote.com/import/import.xsl", null).getSystemId(); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
515 |
Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes"); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
516 |
} catch (Exception e) { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
517 |
Assert.fail(e.getMessage()); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
518 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
519 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
520 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
521 |
/* |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
522 |
@bug 8144966 |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
523 |
Verifies that passing null as CatalogFeatures will result in a NPE. |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
524 |
*/ |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
525 |
@Test(expectedExceptions = NullPointerException.class) |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
526 |
public void testFeatureNull() { |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
527 |
CatalogResolver resolver = CatalogManager.catalogResolver(null, null); |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
528 |
|
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
529 |
} |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
530 |
|
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
531 |
/* |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
532 |
@bug 8144966 |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
533 |
Verifies that passing null as the URI will result in a NPE. |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
534 |
*/ |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
535 |
@Test(expectedExceptions = NullPointerException.class) |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
536 |
public void testPathNull() { |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
537 |
URI uri = null; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
538 |
CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), uri); |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
539 |
} |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
540 |
|
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
541 |
/* |
33542 | 542 |
Tests basic catalog feature by using a CatalogResolver instance to |
543 |
resolve a DTD reference to a locally specified DTD file. If the resolution |
|
544 |
is successful, the Handler shall return the value of the entity reference |
|
545 |
that matches the expected value. |
|
546 |
*/ |
|
547 |
@Test(dataProvider = "catalog") |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
548 |
public void testCatalogResolver(String test, String expected, String catalogFile, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
549 |
String xml, SAXParser saxParser) throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
550 |
URI catalog = null; |
33542 | 551 |
if (catalogFile != null) { |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
552 |
catalog = getClass().getResource(catalogFile).toURI(); |
33542 | 553 |
} |
554 |
String url = getClass().getResource(xml).getFile(); |
|
555 |
try { |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
556 |
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); |
33542 | 557 |
XMLReader reader = saxParser.getXMLReader(); |
558 |
reader.setEntityResolver(cr); |
|
559 |
MyHandler handler = new MyHandler(saxParser); |
|
560 |
reader.setContentHandler(handler); |
|
561 |
reader.parse(url); |
|
562 |
System.out.println(test + ": expected [" + expected + "] <> actual [" + handler.getResult() + "]"); |
|
563 |
Assert.assertEquals(handler.getResult(), expected); |
|
564 |
} catch (SAXException | IOException e) { |
|
565 |
Assert.fail(e.getMessage()); |
|
566 |
} |
|
567 |
} |
|
568 |
||
569 |
/* |
|
570 |
Verifies that when there's no match, in this case only an invalid |
|
571 |
catalog is provided, the resolver will throw an exception by default. |
|
572 |
*/ |
|
573 |
@Test |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
574 |
public void testInvalidCatalog() throws Exception { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
575 |
URI catalog = getClass().getResource("catalog_invalid.xml").toURI(); |
33542 | 576 |
|
577 |
String test = "testInvalidCatalog"; |
|
578 |
try { |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
579 |
CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); |
33542 | 580 |
String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId(); |
581 |
} catch (Exception e) { |
|
582 |
String msg = e.getMessage(); |
|
583 |
if (msg != null) { |
|
584 |
if (msg.contains("No match found for publicId")) { |
|
585 |
Assert.assertEquals(msg, "No match found for publicId 'null' and systemId 'http://remote/xml/dtd/sys/alice/docAlice.dtd'."); |
|
586 |
System.out.println(test + ": expected [No match found for publicId 'null' and systemId 'http://remote/xml/dtd/sys/alice/docAlice.dtd'.]"); |
|
587 |
System.out.println("actual [" + msg + "]"); |
|
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
/* |
|
594 |
Verifies that if resolve is "ignore", an empty InputSource will be returned |
|
595 |
when there's no match. The systemId is then null. |
|
596 |
*/ |
|
597 |
@Test |
|
598 |
public void testIgnoreInvalidCatalog() { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
599 |
String catalog = getClass().getResource("catalog_invalid.xml").toExternalForm(); |
33542 | 600 |
CatalogFeatures f = CatalogFeatures.builder() |
601 |
.with(Feature.FILES, catalog) |
|
602 |
.with(Feature.PREFER, "public") |
|
603 |
.with(Feature.DEFER, "true") |
|
604 |
.with(Feature.RESOLVE, "ignore") |
|
605 |
.build(); |
|
606 |
||
607 |
String test = "testInvalidCatalog"; |
|
608 |
try { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
41847
diff
changeset
|
609 |
CatalogResolver resolver = CatalogManager.catalogResolver(f); |
33542 | 610 |
String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId(); |
611 |
System.out.println("testIgnoreInvalidCatalog: expected [null]"); |
|
612 |
System.out.println("testIgnoreInvalidCatalog: expected [null]"); |
|
613 |
System.out.println("actual [" + actualSystemId + "]"); |
|
614 |
Assert.assertEquals(actualSystemId, null); |
|
615 |
} catch (Exception e) { |
|
616 |
Assert.fail(e.getMessage()); |
|
617 |
} |
|
618 |
} |
|
619 |
||
38497 | 620 |
|
621 |
/* |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
40223
diff
changeset
|
622 |
DataProvider: used to verify CatalogResolver's resolve function. |
38497 | 623 |
Data columns: |
624 |
catalog, uri or publicId, expectedFile, expectedUri, msg |
|
625 |
||
626 |
This DataProvider is copied from JCK ResolveTests' dataMatch1 |
|
627 |
*/ |
|
628 |
@DataProvider(name = "resolveUri") |
|
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
629 |
public Object[][] getDataForUriResolver() { |
38497 | 630 |
return new Object[][]{ |
631 |
{"uri.xml", "urn:publicid:-:Acme,+Inc.:DTD+Book+Version+1.0", null, "http://local/base/dtd/book.dtd", "Uri in publicId namespace is incorrectly unwrapped"}, |
|
632 |
}; |
|
633 |
} |
|
634 |
||
37384
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
635 |
/* |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
636 |
DataProvider: used to verify hierarchical catalogs. Refer to JCK test |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
637 |
hierarchyOfCatFiles2. |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
638 |
*/ |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
639 |
@DataProvider(name = "hierarchyOfCatFilesData") |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
640 |
public Object[][] getHierarchyOfCatFilesData() { |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
641 |
return new Object[][]{ |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
642 |
{"http://www.oracle.com/sequence.dtd", "first.dtd"}, |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
643 |
{"http://www.oracle.com/sequence_next.dtd", "next.dtd"}, |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
644 |
{"http://www.oracle.com/sequence_second.dtd", "second.dtd"} |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
645 |
}; |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
646 |
} |
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
647 |
|
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
648 |
/* |
37384
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
649 |
DataProvider: used to verify CatalogResolver's resolveEntity function. |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
650 |
Data columns: |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
651 |
catalog, prefer, systemId, publicId, expectedUri, expectedFile, msg |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
652 |
*/ |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
653 |
@DataProvider(name = "resolveEntity") |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
654 |
public Object[][] getDataForMatchingBothIds() { |
37384
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
655 |
String expected = "http://www.groupxmlbase.com/dtds/rewrite.dtd"; |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
656 |
return new Object[][]{ |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
657 |
{"rewriteSystem_id.xml", "system", "http://www.sys00test.com/rewrite.dtd", "PUB-404", expected, expected, "Relative rewriteSystem with xml:base at group level failed"}, |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
658 |
}; |
04a4a89d81b9
8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents:
37382
diff
changeset
|
659 |
} |
37737
5b1ec476d3e7
8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents:
37384
diff
changeset
|
660 |
|
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
661 |
static String id = "http://openjdk.java.net/xml/catalog/dtd/system.dtd"; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
662 |
/* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
663 |
DataProvider: used to verify how prefer settings affect the result of the |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
664 |
Catalog's matching operation. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
665 |
Data columns: |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
666 |
prefer, catalog, publicId, systemId, expected result |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
667 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
668 |
@DataProvider(name = "matchWithPrefer") |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
669 |
public Object[][] getDataForMatch() { |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
670 |
return new Object[][]{ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
671 |
{"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
672 |
{"public", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
673 |
{"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
674 |
{"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
675 |
{"system", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
676 |
{"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
677 |
{"public", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
678 |
{"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
679 |
{"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
680 |
{"system", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
681 |
{"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
682 |
{"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
683 |
}; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
684 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
685 |
|
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
686 |
/* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
687 |
DataProvider: used to verify how prefer settings affect the result of the |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
688 |
CatalogResolver's resolution operation. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
689 |
Data columns: |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
690 |
prefer, catalog, publicId, systemId, expected result |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
691 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
692 |
@DataProvider(name = "resolveWithPrefer") |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
693 |
public Object[][] getDataForResolve() { |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
694 |
return new Object[][]{ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
695 |
{"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
696 |
{"system", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
697 |
{"system", "pubOnly.xml", id, id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
698 |
{"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
699 |
{"public", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
700 |
{"public", "pubOnly.xml", id, id, "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
701 |
{"system", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
702 |
{"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
703 |
{"system", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
704 |
{"public", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
705 |
{"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
706 |
{"public", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
707 |
{"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
708 |
{"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
709 |
{"system", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
710 |
{"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
711 |
{"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
712 |
{"public", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
713 |
}; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
714 |
} |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
715 |
/* |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
716 |
DataProvider: catalogs that contain invalid next or delegate catalogs. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
717 |
The defer attribute is set to false. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
718 |
*/ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
719 |
@DataProvider(name = "invalidAltCatalogs") |
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
720 |
public Object[][] getCatalogs() { |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
721 |
return new Object[][]{ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
722 |
{"defer_false_2.xml"}, |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
723 |
{"defer_del_false.xml"} |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
724 |
}; |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
725 |
} |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
726 |
|
33542 | 727 |
|
728 |
/* |
|
729 |
DataProvider: provides test name, expected string, the catalog, and XML |
|
730 |
document. |
|
731 |
*/ |
|
732 |
@DataProvider(name = "catalog") |
|
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
733 |
public Object[][] getCatalog() { |
33542 | 734 |
return new Object[][]{ |
735 |
{"testSystem", "Test system entry", "catalog.xml", "system.xml", getParser()}, |
|
736 |
{"testRewriteSystem", "Test rewritesystem entry", "catalog.xml", "rewritesystem.xml", getParser()}, |
|
737 |
{"testRewriteSystem1", "Test rewritesystem entry", "catalog.xml", "rewritesystem1.xml", getParser()}, |
|
738 |
{"testSystemSuffix", "Test systemsuffix entry", "catalog.xml", "systemsuffix.xml", getParser()}, |
|
739 |
{"testDelegateSystem", "Test delegatesystem entry", "catalog.xml", "delegatesystem.xml", getParser()}, |
|
740 |
{"testPublic", "Test public entry", "catalog.xml", "public.xml", getParser()}, |
|
741 |
{"testDelegatePublic", "Test delegatepublic entry", "catalog.xml", "delegatepublic.xml", getParser()}, |
|
742 |
}; |
|
743 |
} |
|
744 |
||
745 |
SAXParser getParser() { |
|
746 |
SAXParser saxParser = null; |
|
747 |
try { |
|
748 |
SAXParserFactory factory = SAXParserFactory.newInstance(); |
|
749 |
factory.setNamespaceAware(true); |
|
750 |
saxParser = factory.newSAXParser(); |
|
751 |
} catch (ParserConfigurationException | SAXException e) { |
|
752 |
} |
|
753 |
||
754 |
return saxParser; |
|
755 |
} |
|
756 |
||
757 |
/** |
|
758 |
* SAX handler |
|
759 |
*/ |
|
760 |
public class MyHandler extends DefaultHandler2 implements ErrorHandler { |
|
761 |
||
762 |
StringBuilder textContent = new StringBuilder(); |
|
763 |
SAXParser saxParser; |
|
764 |
||
765 |
MyHandler(SAXParser saxParser) { |
|
766 |
textContent.setLength(0); |
|
767 |
this.saxParser = saxParser; |
|
768 |
} |
|
769 |
||
770 |
String getResult() { |
|
771 |
return textContent.toString(); |
|
772 |
} |
|
773 |
||
774 |
@Override |
|
40223
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
775 |
public void startElement(String uri, String localName, String qName, Attributes attributes) |
64662417aa2d
8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents:
38818
diff
changeset
|
776 |
throws SAXException { |
33542 | 777 |
textContent.delete(0, textContent.length()); |
778 |
try { |
|
779 |
System.out.println("Element: " + uri + ":" + localName + " " + qName); |
|
780 |
} catch (Exception e) { |
|
781 |
throw new SAXException(e); |
|
782 |
} |
|
783 |
||
784 |
} |
|
785 |
||
786 |
@Override |
|
787 |
public void characters(char ch[], int start, int length) throws SAXException { |
|
788 |
textContent.append(ch, start, length); |
|
789 |
} |
|
790 |
} |
|
791 |
} |