You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2006/03/10 07:09:50 UTC

svn commit: r384711 - in /xalan/java/trunk/src/org/apache/xml/serializer: ToStream.java ToXMLStream.java

Author: minchau
Date: Thu Mar  9 22:09:49 2006
New Revision: 384711

URL: http://svn.apache.org/viewcvs?rev=384711&view=rev
Log:
Fix for XALANJ-1497 which fixes the incorrect newline
after a PI, but also other incorrect whitespace around
PI and comments.

After this fix the newline after an XML header is almost
never written out because the generated XML could later be
used as an external general parsed entity and even that
extra newline could mess things up.

Modified:
    xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java
    xalan/java/trunk/src/org/apache/xml/serializer/ToXMLStream.java

Modified: xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java
URL: http://svn.apache.org/viewcvs/xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java?rev=384711&r1=384710&r2=384711&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java (original)
+++ xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java Thu Mar  9 22:09:49 2006
@@ -2402,13 +2402,14 @@
 
         try
         {
-            if (shouldIndent())
-                indent();
-
             final int limit = start + length;
             boolean wasDash = false;
             if (m_cdataTagOpen)
                 closeCDATA();
+            
+            if (shouldIndent())
+                indent();
+            
             final java.io.Writer writer = m_writer;    
             writer.write(COMMENT_BEGIN);
             // Detect occurrences of two consecutive dashes, handle as necessary.
@@ -2441,6 +2442,15 @@
             throw new SAXException(e);
         }
 
+        /*
+         * Don't write out any indentation whitespace now,
+         * because there may be non-whitespace text after this.
+         * 
+         * Simply mark that at this point if we do decide
+         * to indent that we should 
+         * add a newline on the end of the current line before
+         * the indentation at the start of the next line.
+         */ 
         m_startNewLine = true;
         // time to generate comment event
         if (m_tracer != null)
@@ -2684,7 +2694,7 @@
      */
     protected boolean shouldIndent()
     {
-        return m_doIndent && (!m_ispreserve && !m_isprevtext);
+        return m_doIndent && (!m_ispreserve && !m_isprevtext) && m_elemContext.m_currentElemDepth > 0;
     }
 
     /**

Modified: xalan/java/trunk/src/org/apache/xml/serializer/ToXMLStream.java
URL: http://svn.apache.org/viewcvs/xalan/java/trunk/src/org/apache/xml/serializer/ToXMLStream.java?rev=384711&r1=384710&r2=384711&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xml/serializer/ToXMLStream.java (original)
+++ xalan/java/trunk/src/org/apache/xml/serializer/ToXMLStream.java Thu Mar  9 22:09:49 2006
@@ -145,8 +145,22 @@
                     writer.write('\"');
                     writer.write(standalone);
                     writer.write("?>");
-                    if (m_doIndent)
-                        writer.write(m_lineSep, 0, m_lineSepLen);
+                    if (m_doIndent) {
+                        if (m_standaloneWasSpecified
+                                || getDoctypePublic() != null
+                                || getDoctypeSystem() != null) {
+                            // We almost never put a newline after the XML
+                            // header because this XML could be used as
+                            // an extenal general parsed entity
+                            // and we don't know the context into which it
+                            // will be used in the future.  Only when
+                            // standalone, or a doctype system or public is
+                            // specified are we free to insert a new line
+                            // after the header.  Is it even worth bothering
+                            // in these rare cases?                           
+                            writer.write(m_lineSep, 0, m_lineSepLen);
+                        }
+                    }
                 } 
                 catch(IOException e)
                 {
@@ -296,13 +310,16 @@
 
                 writer.write('?');
                 writer.write('>');
-
-                // Always output a newline char if not inside of an
-                // element. The whitespace is not significant in that
-                // case.
-                if (m_elemContext.m_currentElemDepth <= 0)
-                    writer.write(m_lineSep, 0, m_lineSepLen);
-
+                
+                /*
+                 * Don't write out any indentation whitespace now,
+                 * because there may be non-whitespace text after this.
+                 * 
+                 * Simply mark that at this point if we do decide
+                 * to indent that we should 
+                 * add a newline on the end of the current line before
+                 * the indentation at the start of the next line.
+                 */ 
                 m_startNewLine = true;
             }
             catch(IOException e)



---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org