You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/10/09 22:31:28 UTC

DO NOT REPLY [Bug 4054] New: - Transformer.setOutputProperties() resets output properties

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4054>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4054

Transformer.setOutputProperties() resets output properties

           Summary: Transformer.setOutputProperties() resets output
                    properties
           Product: XalanJ2
           Version: 2.0.0
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xalan.transformer
        AssignedTo: xalan-dev@xml.apache.org
        ReportedBy: tom.amiro@sun.com


[this description is taken from SunMicrosystem's bug 4512314]

javax.xml.transform.Transformer.setOutputProperties(Properties oformat) reverts
values of the output properties, which are set by
Transformer.setOutputProperty() method, to values defined by stylesheet (See
test.java below). These properties should not be changed 
because they are not listed in the property list 'oformat'. 

The javadoc description of the 
method Transformer.setOutputProperties() (jdk1.4.0beta-b82) reads:
  
     "public abstract void setOutputProperties(Properties oformat)
                                  throws IllegalArgumentException
      ...
      Parameters:
         oformat - A set of output properties that will be used to override any
of the same properties in affect for the transformation."

Hence the property is not changed if it is not in the set of output properties 
'oformat'.

This bug is found in the builds jdk1.4.0-beta3-b82, jaxp-1.1.3 and affects a new
JCK1.4 test

api/javax_xml/transform/Transformer/index.html#GetSetOProperties[GetSetOProperties009]

------------------------------------test.java-----------------------------
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import java.util.Properties;
import javax.xml.transform.OutputKeys;

public class test {
    private static Transformer transformer;

    private static void printPropertyIndentValue(String msgPrefix) {
        System.out.print(msgPrefix);
        System.out.print("indent=");
        System.out.println(transformer.getOutputProperty(OutputKeys.INDENT));
    }

    public static void main (String[] args) {
        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'/>\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);
            
            printPropertyIndentValue("In stylesheet: ");
            
            transformer.setOutputProperty(OutputKeys.INDENT, "no");

            printPropertyIndentValue("Before method call: ");
    
            Properties properties = new Properties();
            properties.setProperty(OutputKeys.ENCODING, "UTF-16");
            transformer.setOutputProperties(properties);
            
            printPropertyIndentValue("After method call: ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


>From Todd Miller:

The bug arises because in the code example given, the sequence is:
        (1) make transformer
        (2) print curr value of INDENT property
        (3) set the INDENT property to a differnt value
        (4) print curr value of INDENT property
        (5) set another property (unrelated to INDENT) but do so
            with the API call setOutputProperties(Properties)
            instead of just setOutputProperty(). 
        (6) print curr value of INDENT property
        
Line (2) prints the default value, which is "yes"
Line (3) changes the value from "yes" to "no"
Line (4) prints the curr value, which is "no" -so far so good.
Line (5) I bet when Xalan gets an array of new properties here,
         they do not bother to merge the ones mentioned in the array
         with the existing ones, they just wipe out all previous set
         values with whatever is in this new array.
        
        This behavior is verified by replacing the call:
       
            Properties properties = new Properties();
            properties.setProperty(OutputKeys.ENCODING, "UTF-16");
            transformer.setOutputProperties(properties);
            
         with
         
            transformer.setOutputProperties(OutputKeys.ENCODING, "UTF-16");
            
         The replacement above does the same thing, but will not cause
         Xalan to forget about previously set values.

Line (6) prints the 'default value' of "yes", which is wrong.