author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57545 | 550a1a6ca596 |
permissions | -rw-r--r-- |
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
1 |
/* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
4 |
* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
8 |
* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
13 |
* accompanied this code). |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
14 |
* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
18 |
* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
21 |
* questions. |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
22 |
*/ |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
23 |
|
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
24 |
package validation; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
25 |
|
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
26 |
|
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
27 |
import java.io.File; |
57545
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
28 |
import java.io.FileInputStream; |
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
29 |
import javax.xml.XMLConstants; |
57545
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
30 |
import javax.xml.parsers.SAXParserFactory; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
31 |
import javax.xml.stream.XMLInputFactory; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
32 |
import javax.xml.stream.XMLStreamReader; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
33 |
import javax.xml.stream.events.XMLEvent; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
34 |
import javax.xml.transform.Source; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
35 |
import javax.xml.transform.sax.SAXSource; |
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
36 |
import javax.xml.transform.stream.StreamSource; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
37 |
import javax.xml.validation.Schema; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
38 |
import javax.xml.validation.SchemaFactory; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
39 |
import javax.xml.validation.Validator; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
40 |
import org.testng.annotations.DataProvider; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
41 |
import org.testng.annotations.Listeners; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
42 |
import org.testng.annotations.Test; |
57545
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
43 |
import org.xml.sax.Attributes; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
44 |
import org.xml.sax.InputSource; |
55688
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
45 |
import org.xml.sax.SAXException; |
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
46 |
import org.xml.sax.SAXParseException; |
57545
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
47 |
import org.xml.sax.XMLFilter; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
48 |
import org.xml.sax.helpers.XMLFilterImpl; |
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
49 |
|
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
50 |
/* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
51 |
* @test |
55688
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
52 |
* @bug 8220818 8176447 |
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
53 |
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
54 |
* @run testng/othervm validation.ValidationTest |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
55 |
* @summary Runs validations with schemas and sources |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
56 |
*/ |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
57 |
@Listeners({jaxp.library.FilePolicy.class}) |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
58 |
public class ValidationTest { |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
59 |
static final String FILE_PATH = "files/"; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
60 |
/* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
61 |
DataProvider: valid xml |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
62 |
*/ |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
63 |
@DataProvider(name = "valid") |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
64 |
Object[][] getValid() { |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
65 |
return new Object[][]{ |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
66 |
{"JDK8220818a.xsd", "JDK8220818a_Valid.xml"}, |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
67 |
{"JDK8220818a.xsd", "JDK8220818a_Valid1.xml"}, |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
68 |
{"JDK8220818b.xsd", "JDK8220818b_Valid.xml"}, |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
69 |
}; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
70 |
} |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
71 |
|
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
72 |
/* |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
73 |
DataProvider: invalid xml |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
74 |
*/ |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
75 |
@DataProvider(name = "invalid") |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
76 |
Object[][] getInvalid() { |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
77 |
return new Object[][]{ |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
78 |
{"JDK8220818a.xsd", "JDK8220818a_Invalid.xml"}, |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
79 |
{"JDK8220818b.xsd", "JDK8220818b_Invalid.xml"}, |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
80 |
}; |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
81 |
} |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
82 |
|
55688
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
83 |
/* |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
84 |
DataProvider: uniqueness |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
85 |
*/ |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
86 |
@DataProvider(name = "uniqueness") |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
87 |
Object[][] getUniqueData() { |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
88 |
return new Object[][]{ |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
89 |
{"JDK8176447a.xsd", "JDK8176447a.xml"}, |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
90 |
{"JDK8176447b.xsd", "JDK8176447b.xml"}, |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
91 |
}; |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
92 |
} |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
93 |
|
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
94 |
@Test(dataProvider = "invalid", expectedExceptions = SAXParseException.class) |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
95 |
public void testValidateRefType(String xsd, String xml) throws Exception { |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
96 |
validate(xsd, xml); |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
97 |
} |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
98 |
|
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
99 |
@Test(dataProvider = "valid") |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
100 |
public void testValidateRefType1(String xsd, String xml) throws Exception { |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
101 |
validate(xsd, xml); |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
102 |
} |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
103 |
|
55688
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
104 |
/** |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
105 |
* @bug 8176447 |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
106 |
* Verifies that the uniqueness constraint is checked. |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
107 |
* @param xsd the XSD |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
108 |
* @param xml the XML |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
109 |
* @throws Exception expected when the uniqueness constraint is validated |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
110 |
* correctly. |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
111 |
*/ |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
112 |
@Test(dataProvider = "uniqueness", expectedExceptions = SAXException.class) |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
113 |
public void testUnique(String xsd, String xml) throws Exception { |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
114 |
validate(xsd, xml); |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
115 |
} |
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
116 |
|
57545
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
117 |
/** |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
118 |
* @bug 8068376 |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
119 |
* Verifies that validation performs normally with externally provided string |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
120 |
* parameters. |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
121 |
* @throws Exception if the test fails |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
122 |
*/ |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
123 |
@Test |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
124 |
public void testJDK8068376() throws Exception { |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
125 |
|
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
126 |
String xsdFile = getClass().getResource(FILE_PATH + "JDK8068376.xsd").getFile(); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
127 |
String xmlFile = getClass().getResource(FILE_PATH + "JDK8068376.xml").getFile(); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
128 |
String targetNamespace = getTargetNamespace(xsdFile); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
129 |
|
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
130 |
XMLFilter namespaceFilter = new XMLFilterImpl(SAXParserFactory.newDefaultNSInstance().newSAXParser().getXMLReader()) { |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
131 |
@Override |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
132 |
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
133 |
uri = targetNamespace; // overwriting the uri with our own choice |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
134 |
super.startElement(uri, localName, qName, atts); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
135 |
} |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
136 |
}; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
137 |
|
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
138 |
Source xmlSource = new SAXSource(namespaceFilter, new InputSource(xmlFile)); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
139 |
Source schemaSource = new StreamSource(xsdFile); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
140 |
validate(schemaSource, xmlSource); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
141 |
|
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
142 |
} |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
143 |
|
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
144 |
private static String getTargetNamespace(String xsdFile) throws Exception { |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
145 |
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(xsdFile)); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
146 |
while (reader.hasNext()) { |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
147 |
int event = reader.next(); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
148 |
|
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
149 |
// Get the root element's "targetNamespace" attribute |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
150 |
if (event == XMLEvent.START_ELEMENT) { |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
151 |
// validation fails before patch |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
152 |
String value = reader.getAttributeValue(null, "targetNamespace"); // fails validation |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
153 |
// validation passes due to a reference comparison in the original code |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
154 |
// String value = "mynamespace"; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
155 |
return value; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
156 |
} |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
157 |
} |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
158 |
return null; |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
159 |
} |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
160 |
|
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
161 |
private void validate(String xsd, String xml) throws Exception { |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
162 |
final SchemaFactory schemaFactory = SchemaFactory.newInstance( |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
163 |
XMLConstants.W3C_XML_SCHEMA_NS_URI); |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
164 |
final Schema schema = schemaFactory.newSchema( |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
165 |
new File(getClass().getResource(FILE_PATH + xsd).getFile())); |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
166 |
final Validator validator = schema.newValidator(); |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
167 |
validator.validate(new StreamSource( |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
168 |
new File(getClass().getResource(FILE_PATH + xml).getFile()))); |
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
169 |
} |
55688
0e1bc587472c
8176447: javax.xml.validation.Validator validates incorrectly on uniqueness constraint
joehw
parents:
54672
diff
changeset
|
170 |
|
57545
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
171 |
private void validate(Source xsd, Source xml) throws Exception { |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
172 |
final SchemaFactory schemaFactory = SchemaFactory.newInstance( |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
173 |
XMLConstants.W3C_XML_SCHEMA_NS_URI); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
174 |
final Schema schema = schemaFactory.newSchema(xsd); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
175 |
final Validator validator = schema.newValidator(); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
176 |
validator.validate(xml); |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
177 |
} |
550a1a6ca596
8068376: Validator fails valid XML files due to String == in XSD validator code
joehw
parents:
55688
diff
changeset
|
178 |
|
54672
a43d6467317d
8220818: Validator does not find missing match for keyref error
joehw
parents:
diff
changeset
|
179 |
} |