You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2008/02/18 13:37:21 UTC
svn commit: r628705 - in /commons/proper/configuration/trunk: conf/
src/java/org/apache/commons/configuration/plist/
src/test/org/apache/commons/configuration/plist/ xdocs/
Author: ebourg
Date: Mon Feb 18 04:37:19 2008
New Revision: 628705
URL: http://svn.apache.org/viewvc?rev=628705&view=rev
Log:
Fixed the date format for XMLPropertyListConfiguration (CONFIGURATION-260)
Modified:
commons/proper/configuration/trunk/conf/test.plist.xml
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
commons/proper/configuration/trunk/xdocs/changes.xml
Modified: commons/proper/configuration/trunk/conf/test.plist.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/test.plist.xml?rev=628705&r1=628704&r2=628705&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/test.plist.xml (original)
+++ commons/proper/configuration/trunk/conf/test.plist.xml Mon Feb 18 04:37:19 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>
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=628705&r1=628704&r2=628705&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 Mon Feb 18 04:37:19 2008
@@ -40,7 +40,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/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java?rev=628705&r1=628704&r2=628705&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java Mon Feb 18 04:37:19 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 @@
* <true/>
*
* <key>date</key>
- * <date>2005-01-01T12:00:00-0700</date>
+ * <date>2005-01-01T12:00:00Z</date>
*
* <key>data</key>
* <data>RHJhY28gRG9ybWllbnMgTnVucXVhbSBUaXRpbGxhbmR1cw==</data>
@@ -317,7 +319,10 @@
if (value instanceof Date)
{
- out.println(padding + "<date>" + PListNode.format.format((Date) value) + "</date>");
+ synchronized (PListNode.format)
+ {
+ out.println(padding + "<date>" + PListNode.format.format((Date) value) + "</date>");
+ }
}
else if (value instanceof Calendar)
{
@@ -557,8 +562,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
@@ -574,10 +586,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
{
@@ -597,7 +609,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/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java?rev=628705&r1=628704&r2=628705&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java Mon Feb 18 04:37:19 2008
@@ -73,6 +73,21 @@
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()
{
Configuration subset = config.subset("dictionary");
Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=628705&r1=628704&r2=628705&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Mon Feb 18 04:37:19 2008
@@ -44,6 +44,9 @@
It's now possible to read a configuration file containing
a '#' in its name (requires Java 1.4 or above).
</action>
+ <action dev="ebourg" type="fix" issue="CONFIGURATION-260">
+ Fixed the date format for XMLPropertyListConfiguration.
+ </action>
</release>
<release version="1.5" date="2007-11-24" description="Many smaller bugfixes">