-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
None
-
5.0
-
generic
-
generic
Regression(Bug4512806) : transformer.setOutputProperties(null)
does not work properly
According to javadoc - If argument to this function is null,
any properties previously set are removed, and the value
will revert to the value defined in the templates object.
To reproduce the problem : use the program below
---------------------------------------------------
java -version
javac Bug4512806.java
java Bug4512806
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.OutputKeys;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
public class Bug4512806 { // extends Util{
private static Transformer transformer;
public Bug4512806() {
}
public static void main(String args[]){
Bug4512806 bug = new Bug4512806();
bug.run();
}
/**
* This will check bug xxxxxxx
*
*
*/
public void run() {
try {
boolean status = testProperty();
System.out.println("status"+status);
} catch (Exception ex) {
System.err.println(ex);
}
}
private String printPropertyValue(String name) {
return name+"="+transformer.getOutputProperty(name);
}
public boolean testProperty () {
boolean testStat = false;
try {
String xslData = "<?xml version='1.0'?>"
+ "<xsl:stylesheet"
+ " version='1.0'"
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
+ ">\n"
+ " <xsl:output method='xml' indent='yes'"
+ " encoding='UTF-8'/>\n"
+ " <xsl:template match='/'>\n"
+ " Hello World! \n"
+ " </xsl:template>\n"
+ "</xsl:stylesheet>";
/* Create a transform factory instance */
TransformerFactory tfactory = TransformerFactory.newInstance();
/* Create a StreamSource instance */
StreamSource streamSource = new StreamSource(new StringReader(xslData));
transformer = tfactory.newTransformer(streamSource);
System.out.println("In stylesheet: ");
System.err.println("before "+ printPropertyValue(OutputKeys.INDENT));
System.err.println("before "+ printPropertyValue(OutputKeys.ENCODING));
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-16");
System.err.println("\nBefore method call: ");
System.err.println(printPropertyValue(OutputKeys.INDENT));
System.err.println(printPropertyValue(OutputKeys.ENCODING));
if((printPropertyValue(OutputKeys.INDENT).equals("no")) && (printPropertyValue(OutputKeys.ENCODING).equals("UTF16"))) {
testStat =true;
}else{
System.err.println("Values not set");
testStat = false;
return testStat ;
}
transformer.setOutputProperties(null);
System.out.println("After method call: ");
System.err.println(printPropertyValue(OutputKeys.INDENT));
System.err.println(printPropertyValue(OutputKeys.ENCODING));
if((printPropertyValue(OutputKeys.INDENT).equals("yes")) && ( printPropertyValue(OutputKeys.ENCODING).equals("UTF8"))){
testStat = true;
}else{
System.err.println("Value not UNSET");
testStat = false;
return testStat;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
- Sample program attached
does not work properly
According to javadoc - If argument to this function is null,
any properties previously set are removed, and the value
will revert to the value defined in the templates object.
To reproduce the problem : use the program below
---------------------------------------------------
java -version
javac Bug4512806.java
java Bug4512806
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.OutputKeys;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
public class Bug4512806 { // extends Util{
private static Transformer transformer;
public Bug4512806() {
}
public static void main(String args[]){
Bug4512806 bug = new Bug4512806();
bug.run();
}
/**
* This will check bug xxxxxxx
*
*
*/
public void run() {
try {
boolean status = testProperty();
System.out.println("status"+status);
} catch (Exception ex) {
System.err.println(ex);
}
}
private String printPropertyValue(String name) {
return name+"="+transformer.getOutputProperty(name);
}
public boolean testProperty () {
boolean testStat = false;
try {
String xslData = "<?xml version='1.0'?>"
+ "<xsl:stylesheet"
+ " version='1.0'"
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
+ ">\n"
+ " <xsl:output method='xml' indent='yes'"
+ " encoding='UTF-8'/>\n"
+ " <xsl:template match='/'>\n"
+ " Hello World! \n"
+ " </xsl:template>\n"
+ "</xsl:stylesheet>";
/* Create a transform factory instance */
TransformerFactory tfactory = TransformerFactory.newInstance();
/* Create a StreamSource instance */
StreamSource streamSource = new StreamSource(new StringReader(xslData));
transformer = tfactory.newTransformer(streamSource);
System.out.println("In stylesheet: ");
System.err.println("before "+ printPropertyValue(OutputKeys.INDENT));
System.err.println("before "+ printPropertyValue(OutputKeys.ENCODING));
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-16");
System.err.println("\nBefore method call: ");
System.err.println(printPropertyValue(OutputKeys.INDENT));
System.err.println(printPropertyValue(OutputKeys.ENCODING));
if((printPropertyValue(OutputKeys.INDENT).equals("no")) && (printPropertyValue(OutputKeys.ENCODING).equals("UTF16"))) {
testStat =true;
}else{
System.err.println("Values not set");
testStat = false;
return testStat ;
}
transformer.setOutputProperties(null);
System.out.println("After method call: ");
System.err.println(printPropertyValue(OutputKeys.INDENT));
System.err.println(printPropertyValue(OutputKeys.ENCODING));
if((printPropertyValue(OutputKeys.INDENT).equals("yes")) && ( printPropertyValue(OutputKeys.ENCODING).equals("UTF8"))){
testStat = true;
}else{
System.err.println("Value not UNSET");
testStat = false;
return testStat;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
- Sample program attached
- relates to
-
JDK-4512806 Transformer.setOutputProperties(null) doesn't revert properties values
-
- Resolved
-