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.namespace.QName; 27 import javax.xml.stream.EventFilter; 28 import javax.xml.stream.XMLEventReader; 29 import javax.xml.stream.XMLInputFactory; 30 import javax.xml.stream.XMLStreamException; 31 import javax.xml.stream.events.XMLEvent; 32 33 import org.testng.Assert; 34 import org.testng.annotations.Test; 35 36 /* 37 * @bug 6976938 38 * @summary Test StAX parser won't throw StackOverflowError while reading valid XML file, in case the text content of an XML element contains many lines like "< ... >". 39 */ 40 public class Bug6976938Test { 41 42 private static final String INPUT_FILE = "Bug6976938.xml"; 43 44 public static final String VF_GENERIC_TT_NAMESPACE = "http://www.vodafone.com/oss/xml/TroubleTicket"; 45 46 public static final QName ATTACHMENT_NAME = new QName(VF_GENERIC_TT_NAMESPACE, "attachment"); 47 48 @Test 49 public void testEventReader() { 50 XMLInputFactory xif = XMLInputFactory.newInstance(); 51 xif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); 52 eventReaderTest(xif); 53 } 54 55 @Test 56 public void testEventReader1() { 57 XMLInputFactory xif = XMLInputFactory.newInstance(); 58 eventReaderTest(xif); 59 } 60 61 public void eventReaderTest(XMLInputFactory xif) { 62 XMLEventReader eventReader = null; 63 try { 64 eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE)); 65 XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() { 66 public boolean accept(XMLEvent event) { 67 if (!event.isStartElement()) { 68 return false; 69 } 70 QName elementQName = event.asStartElement().getName(); 71 if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment")) 72 && elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) { 73 return true; 74 } 75 return false; 76 } 77 }); 78 if (filteredEventReader.hasNext()) { 79 System.out.println("containsAttachments() returns true"); 80 } 81 } catch (Exception e) { 82 e.printStackTrace(); 83 Assert.fail(e.getMessage()); 84 85 } finally { 86 if (eventReader != null) { 87 try { 88 eventReader.close(); 89 } catch (XMLStreamException xse) { 90 // Ignored by intention 91 } 92 } 93 } 94 } 95 96 }