ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r348913 - in /ant/core/trunk/src: main/org/apache/tools/ant/util/DOMElementWriter.java testcases/org/apache/tools/ant/util/DOMElementWriterTest.java
Date Fri, 25 Nov 2005 08:42:28 GMT
Author: bodewig
Date: Fri Nov 25 00:42:22 2005
New Revision: 348913

URL: http://svn.apache.org/viewcvs?rev=348913&view=rev
Log:
fix extraneous whitespace, should fix svn-antlib tests

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java?rev=348913&r1=348912&r2=348913&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java Fri Nov 25 00:42:22
2005
@@ -103,6 +103,7 @@
         // Write child elements and text
         NodeList children = element.getChildNodes();
         boolean hasChildren = (children.getLength() > 0);
+        boolean hasChildElements = false;
         openElement(element, out, indent, indentWith, hasChildren);
 
         if (hasChildren) {
@@ -112,6 +113,7 @@
                 switch (child.getNodeType()) {
     
                 case Node.ELEMENT_NODE:
+                    hasChildElements = true;
                     if (i == 0) {
                         out.write(lSep);
                     }
@@ -154,7 +156,7 @@
                     // Do nothing
                 }
             }
-            closeElement(element, out, indent, indentWith, true);
+            closeElement(element, out, indent, indentWith, hasChildElements);
         }
     }
 

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java?rev=348913&r1=348912&r2=348913&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java Fri Nov
25 00:42:22 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright  2000-2004 The Apache Software Foundation
+ * Copyright  2000-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -17,9 +17,13 @@
 
 package org.apache.tools.ant.util;
 
+import java.io.IOException;
+import java.io.StringWriter;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
  * Tests for org.apache.tools.ant.util.DOMElementWriter.
@@ -92,4 +96,51 @@
         assertEquals("A]]>B]]>C",
                      w.encodedata("A]]>B]]>C"));
     }
+
+    public void testNoAdditionalWhiteSpaceForText() throws IOException {
+        Document d = DOMUtils.newDocument();
+        Element root = d.createElement("root");
+        DOMUtils.appendTextElement(root, "textElement", "content");
+
+        StringWriter sw = new StringWriter();
+        DOMElementWriter w = new DOMElementWriter();
+        w.write(root, sw, 0, "  ");
+        assertEquals("<root>" + StringUtils.LINE_SEP
+                     + "  <textElement>content</textElement>"
+                     + StringUtils.LINE_SEP
+                     + "</root>" + StringUtils.LINE_SEP,
+                     sw.toString());
+    }
+
+    public void testNoAdditionalWhiteSpaceForCDATA() throws IOException {
+        Document d = DOMUtils.newDocument();
+        Element root = d.createElement("root");
+        DOMUtils.appendCDATAElement(root, "cdataElement", "content");
+
+        StringWriter sw = new StringWriter();
+        DOMElementWriter w = new DOMElementWriter();
+        w.write(root, sw, 0, "  ");
+        assertEquals("<root>" + StringUtils.LINE_SEP
+                     + "  <cdataElement><![CDATA[content]]></cdataElement>"
+                     + StringUtils.LINE_SEP
+                     + "</root>" + StringUtils.LINE_SEP,
+                     sw.toString());
+    }
+
+    public void testNoAdditionalWhiteSpaceForEmptyElement() throws IOException {
+        Document d = DOMUtils.newDocument();
+        Element root = d.createElement("root");
+        DOMUtils.createChildElement(root, "emptyElement");
+
+        StringWriter sw = new StringWriter();
+        DOMElementWriter w = new DOMElementWriter();
+        w.write(root, sw, 0, "  ");
+        assertEquals("<root>" + StringUtils.LINE_SEP
+                     //                     + "  <emptyElement></emptyElement>"
+                     + "  <emptyElement />"
+                     + StringUtils.LINE_SEP
+                     + "</root>" + StringUtils.LINE_SEP,
+                     sw.toString());
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message