1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
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
24 package dom;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.IOException;
28
29 import javax.xml.parsers.DocumentBuilder;
30 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.parsers.ParserConfigurationException;
32
33 import org.testng.Assert;
34 import org.testng.annotations.Test;
35 import org.w3c.dom.Document;
36 import org.w3c.dom.Element;
37 import org.xml.sax.SAXException;
38
39 /*
40 * @bug 6521260
41 * @summary Test setAttributeNS doesn't result in an unsorted internal list of attributes.
42 */
43 public class Bug6521260 {
44
45 @Test
46 public void test() throws ParserConfigurationException, SAXException, IOException {
47 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
48 factory.setNamespaceAware(true);
49 DocumentBuilder builder = factory.newDocumentBuilder();
50
51 String docStr = "<system systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'" + " uri='/cache/data/xrc36316.bin'"
52 + " xmlns:xr='urn:oasis:names:tc:entity:xmlns:xml:catalog'" + " xr:systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'"
53 + " xmlns:NS1='http://xmlresolver.org/ns/catalog'" + " NS1:time='1170267571097'/>";
54
55 ByteArrayInputStream bais = new ByteArrayInputStream(docStr.getBytes());
56
57 Document doc = builder.parse(bais);
58
59 Element root = doc.getDocumentElement();
60
61 String systemId = root.getAttribute("systemId");
62
|
1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
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
24 package dom;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.IOException;
28
29 import javax.xml.parsers.DocumentBuilder;
30 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.parsers.ParserConfigurationException;
32
33 import org.testng.Assert;
34 import org.testng.annotations.Listeners;
35 import org.testng.annotations.Test;
36 import org.w3c.dom.Document;
37 import org.w3c.dom.Element;
38 import org.xml.sax.SAXException;
39
40 /*
41 * @bug 6521260
42 * @summary Test setAttributeNS doesn't result in an unsorted internal list of attributes.
43 */
44 @Listeners({jaxp.library.BasePolicy.class})
45 public class Bug6521260 {
46
47 @Test
48 public void test() throws ParserConfigurationException, SAXException, IOException {
49 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
50 factory.setNamespaceAware(true);
51 DocumentBuilder builder = factory.newDocumentBuilder();
52
53 String docStr = "<system systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'" + " uri='/cache/data/xrc36316.bin'"
54 + " xmlns:xr='urn:oasis:names:tc:entity:xmlns:xml:catalog'" + " xr:systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'"
55 + " xmlns:NS1='http://xmlresolver.org/ns/catalog'" + " NS1:time='1170267571097'/>";
56
57 ByteArrayInputStream bais = new ByteArrayInputStream(docStr.getBytes());
58
59 Document doc = builder.parse(bais);
60
61 Element root = doc.getDocumentElement();
62
63 String systemId = root.getAttribute("systemId");
64
|