Path: blob/master/test/jdk/javax/xml/jaxp/parsers/8021148/JAXPSAXParserTest.java
41154 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 802114826* @summary test that JAXPSAXParser works even if referenced directly27* @run main/othervm JAXPSAXParserTest28*/29import java.io.StringReader;30import java.io.StringWriter;31import javax.xml.transform.Result;32import javax.xml.transform.Transformer;33import javax.xml.transform.TransformerFactory;34import javax.xml.transform.stream.StreamResult;35import javax.xml.transform.stream.StreamSource;3637/**38* test that JAXPSAXParser works even if referenced directly as39* NetBeans did. **Note that JAXPSAXParser is an internal implementation, this40* may therefore change.41*42* @author [email protected]43*/44public class JAXPSAXParserTest extends TestBase {4546public JAXPSAXParserTest(String name) {47super(name);48}4950/**51* @param args the command line arguments52*/53public static void main(String[] args) {54JAXPSAXParserTest test = new JAXPSAXParserTest("JAXP 1.5 regression");55test.setUp();56test.testTransform();57test.tearDown();58}5960public final void testTransform() {61String data =62"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"63+ "<r>\n"64+ " <e/>\n"65+ "</r>\n";66String IDENTITY_XSLT_WITH_INDENT = // #5064280 workaround67"<xsl:stylesheet version='1.0' "68+ "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' "69+ "xmlns:xalan='http://xml.apache.org/xslt' "70+ "exclude-result-prefixes='xalan'>"71+ "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>"72+ "<xsl:template match='@*|node()'>"73+ "<xsl:copy>"74+ "<xsl:apply-templates select='@*|node()'/>"75+ "</xsl:copy>"76+ "</xsl:template>"77+ "</xsl:stylesheet>";78try {79//Skip the default XMLReader80System.setProperty("org.xml.sax.driver", "com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser");8182StringWriter sw = new StringWriter();83TransformerFactory tf = TransformerFactory.newInstance();84Transformer t = tf.newTransformer(new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));85Result result = new StreamResult(sw);86t.transform(new StreamSource(new StringReader(data)), result);87success("JAXPSAXParserTest passed");88} catch (Exception e) {89/**90* JAXPSAXParser throws NullPointerException since the jaxp 1.5 security91* manager is not initialized when JAXPSAXParser is instantiated using92* the default constructor.93*/94fail(e.toString());95} finally {96System.clearProperty("org.xml.sax.driver");97}98}99}100101102