Author: ebourg
Date: Sun Jun 21 17:46:56 2009
New Revision: 787057

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

Modified:
    
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
    
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: 
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java?rev=787057&r1=787056&r2=787057&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
 Sun Jun 21 17:46:56 2009
@@ -45,7 +45,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 Documentation - Old-Style ASCII Property Lists</a></li>
  *   <li><a
  * 
href="http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSPropertyList.html";>
@@ -252,18 +252,7 @@
             out.print(padding + quoteString(node.getName()) + " = ");
         }
 
-        // get all non trivial nodes
         List children = new ArrayList(node.getChildren());
-        Iterator it = children.iterator();
-        while (it.hasNext())
-        {
-            Node child = (Node) 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
@@ -275,7 +264,7 @@
             out.println(padding + "{");
 
             // display the children
-            it = children.iterator();
+            Iterator it = children.iterator();
             while (it.hasNext())
             {
                 Node child = (Node) it.next();
@@ -304,6 +293,17 @@
                 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

Modified: 
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java?rev=787057&r1=787056&r2=787057&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
 Sun Jun 21 17:46:56 2009
@@ -252,6 +252,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));

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=787057&r1=787056&r2=787057&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Sun Jun 21 17:46:56 
2009
@@ -24,8 +24,7 @@
   <body>
     <release version="1.7" date="in SVN" description="">
       <action dev="ebourg" type="fix" issue="CONFIGURATION-362">
-        Empty dictionary elements in an XML PropertyList are now preserved and 
no longer
-        turned into a string when the configuration is saved.
+        Empty dictionaries in a PropertyList configuration are now preserved 
when the configuration is saved.
       </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-385">
         DatabaseConfiguration now generates correct events for the clear() and


Reply via email to