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 stream; 25 26 import javax.xml.stream.XMLInputFactory; 27 import javax.xml.stream.XMLStreamConstants; 28 import javax.xml.stream.XMLStreamReader; 29 30 import org.testng.Assert; 31 import org.testng.annotations.Test; 32 33 /* 34 * @bug 6509774 35 * @summary Test Property javax.xml.stream.supportDTD, DTD events are now returned even if supportDTD=false. 36 */ 37 public class Bug6509774 { 38 39 @Test 40 public void test0() { 41 42 try { 43 44 XMLInputFactory xif = XMLInputFactory.newInstance(); 45 46 xif.setProperty("javax.xml.stream.supportDTD", Boolean.TRUE); 47 48 XMLStreamReader xsr = xif.createXMLStreamReader( 49 50 getClass().getResource("sgml_Bug6509774.xml").toString(), 51 52 getClass().getResourceAsStream("sgml_Bug6509774.xml")); 53 54 Assert.assertTrue(xsr.getEventType() == XMLStreamConstants.START_DOCUMENT); 55 56 int event = xsr.next(); 57 58 // Must be a DTD event since DTDs are supported 59 60 Assert.assertTrue(event == XMLStreamConstants.DTD); 61 62 while (xsr.hasNext()) { 63 64 event = xsr.next(); 65 66 } 67 68 Assert.assertTrue(event == XMLStreamConstants.END_DOCUMENT); 69 70 xsr.close(); 71 72 } 73 74 catch (Exception e) { 75 76 Assert.fail(e.getMessage()); 77 78 } 79 80 } 81 82 @Test 83 public void test1() { 84 85 try { 86 87 XMLInputFactory xif = XMLInputFactory.newInstance(); 88 89 xif.setProperty("javax.xml.stream.supportDTD", Boolean.FALSE); 90 91 XMLStreamReader xsr = xif.createXMLStreamReader( 92 93 getClass().getResource("sgml_Bug6509774.xml").toString(), 94 95 getClass().getResourceAsStream("sgml_Bug6509774.xml")); 96 97 Assert.assertTrue(xsr.getEventType() == XMLStreamConstants.START_DOCUMENT); 98 99 int event = xsr.next(); 100 101 // Should not be a DTD event since they are ignored 102 103 Assert.assertTrue(event == XMLStreamConstants.DTD); 104 105 while (xsr.hasNext()) { 106 107 event = xsr.next(); 108 109 } 110 111 Assert.assertTrue(event == XMLStreamConstants.END_DOCUMENT); 112 113 xsr.close(); 114 115 } 116 117 catch (Exception e) { 118 119 Assert.fail(e.getMessage()); 120 121 } 122 123 } 124 125 @Test 126 public void test2() { 127 128 try { 129 130 XMLInputFactory xif = XMLInputFactory.newInstance(); 131 132 xif.setProperty("javax.xml.stream.supportDTD", Boolean.FALSE); 133 134 XMLStreamReader xsr = xif.createXMLStreamReader( 135 136 getClass().getResource("sgml-bad-systemId.xml").toString(), 137 138 getClass().getResourceAsStream("sgml-bad-systemId.xml")); 139 140 Assert.assertTrue(xsr.getEventType() == XMLStreamConstants.START_DOCUMENT); 141 142 int event = xsr.next(); 143 144 // Should not be a DTD event since they are ignored 145 146 Assert.assertTrue(event == XMLStreamConstants.DTD); 147 148 while (xsr.hasNext()) { 149 150 event = xsr.next(); 151 152 } 153 154 Assert.assertTrue(event == XMLStreamConstants.END_DOCUMENT); 155 156 xsr.close(); 157 158 } 159 160 catch (Exception e) { 161 162 // Bogus systemId in XML document should not result in exception 163 164 Assert.fail(e.getMessage()); 165 166 } 167 168 } 169 170 }