# HG changeset patch # User joehw # Date 1388984577 28800 # Node ID ff3bfe024b5fd13ec944ad180202869058246c8e # Parent 918412102df384d5627a7d3221618cebba60edbc 8027359: XML parser returns incorrect parsing results Reviewed-by: lancea diff -r 918412102df3 -r ff3bfe024b5f jdk/test/javax/xml/jaxp/parsers/8027359/XML11EntityScannerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/xml/jaxp/parsers/8027359/XML11EntityScannerTest.java Sun Jan 05 21:02:57 2014 -0800 @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8027359 + * @summary test that the XML11EntityScanner refreshes cache when it loads new data + * @run main XML11EntityScannerTest + */ + +import java.io.*; +import java.util.regex.Pattern; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.*; + + +/** + * XML11EntityScanner functions similarly as XMLEntityScanner in handling data + * cache + */ +public class XML11EntityScannerTest { + static final String rawXML = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + /** + * main method. + * + * @param args Standard args. + */ + public static void main(String[] args) { + try { + final Document xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(rawXML.getBytes("UTF-8"))); + final Element identityElement = (Element) xmlDoc.getElementsByTagName("Identity").item(0); + final Element trustListElement = (Element) identityElement.getElementsByTagName("TrustList").item(0); + final NodeList trustList = trustListElement.getElementsByTagName("Trust"); + final Pattern keyPattern = Pattern.compile("USK@[%,~" + "*-_./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" + "]+"); + for (int i = 0; i < trustList.getLength(); ++i) { + Element trustElement = (Element) trustList.item(i); + final String identity = trustElement.getAttribute("Identity"); + if (!keyPattern.matcher(identity).matches()) { + throw new RuntimeException("Parsing failure: Instead of USK URI I got: " + identity); + } + } + } catch (Exception ex) { + throw new RuntimeException(ex.getMessage()); + } + } + +}