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.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.StringWriter;
29
30 import javax.xml.transform.Result;
31 import javax.xml.transform.Source;
32 import javax.xml.transform.SourceLocator;
33 import javax.xml.transform.Templates;
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.stream.StreamResult;
39 import javax.xml.transform.stream.StreamSource;
40
41 import org.testng.Assert;
42 import org.testng.annotations.Test;
43
44 /*
45 * @bug 6940416
46 * @summary Test transforming correctly.
47 */
48 public class Bug6940416 {
49
50 @Test
51 public void test() {
52 String xslFilename = getClass().getResource("ViewEditor1.xsl").getFile();
53 String inFilename = getClass().getResource("in.xml").getFile();
54 // String outFilename =
55 // getClass().getResource("out-6u17.xml").getFile();
56 // the xml result
57 StringWriter xmlResultString = new StringWriter();
58 try {
59 // Create transformer factory
60 TransformerFactory factory = TransformerFactory.newInstance();
61 factory.setAttribute("debug", true);
62 // Use the factory to create a template containing the xsl file
63 Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
64 // Use the template to create a transformer
65 Transformer xformer = template.newTransformer();
66 // Prepare the input and output files
67 Source source = new StreamSource(new FileInputStream(inFilename));
|
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.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.StringWriter;
29
30 import javax.xml.transform.Result;
31 import javax.xml.transform.Source;
32 import javax.xml.transform.SourceLocator;
33 import javax.xml.transform.Templates;
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.stream.StreamResult;
39 import javax.xml.transform.stream.StreamSource;
40
41 import org.testng.Assert;
42 import org.testng.annotations.Listeners;
43 import org.testng.annotations.Test;
44
45 /*
46 * @bug 6940416
47 * @summary Test transforming correctly.
48 */
49 @Listeners({jaxp.library.FilePolicy.class})
50 public class Bug6940416 {
51
52 @Test
53 public void test() {
54 String xslFilename = getClass().getResource("ViewEditor1.xsl").getFile();
55 String inFilename = getClass().getResource("in.xml").getFile();
56 // String outFilename =
57 // getClass().getResource("out-6u17.xml").getFile();
58 // the xml result
59 StringWriter xmlResultString = new StringWriter();
60 try {
61 // Create transformer factory
62 TransformerFactory factory = TransformerFactory.newInstance();
63 factory.setAttribute("debug", true);
64 // Use the factory to create a template containing the xsl file
65 Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
66 // Use the template to create a transformer
67 Transformer xformer = template.newTransformer();
68 // Prepare the input and output files
69 Source source = new StreamSource(new FileInputStream(inFilename));
|