28696
|
1 |
/*
|
|
2 |
* Copyright (c) 2003, 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 test.gaptest;
|
|
25 |
|
|
26 |
import static javax.xml.transform.OutputKeys.ENCODING;
|
|
27 |
import static javax.xml.transform.OutputKeys.INDENT;
|
|
28 |
import static org.testng.Assert.assertEquals;
|
|
29 |
|
|
30 |
import java.io.StringReader;
|
|
31 |
|
|
32 |
import javax.xml.transform.Transformer;
|
|
33 |
import javax.xml.transform.TransformerConfigurationException;
|
|
34 |
import javax.xml.transform.TransformerFactory;
|
|
35 |
import javax.xml.transform.stream.StreamSource;
|
|
36 |
|
|
37 |
import jaxp.library.JAXPBaseTest;
|
|
38 |
|
|
39 |
import org.testng.annotations.Test;
|
|
40 |
|
|
41 |
/*
|
|
42 |
* @bug 4512806
|
|
43 |
* @summary test transformer.setOutputProperties(null)
|
|
44 |
*/
|
|
45 |
public class Bug4512806 extends JAXPBaseTest {
|
|
46 |
|
|
47 |
@Test
|
|
48 |
public void testProperty() throws TransformerConfigurationException {
|
|
49 |
/* Create a transform factory instance */
|
|
50 |
TransformerFactory tfactory = TransformerFactory.newInstance();
|
|
51 |
|
|
52 |
/* Create a StreamSource instance */
|
|
53 |
StreamSource streamSource = new StreamSource(new StringReader(xslData));
|
|
54 |
|
|
55 |
transformer = tfactory.newTransformer(streamSource);
|
|
56 |
transformer.setOutputProperty(INDENT, "no");
|
|
57 |
transformer.setOutputProperty(ENCODING, "UTF-16");
|
|
58 |
|
|
59 |
assertEquals(printPropertyValue(INDENT), "indent=no");
|
|
60 |
assertEquals(printPropertyValue(ENCODING), "encoding=UTF-16");
|
|
61 |
|
|
62 |
transformer.setOutputProperties(null);
|
|
63 |
|
|
64 |
assertEquals(printPropertyValue(INDENT), "indent=yes");
|
|
65 |
assertEquals(printPropertyValue(ENCODING), "encoding=UTF-8");
|
|
66 |
|
|
67 |
}
|
|
68 |
|
|
69 |
private String printPropertyValue(String name) {
|
|
70 |
return name + "=" + transformer.getOutputProperty(name);
|
|
71 |
}
|
|
72 |
|
|
73 |
private Transformer transformer;
|
|
74 |
|
|
75 |
private static final String xslData = "<?xml version='1.0'?>"
|
|
76 |
+ "<xsl:stylesheet"
|
|
77 |
+ " version='1.0'"
|
|
78 |
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
|
|
79 |
+ ">\n"
|
|
80 |
+ " <xsl:output method='xml' indent='yes'"
|
|
81 |
+ " encoding='UTF-8'/>\n"
|
|
82 |
+ " <xsl:template match='/'>\n"
|
|
83 |
+ " Hello World! \n"
|
|
84 |
+ " </xsl:template>\n"
|
|
85 |
+ "</xsl:stylesheet>";
|
|
86 |
|
|
87 |
|
|
88 |
}
|