commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r628707 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/plist/ test/java/org/apache/commons/configuration2/plist/ test/resources/
Date Mon, 18 Feb 2008 12:43:10 GMT
Author: ebourg
Date: Mon Feb 18 04:43:07 2008
New Revision: 628707

URL: http://svn.apache.org/viewvc?rev=628707&view=rev
Log:
Fixed the date format for XMLPropertyListConfiguration (CONFIGURATION-260)

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test.plist.xml

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=628707&r1=628706&r2=628707&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
Mon Feb 18 04:43:07 2008
@@ -41,7 +41,7 @@
 
 /**
  * NeXT / OpenStep style configuration. This configuration can read and write
- * ASCII plist files. It support the GNUStep extension to specify date objects.
+ * ASCII plist files. It supports the GNUStep extension to specify date objects.
  * <p>
  * References:
  * <ul>

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java?rev=628707&r1=628706&r2=628707&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
Mon Feb 18 04:43:07 2008
@@ -28,10 +28,12 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.TimeZone;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
@@ -73,7 +75,7 @@
  *         &lt;true/>
  *
  *         &lt;key>date&lt;/key>
- *         &lt;date>2005-01-01T12:00:00-0700&lt;/date>
+ *         &lt;date>2005-01-01T12:00:00Z&lt;/date>
  *
  *         &lt;key>data&lt;/key>
  *         &lt;data>RHJhY28gRG9ybWllbnMgTnVucXVhbSBUaXRpbGxhbmR1cw==&lt;/data>
@@ -556,8 +558,15 @@
          */
         private static final long serialVersionUID = -7614060264754798317L;
 
-        /** The standard format of dates in plist files. */
-        private static DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+        /** The MacOS format of dates in plist files. */
+        private static DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+        static
+        {
+            format.setTimeZone(TimeZone.getTimeZone("UTC"));
+        }
+
+        /** The GNUstep format of dates in plist files. */
+        private static DateFormat gnustepFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss
Z");
 
         /**
          * Update the value of the node. If the existing value is null, it's
@@ -573,10 +582,10 @@
             {
                 setValue(value);
             }
-            else if (getValue() instanceof List)
+            else if (getValue() instanceof Collection)
             {
-                List list = (List) getValue();
-                list.add(value);
+                Collection collection = (Collection) getValue();
+                collection.add(value);
             }
             else
             {
@@ -596,7 +605,22 @@
         {
             try
             {
-                addValue(format.parse(value));
+                if (value.indexOf(' ') != -1)
+                {
+                    // parse the date using the GNUstep format
+                    synchronized (gnustepFormat)
+                    {
+                        addValue(gnustepFormat.parse(value));
+                    }
+                }
+                else
+                {
+                    // parse the date using the MacOS X format
+                    synchronized (format)
+                    {
+                        addValue(format.parse(value));
+                    }
+                }
             }
             catch (ParseException e)
             {

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java?rev=628707&r1=628706&r2=628707&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
Mon Feb 18 04:43:07 2008
@@ -18,12 +18,10 @@
 package org.apache.commons.configuration2.plist;
 
 import java.io.File;
-import java.util.*;
-
-import junit.framework.TestCase;
-import junitx.framework.ObjectAssert;
-import junitx.framework.ArrayAssert;
-import junitx.framework.ListAssert;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TimeZone;
 
 import org.apache.commons.configuration2.Configuration;
 import org.apache.commons.configuration2.ConfigurationAssert;
@@ -31,7 +29,11 @@
 import org.apache.commons.configuration2.FileConfiguration;
 import org.apache.commons.configuration2.HierarchicalConfiguration;
 import org.apache.commons.configuration2.StrictConfigurationComparator;
-import org.apache.commons.configuration2.plist.XMLPropertyListConfiguration;
+
+import junit.framework.TestCase;
+import junitx.framework.ArrayAssert;
+import junitx.framework.ListAssert;
+import junitx.framework.ObjectAssert;
 
 /**
  * @author Emmanuel Bourg
@@ -74,6 +76,21 @@
         assertEquals("1st element", "value1", config.getProperty("dictionary.key1"));
         assertEquals("2nd element", "value2", config.getProperty("dictionary.key2"));
         assertEquals("3rd element", "value3", config.getProperty("dictionary.key3"));
+    }
+
+    public void testDate() throws Exception
+    {
+        Calendar calendar = Calendar.getInstance();
+        calendar.clear();
+        calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
+        calendar.set(2005, Calendar.JANUARY, 1, 12, 0, 0);
+
+        assertEquals("'date' property", calendar.getTime(), config.getProperty("date"));
+
+        calendar.setTimeZone(TimeZone.getTimeZone("CET"));
+        calendar.set(2002, Calendar.MARCH, 22, 11, 30, 0);
+
+        assertEquals("'date-gnustep' property", calendar.getTime(), config.getProperty("date-gnustep"));
     }
 
     public void testSubset()

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test.plist.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test.plist.xml?rev=628707&r1=628706&r2=628707&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test.plist.xml
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test.plist.xml
Mon Feb 18 04:43:07 2008
@@ -19,7 +19,10 @@
         <false/>
 
         <key>date</key>
-        <date>2005-01-01T12:00:00-0700</date>
+        <date>2005-01-01T12:00:00Z</date>
+
+        <key>date-gnustep</key>
+        <date>2002-03-22 11:30:00 +0100</date>
 
         <key>data</key>
         <data>RHJhY28gRG9ybWllbnMgTnVucXVhbSBUaXRpbGxhbmR1cw==</data>



Mime
View raw message