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 */
25
26 import java.io.IOException;
27 import java.io.InputStream;
28
29 import javax.xml.parsers.DocumentBuilder;
30 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.parsers.ParserConfigurationException;
32 import javax.xml.transform.Source;
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.URIResolver;
39 import javax.xml.transform.dom.DOMSource;
40 import javax.xml.transform.stax.StAXResult;
41 import javax.xml.transform.stax.StAXSource;
42 import javax.xml.transform.stream.StreamSource;
43
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
46 import org.w3c.dom.Document;
47 import org.xml.sax.SAXException;
48
49 /*
50 * @summary Test TransformerFactory.
51 */
52 public class TransformerFactoryTest {
53
54 private static URIResolver resolver = new URIResolver() {
55
56 private int n = 0;
57
58 public Source resolve(String href, String base) throws TransformerException {
59
60 System.out.println("resolving: " + href);
61
62 if (n++ > 10) {
63 Assert.fail("Nesting too deep when resolving: " + href);
64 }
65
66 return new StreamSource(this.getClass().getResourceAsStream(href));
67 }
68 };
69
70 private static Document load(InputStream in) throws IOException {
71
|
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 */
25
26 import java.io.IOException;
27 import java.io.InputStream;
28
29 import javax.xml.parsers.DocumentBuilder;
30 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.parsers.ParserConfigurationException;
32 import javax.xml.transform.Source;
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.URIResolver;
39 import javax.xml.transform.dom.DOMSource;
40 import javax.xml.transform.stax.StAXResult;
41 import javax.xml.transform.stax.StAXSource;
42 import javax.xml.transform.stream.StreamSource;
43
44 import org.testng.Assert;
45 import org.testng.annotations.Listeners;
46 import org.testng.annotations.Test;
47 import org.w3c.dom.Document;
48 import org.xml.sax.SAXException;
49
50 /*
51 * @summary Test TransformerFactory.
52 */
53 @Listeners({jaxp.library.FilePolicy.class})
54 public class TransformerFactoryTest {
55
56 private static URIResolver resolver = new URIResolver() {
57
58 private int n = 0;
59
60 public Source resolve(String href, String base) throws TransformerException {
61
62 System.out.println("resolving: " + href);
63
64 if (n++ > 10) {
65 Assert.fail("Nesting too deep when resolving: " + href);
66 }
67
68 return new StreamSource(this.getClass().getResourceAsStream(href));
69 }
70 };
71
72 private static Document load(InputStream in) throws IOException {
73
|