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