Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4512314

Transformer.setOutputProperties() affects not specified output properties

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Name: eaR10174 Date: 10/09/2001


        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&#39;"
                                 + ">\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();
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % java -showversion test
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b82)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b82, mixed mode)

      In stylesheet: indent=yes
      Before method call: indent=no
      After method call: indent=yes
      ---------------------------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            duke J. Duke (Inactive)
            Reporter:
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: