|
1 /* |
|
2 * Copyright (c) 2014, 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 org.w3c.dom; |
|
25 |
|
26 import javax.xml.parsers.DocumentBuilder; |
|
27 import javax.xml.parsers.DocumentBuilderFactory; |
|
28 |
|
29 import org.testng.Assert; |
|
30 import org.testng.annotations.Test; |
|
31 import org.w3c.dom.DOMConfiguration; |
|
32 import org.w3c.dom.DOMImplementation; |
|
33 import org.w3c.dom.DOMStringList; |
|
34 import org.w3c.dom.ls.DOMImplementationLS; |
|
35 import org.w3c.dom.ls.LSParser; |
|
36 import org.w3c.dom.ls.LSSerializer; |
|
37 |
|
38 /* |
|
39 * @bug 6339023 |
|
40 * @summary Test normalize-characters. |
|
41 */ |
|
42 public class Bug6339023 { |
|
43 |
|
44 /* |
|
45 * This test checks DOMConfiguration for DOM Level3 Load and Save |
|
46 * implementation. |
|
47 */ |
|
48 @Test |
|
49 public void testLSSerializer() { |
|
50 try { |
|
51 DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
|
52 DOMImplementation impln = parser.getDOMImplementation(); |
|
53 DOMImplementationLS lsImpln = (DOMImplementationLS) impln.getFeature("LS", "3.0"); |
|
54 LSSerializer serializer = lsImpln.createLSSerializer(); |
|
55 DOMConfiguration domConfig = serializer.getDomConfig(); |
|
56 System.out.println("DOMConfig: " + domConfig.toString()); |
|
57 Assert.assertTrue(domConfig.getParameter("normalize-characters") == null); |
|
58 System.out.println("value: " + domConfig.getParameter("normalize-characters")); |
|
59 |
|
60 DOMStringList list = domConfig.getParameterNames(); |
|
61 for (int i = 0; i < list.getLength(); i++) { |
|
62 System.out.println("Param Name: " + list.item(i)); |
|
63 Assert.assertFalse(list.item(i).equals("normalize-characters")); |
|
64 } |
|
65 |
|
66 Assert.assertFalse(domConfig.canSetParameter("normalize-characters", Boolean.FALSE)); |
|
67 Assert.assertFalse(domConfig.canSetParameter("normalize-characters", Boolean.TRUE)); |
|
68 |
|
69 try { |
|
70 domConfig.setParameter("normalize-characters", Boolean.TRUE); |
|
71 Assert.fail("Exception expected as 'normalize-characters' is not supported"); |
|
72 } catch (Exception e) { |
|
73 } |
|
74 |
|
75 try { |
|
76 domConfig.setParameter("normalize-characters", Boolean.FALSE); |
|
77 Assert.fail("Exception expected as 'normalize-characters' is not supported"); |
|
78 } catch (Exception e) { |
|
79 } |
|
80 |
|
81 } catch (Exception e) { |
|
82 e.printStackTrace(); |
|
83 Assert.fail("Exception: " + e.getMessage()); |
|
84 } |
|
85 } |
|
86 |
|
87 /* |
|
88 * This test checks DOMConfiguration for DOM Level3 Core implementation. |
|
89 */ |
|
90 @Test |
|
91 public void testLSParser() { |
|
92 try { |
|
93 DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
|
94 DOMImplementation impln = parser.getDOMImplementation(); |
|
95 DOMImplementationLS lsImpln = (DOMImplementationLS) impln.getFeature("Core", "3.0"); |
|
96 LSParser lsparser = lsImpln.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, "http://www.w3.org/2001/XMLSchema"); |
|
97 DOMConfiguration domConfig = lsparser.getDomConfig(); |
|
98 System.out.println("DOMConfig: " + domConfig.toString()); |
|
99 Assert.assertTrue(domConfig.getParameter("normalize-characters").toString().equalsIgnoreCase("false")); |
|
100 System.out.println("value: " + domConfig.getParameter("normalize-characters")); |
|
101 |
|
102 DOMStringList list = domConfig.getParameterNames(); |
|
103 boolean flag = false; |
|
104 for (int i = 0; i < list.getLength(); i++) { |
|
105 System.out.println("Param Name: " + list.item(i)); |
|
106 if (list.item(i).equals("normalize-characters")) { |
|
107 flag = true; |
|
108 break; |
|
109 } |
|
110 } |
|
111 Assert.assertTrue(flag, "'normalize-characters' doesnot exist in the list returned by domConfig.getParameterNames()"); |
|
112 |
|
113 Assert.assertTrue(domConfig.canSetParameter("normalize-characters", Boolean.FALSE)); |
|
114 Assert.assertFalse(domConfig.canSetParameter("normalize-characters", Boolean.TRUE)); |
|
115 |
|
116 try { |
|
117 domConfig.setParameter("normalize-characters", Boolean.TRUE); |
|
118 Assert.fail("Exception expected as 'normalize-characters' is not supported"); |
|
119 } catch (Exception e) { |
|
120 } |
|
121 |
|
122 try { |
|
123 domConfig.setParameter("normalize-characters", Boolean.FALSE); |
|
124 } catch (Exception e) { |
|
125 e.printStackTrace(); |
|
126 Assert.fail("Exception expected as 'normalize-characters' is not supported"); |
|
127 } |
|
128 |
|
129 } catch (Exception e) { |
|
130 e.printStackTrace(); |
|
131 Assert.fail("Exception: " + e.getMessage()); |
|
132 } |
|
133 } |
|
134 |
|
135 } |