Issue2290Test.java revision 779:2b61bfcaa586
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
24package transform;
25
26import java.io.StringReader;
27import java.io.StringWriter;
28import java.util.Properties;
29
30import javax.xml.parsers.DocumentBuilder;
31import javax.xml.parsers.DocumentBuilderFactory;
32import javax.xml.transform.OutputKeys;
33import javax.xml.transform.Transformer;
34import javax.xml.transform.TransformerFactory;
35import javax.xml.transform.dom.DOMResult;
36import javax.xml.transform.dom.DOMSource;
37import javax.xml.transform.stream.StreamResult;
38import javax.xml.transform.stream.StreamSource;
39
40import org.w3c.dom.Document;
41import org.w3c.dom.DocumentFragment;
42
43import org.testng.Assert;
44import org.testng.annotations.Test;
45
46/*
47 * @summary Test XSL extension for RTF works, for https://issues.apache.org/jira/i#browse/XALANJ-2290.
48 */
49public class Issue2290Test {
50
51    @Test
52    public final void testTransform() throws Exception {
53        DocumentFragment outNode = null;
54        DocumentBuilder docBuilder = null;
55        Document outDoc = null;
56        // TransformerImpl transformer = null;
57        StringReader execReaderXML = null;
58        Properties propFormat = null;
59        StringWriter sw = null;
60
61        try {
62            // template = TransformerFactory.newInstance().newTemplates(new
63            // StreamSource("D:/Work/Apache/TestVar.xsl"));
64            // transformer = (TransformerImpl) template.newTransformer();
65            Transformer t = TransformerFactory.newInstance().newTransformer(new StreamSource(getClass().getResourceAsStream("Issue2290.xsl")));
66            System.out.print("Created Transformer");
67            execReaderXML = new StringReader("<?xml version=\"1.0\"?> <doc>Stuff</doc>");
68
69
70            docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
71            outDoc = docBuilder.newDocument();
72            outNode = outDoc.createDocumentFragment();
73            System.out.println("Created Fragment");
74            System.out.println("execute transformer.");
75            // transformer.transform(new StreamSource(execReaderXML),new
76            // DOMResult(outNode));
77            t.transform(new StreamSource(execReaderXML), new DOMResult(outNode));
78            System.out.println("Finsished transformer.");
79            sw = new StringWriter();
80
81            StreamResult sr = new StreamResult(sw);
82            t = TransformerFactory.newInstance().newTransformer();
83            t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
84            t.transform(new DOMSource(outNode), sr);
85            System.out.println(sw.toString());
86        } catch (Exception e) {
87            Assert.fail(e.toString());
88        } finally {
89        }
90
91    }
92}
93