< prev index next >

test/javax/xml/jaxp/unittest/transform/StAXSourceTest.java

Print this page


   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 transform;
  25 
  26 import java.io.StringReader;
  27 import java.io.StringWriter;
  28 
  29 import javax.xml.stream.XMLEventReader;
  30 import javax.xml.stream.XMLEventWriter;
  31 import javax.xml.stream.XMLInputFactory;
  32 import javax.xml.stream.XMLOutputFactory;
  33 import javax.xml.stream.XMLStreamException;
  34 import javax.xml.transform.Transformer;
  35 import javax.xml.transform.TransformerConfigurationException;
  36 import javax.xml.transform.TransformerException;
  37 import javax.xml.transform.TransformerFactory;
  38 import javax.xml.transform.dom.DOMResult;
  39 import javax.xml.transform.stax.StAXResult;
  40 import javax.xml.transform.stax.StAXSource;
  41 
  42 import org.testng.Assert;

  43 import org.testng.annotations.Test;
  44 
  45 /*
  46  * @summary Test parsing from StAXSource.
  47  */

  48 public class StAXSourceTest {
  49 
  50     @Test
  51     public final void testStAXSource() throws XMLStreamException {
  52         XMLInputFactory ifactory = XMLInputFactory.newInstance();
  53         XMLOutputFactory ofactory = XMLOutputFactory.newInstance();
  54 
  55         String xslStylesheet = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>"
  56                 + "  <xsl:output method='xml' encoding='utf-8' indent='no'/>" + "  <xsl:preserve-space elements='*'/>" + "  <xsl:template match='*'>"
  57                 + "    <xsl:copy><xsl:copy-of select='@*'/><xsl:apply-templates/></xsl:copy>" + "  </xsl:template>"
  58                 + "  <xsl:template match='comment()|processing-instruction()|text()'>" + "    <xsl:copy/>" + "  </xsl:template>" + "</xsl:stylesheet>";
  59         StringReader xslStringReader = new StringReader(xslStylesheet);
  60         StringReader xmlStringReader = new StringReader(xslStylesheet); // identity
  61                                                                         // on
  62                                                                         // itself,
  63         StringWriter xmlStringWriter = new StringWriter();
  64 
  65         XMLEventReader styleReader = ifactory.createXMLEventReader(xslStringReader);
  66         XMLEventReader docReader = ifactory.createXMLEventReader(xmlStringReader);
  67         XMLEventWriter writer = ofactory.createXMLEventWriter(xmlStringWriter);


   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 transform;
  25 
  26 import java.io.StringReader;
  27 import java.io.StringWriter;
  28 
  29 import javax.xml.stream.XMLEventReader;
  30 import javax.xml.stream.XMLEventWriter;
  31 import javax.xml.stream.XMLInputFactory;
  32 import javax.xml.stream.XMLOutputFactory;
  33 import javax.xml.stream.XMLStreamException;
  34 import javax.xml.transform.Transformer;
  35 import javax.xml.transform.TransformerConfigurationException;
  36 import javax.xml.transform.TransformerException;
  37 import javax.xml.transform.TransformerFactory;
  38 import javax.xml.transform.dom.DOMResult;
  39 import javax.xml.transform.stax.StAXResult;
  40 import javax.xml.transform.stax.StAXSource;
  41 
  42 import org.testng.Assert;
  43 import org.testng.annotations.Listeners;
  44 import org.testng.annotations.Test;
  45 
  46 /*
  47  * @summary Test parsing from StAXSource.
  48  */
  49 @Listeners({jaxp.library.FilePolicy.class})
  50 public class StAXSourceTest {
  51 
  52     @Test
  53     public final void testStAXSource() throws XMLStreamException {
  54         XMLInputFactory ifactory = XMLInputFactory.newInstance();
  55         XMLOutputFactory ofactory = XMLOutputFactory.newInstance();
  56 
  57         String xslStylesheet = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>"
  58                 + "  <xsl:output method='xml' encoding='utf-8' indent='no'/>" + "  <xsl:preserve-space elements='*'/>" + "  <xsl:template match='*'>"
  59                 + "    <xsl:copy><xsl:copy-of select='@*'/><xsl:apply-templates/></xsl:copy>" + "  </xsl:template>"
  60                 + "  <xsl:template match='comment()|processing-instruction()|text()'>" + "    <xsl:copy/>" + "  </xsl:template>" + "</xsl:stylesheet>";
  61         StringReader xslStringReader = new StringReader(xslStylesheet);
  62         StringReader xmlStringReader = new StringReader(xslStylesheet); // identity
  63                                                                         // on
  64                                                                         // itself,
  65         StringWriter xmlStringWriter = new StringWriter();
  66 
  67         XMLEventReader styleReader = ifactory.createXMLEventReader(xslStringReader);
  68         XMLEventReader docReader = ifactory.createXMLEventReader(xmlStringReader);
  69         XMLEventWriter writer = ofactory.createXMLEventWriter(xmlStringWriter);


< prev index next >