Author: ebourg
Date: Sun Jun 21 17:02:43 2009
New Revision: 787051

URL: http://svn.apache.org/viewvc?rev=787051&view=rev
Log:
Removed the trimming of empty dictionaries for consistency with 
XMLPropertyListConfiguration

Modified:
    
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
    
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestPropertyListConfiguration.java

Modified: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java?rev=787051&r1=787050&r2=787051&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
 Sun Jun 21 17:02:43 2009
@@ -48,7 +48,7 @@
  * References:
  * <ul>
  *   <li><a
- * 
href="http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/Articles/OldStylePListsConcept.html";>
+ * 
href="http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/OldStylePlists/OldStylePLists.html#//apple_ref/doc/uid/20001012-BBCBDBJE";>
  * Apple Documentation - Old-Style ASCII Property Lists</a></li>
  *   <li><a
  * 
href="http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSPropertyList.html";>
@@ -225,18 +225,7 @@
             out.print(padding + quoteString(node.getName()) + " = ");
         }
 
-        // get all non trivial nodes
         List<ConfigurationNode> children = new 
ArrayList<ConfigurationNode>(node.getChildren());
-        Iterator<ConfigurationNode> it = children.iterator();
-        while (it.hasNext())
-        {
-            ConfigurationNode child = it.next();
-            if (child.getValue() == null && (child.getChildren() == null || 
child.getChildren().isEmpty()))
-            {
-                it.remove();
-            }
-        }
-
         if (!children.isEmpty())
         {
             // skip a line, except for the root dictionary
@@ -248,7 +237,7 @@
             out.println(padding + "{");
 
             // display the children
-            it = children.iterator();
+            Iterator<ConfigurationNode> it = children.iterator();
             while (it.hasNext())
             {
                 ConfigurationNode child = it.next();
@@ -277,11 +266,21 @@
                 out.println();
             }
         }
+        else if (node.getValue() == null)
+        {
+            out.println();
+            out.print(padding + "{ };");
+            
+            // line feed if the dictionary is not in an array
+            if (node.getParentNode() != null)
+            {
+                out.println();
+            }
+        }
         else
         {
             // display the leaf value
-            Object value = node.getValue();
-            printValue(out, indentLevel, value);
+            printValue(out, indentLevel, node.getValue());
         }
     }
 

Modified: 
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestPropertyListConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestPropertyListConfiguration.java?rev=787051&r1=787050&r2=787051&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestPropertyListConfiguration.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestPropertyListConfiguration.java
 Sun Jun 21 17:02:43 2009
@@ -285,6 +285,29 @@
         }
     }
 
+    public void testSaveEmptyDictionary() throws Exception
+    {
+        File savedFile = new File("target/testsave.plist");
+
+        // remove the file previously saved if necessary
+        if (savedFile.exists())
+        {
+            assertTrue(savedFile.delete());
+        }
+        
+        // save the configuration
+        String filename = savedFile.getAbsolutePath();
+        config.save(filename);
+
+        assertTrue("The saved file doesn't exist", savedFile.exists());
+
+        // read the configuration and compare the properties
+        PropertyListConfiguration checkConfig = new 
PropertyListConfiguration(new File(filename));
+
+        
assertFalse(config.getRootNode().getChildren("empty-dictionary").isEmpty());
+        
assertFalse(checkConfig.getRootNode().getChildren("empty-dictionary").isEmpty());
+    }
+
     public void testQuoteString()
     {
         assertEquals("null string", null, config.quoteString(null));


Reply via email to