changeset 381:35416f31de0a

7150637: No newline emitted after XML decl in XSLT output Reviewed-by: lancea
author joehw
date Wed, 21 Mar 2012 15:35:53 -0700
parents 5c881231f116
children b3b62f285a2c
files src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java src/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java src/com/sun/org/apache/xml/internal/serializer/ToStream.java src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
diffstat 8 files changed, 77 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java	Wed Mar 21 15:35:53 2012 -0700
@@ -67,6 +67,8 @@
     public String  _encoding = "UTF-8";
     public boolean _omitHeader = false;
     public String  _standalone = null;
+    //see OutputPropertiesFactory.ORACLE_IS_STANDALONE
+    public boolean  _isStandalone = false;
     public String  _doctypePublic = null;
     public String  _doctypeSystem = null;
     public boolean _indent = false;
@@ -671,6 +673,7 @@
                 if (_doctypeSystem != null) {
                     handler.setDoctype(_doctypeSystem, _doctypePublic);
                 }
+                handler.setIsStandalone(_isStandalone);
             }
             else if (_method.equals("html")) {
                 handler.setIndent(_indent);
@@ -693,6 +696,7 @@
             }
             handler.setIndent(_indent);
             handler.setDoctype(_doctypeSystem, _doctypePublic);
+            handler.setIsStandalone(_isStandalone);
         }
     }
 
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java	Wed Mar 21 15:35:53 2012 -0700
@@ -990,6 +990,11 @@
                     }
                 }
             }
+            else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
+                 if (value != null && value.equals("yes")) {
+                     translet._isStandalone = true;
+                 }
+            }
         }
     }
 
@@ -1049,6 +1054,11 @@
                     handler.setIndentAmount(Integer.parseInt(value));
                 }
             }
+            else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
+                if (value != null && value.equals("yes")) {
+                    handler.setIsStandalone(true);
+                }
+            }
             else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
                 if (value != null) {
                     StringTokenizer e = new StringTokenizer(value);
@@ -1162,6 +1172,7 @@
                 name.equals(OutputKeys.OMIT_XML_DECLARATION)   ||
                 name.equals(OutputKeys.STANDALONE) ||
                 name.equals(OutputKeys.VERSION) ||
+                name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE) ||
                 name.charAt(0) == '{');
     }
 
--- a/src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java	Wed Mar 21 15:35:53 2012 -0700
@@ -179,6 +179,13 @@
         aMethodIsCalled();
     }
     /**
+     * @see SerializationHandler#setIsStandalone(boolean)
+     */
+    public void setIsStandalone(boolean isStandalone)
+    {
+        aMethodIsCalled();
+    }
+    /**
      * @see SerializationHandler#setOutputFormat(java.util.Properties)
      */
     public void setOutputFormat(Properties format)
--- a/src/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java	Wed Mar 21 15:35:53 2012 -0700
@@ -175,6 +175,26 @@
     public static final int S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL_LEN =
         S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL.length();
 
+    /**
+     * This non-standard, Oracle-impl only property key is used as if OutputKeys.STANDALONE is specified but
+     * without writing it out in the declaration; It can be used to reverse the change by Xalan patch 1495.
+     * Since Xalan patch 1495 can cause incompatible behavior, this property is add for application to neutralize
+     * the effect of Xalan patch 1495
+     */
+        /**
+         * <p>Is Standalone</p>
+         *
+         * <ul>
+         *   <li>
+         *     <code>yes</code> to indicate the output is intended to be used as standalone
+         *   </li>
+         *   <li>
+         *     <code>no</code> has no effect.
+         *   </li>
+         * </ul>
+         */
+    public static final String ORACLE_IS_STANDALONE = "http://www.oracle.com/xml/is-standalone";
+
     //************************************************************
     //*  PRIVATE CONSTANTS
     //************************************************************
--- a/src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java	Wed Mar 21 15:35:53 2012 -0700
@@ -124,5 +124,11 @@
      */
     public void setDTDEntityExpansion(boolean expand);
 
+    /**
+     * Specify if the output will be treated as a standalone  property
+     * @param isStandalone true if the http://www.oracle.com/xml/is-standalone is set to yes
+     * @see OutputPropertiesFactory ORACLE_IS_STANDALONE
+     */
+    public void setIsStandalone(boolean b);
 
 }
--- a/src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java	Wed Mar 21 15:35:53 2012 -0700
@@ -143,6 +143,11 @@
     protected boolean m_standaloneWasSpecified = false;
 
     /**
+     * Determine if the output is a standalone.
+     */
+    protected boolean m_isStandalone = false;
+
+    /**
      * Flag to tell if indenting (pretty-printing) is on.
      */
     protected boolean m_doIndent = false;
@@ -740,6 +745,16 @@
     }
 
     /**
+     * Sets the isStandalone property
+     * @param isStandalone true if the ORACLE_IS_STANDALONE is set to yes
+     * @see OutputPropertiesFactory ORACLE_IS_STANDALONE
+     */
+    public void setIsStandalone(boolean isStandalone)
+    {
+       m_isStandalone = isStandalone;
+    }
+
+    /**
      * This method is used when a prefix/uri namespace mapping
      * is indicated after the element was started with a
      * startElement() and before and endElement().
--- a/src/com/sun/org/apache/xml/internal/serializer/ToStream.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xml/internal/serializer/ToStream.java	Wed Mar 21 15:35:53 2012 -0700
@@ -2393,12 +2393,15 @@
 
         try
         {
+            if (shouldIndent() && m_isStandalone)
+                indent();
+
             final int limit = start + length;
             boolean wasDash = false;
             if (m_cdataTagOpen)
                 closeCDATA();
 
-            if (shouldIndent())
+            if (shouldIndent() && !m_isStandalone)
                 indent();
 
             final java.io.Writer writer = m_writer;
@@ -2690,7 +2693,7 @@
      */
     protected boolean shouldIndent()
     {
-        return m_doIndent && (!m_ispreserve && !m_isprevtext) && m_elemContext.m_currentElemDepth > 0;
+        return m_doIndent && (!m_ispreserve && !m_isprevtext) && (m_elemContext.m_currentElemDepth > 0 || m_isStandalone);
     }
 
     /**
--- a/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java	Mon Mar 12 14:54:58 2012 -0700
+++ b/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java	Wed Mar 21 15:35:53 2012 -0700
@@ -163,7 +163,8 @@
                     if (m_doIndent) {
                         if (m_standaloneWasSpecified
                                 || getDoctypePublic() != null
-                                || getDoctypeSystem() != null) {
+                                || getDoctypeSystem() != null
+                                || m_isStandalone) {
                             // We almost never put a newline after the XML
                             // header because this XML could be used as
                             // an extenal general parsed entity
@@ -326,6 +327,13 @@
                 writer.write('?');
                 writer.write('>');
 
+                /**
+                 * Before Xalan 1497, a newline char was printed out if not inside of an
+                 * element. The whitespace is not significant if the output is standalone
+                */
+                if (m_elemContext.m_currentElemDepth <= 0 && m_isStandalone)
+                    writer.write(m_lineSep, 0, m_lineSepLen);
+
                 /*
                  * Don't write out any indentation whitespace now,
                  * because there may be non-whitespace text after this.