You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2010/01/24 17:49:24 UTC
svn commit: r902600 - in
/commons/proper/configuration/branches/configuration2_experimental:
src/main/java/org/apache/commons/configuration2/plist/
src/test/java/org/apache/commons/configuration2/plist/ src/test/resources/
xdocs/
Author: oheger
Date: Sun Jan 24 16:49:23 2010
New Revision: 902600
URL: http://svn.apache.org/viewvc?rev=902600&view=rev
Log:
[CONFIGURATION-405] Make sure that the root node of XMLPropertyListConfiguration is a PListNode. Otherwise a ConfigurationException is thrown when loading configuration files that do not have an outer dict element. Ported fix to configuration2 branch.
Added:
commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml (with props)
Modified:
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/xdocs/changes.xml
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=902600&r1=902599&r2=902600&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 Sun Jan 24 16:49:23 2010
@@ -137,6 +137,7 @@
*/
public XMLPropertyListConfiguration()
{
+ initRoot();
}
/**
@@ -227,6 +228,14 @@
public void load(Reader in) throws ConfigurationException
{
+ // We have to make sure that the root node is actually a PListNode.
+ // If this object was not created using the standard constructor, the
+ // root node is a plain Node.
+ if (!(getRootNode() instanceof PListNode))
+ {
+ initRoot();
+ }
+
// set up the DTD validation
EntityResolver resolver = new EntityResolver()
{
@@ -422,6 +431,14 @@
}
/**
+ * Helper method for initializing the configuration's root node.
+ */
+ private void initRoot()
+ {
+ setRootNode(new PListNode());
+ }
+
+ /**
* SAX Handler to build the configuration nodes while the document is being parsed.
*/
private static class XMLPropertyListHandler extends DefaultHandler
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=902600&r1=902599&r2=902600&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 Sun Jan 24 16:49:23 2010
@@ -31,6 +31,7 @@
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ConfigurationAssert;
import org.apache.commons.configuration2.ConfigurationComparator;
+import org.apache.commons.configuration2.ConfigurationException;
import org.apache.commons.configuration2.FileConfiguration;
import org.apache.commons.configuration2.InMemoryConfiguration;
import org.apache.commons.configuration2.StrictConfigurationComparator;
@@ -341,4 +342,29 @@
StrictConfigurationComparator comp = new StrictConfigurationComparator();
assertTrue("Configurations are not equal", comp.compare(config, copy));
}
+
+ /**
+ * Tests whether a configuration can be loaded that does not start with a
+ * <code>dict</code> element. This test case is related to
+ * CONFIGURATION-405.
+ */
+ public void testLoadNoDict() throws ConfigurationException
+ {
+ XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
+ plist.setFile(ConfigurationAssert.getTestFile("test2.plist.xml"));
+ plist.load();
+ assertFalse("Configuration is empty", plist.isEmpty());
+ }
+
+ /**
+ * Tests whether a configuration that does not start with a
+ * <code>dict</code> element can be loaded from a constructor. This test
+ * case is related to CONFIGURATION-405.
+ */
+ public void testLoadNoDictConstr() throws ConfigurationException
+ {
+ XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration(
+ ConfigurationAssert.getTestFile("test2.plist.xml"));
+ assertFalse("Configuration is empty", plist.isEmpty());
+ }
}
Added: commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml?rev=902600&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml (added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml Sun Jan 24 16:49:23 2010
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="1.0">
+ <array>
+ <array>
+ <string>http://www.google.com/search?hl=en&client=safari&rls=en&q=RFC822MessageDatasPboardType&btnG=Search&aq=f&oq=&aqi=</string>
+ </array>
+ <array>
+ <string>RFC822MessageDatasPboardType - Google Search</string>
+ </array>
+ </array>
+</plist>
+
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test2.plist.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml?rev=902600&r1=902599&r2=902600&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml Sun Jan 24 16:49:23 2010
@@ -79,6 +79,10 @@
</release>
<release version="1.7" date="in SVN" description="">
+ <action dev="oheger" type="fix" issue="CONFIGURATION-405">
+ XMLPropertyListConfiguration no longer throws a ConfigurationException
+ if the file to be loaded does not have an outer dict element.
+ </action>
<action dev="oheger" type="fix" issue="CONFIGURATION-403">
When an empty XMLConfiguration was saved and reloaded the root element
was assigned an empty text value. Because of this isEmpty() returned