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