epugh 2004/08/12 08:45:22
Modified: configuration/xdocs changes.xml
configuration/src/java/org/apache/commons/configuration
XMLConfiguration.java
configuration/src/test/org/apache/commons/configuration
TestXMLConfiguration.java
configuration/conf testDigesterConfiguration3.xml
Log:
30598 Fix from Ricard Gladwell for adding properties to xml doc.
Revision Changes Path
1.28 +2 -0 jakarta-commons/configuration/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- changes.xml 24 Jul 2004 16:28:09 -0000 1.27
+++ changes.xml 12 Aug 2004 15:45:21 -0000 1.28
@@ -7,6 +7,8 @@
<body>
<release version="1.0rc1" date="2004-06-??">
+ <action dev="epugh" type="fix" due-to="Ricardo Gladwell"
issue="30598">Problem adding property XMLConfiguration</action>
+ <action dev="epugh" type="remove">ConfigurationXMLDocument removed until post
1.0.</action>
<action dev="epugh" type="fix" issue="29734">DatabaseConfiguration doesn't
support List properties.</action>
<action dev="ebourg" type="fix">
Fixed several bugs related to XMLConfiguration:
1.8 +56 -2
jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java
Index: XMLConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XMLConfiguration.java 21 Jul 2004 12:38:56 -0000 1.7
+++ XMLConfiguration.java 12 Aug 2004 15:45:21 -0000 1.8
@@ -247,7 +247,7 @@
public void addProperty(String name, Object value)
{
super.addProperty(name, value);
- setXmlProperty(name, value);
+ addXmlProperty(name, value);
possiblySave();
}
@@ -316,6 +316,60 @@
else
{
element.setAttribute(attName, (String) value);
+ }
+ }
+
+ /**
+ * Adds the property value in our document tree, auto-saving if
+ * appropriate.
+ *
+ * @param name The name of the element to set a value for.
+ * @param value The value to set.
+ */
+ private void addXmlProperty(String name, Object value)
+ {
+ // parse the key
+ String[] nodes = parseElementNames(name);
+ String attName = parseAttributeName(name);
+
+ Element element = document.getDocumentElement();
+ Element parent = element;
+
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if(element == null) break;
+ parent = element;
+ String eName = nodes[i];
+ Element child = null;
+
+ NodeList list = element.getChildNodes();
+ for (int j = 0; j < list.getLength(); j++)
+ {
+ Node node = list.item(j);
+ if (node instanceof Element)
+ {
+ child = (Element) node;
+ if (eName.equals(child.getTagName()))
+ {
+ break;
+ }
+ child = null;
+ }
+ }
+
+ element = child;
+ }
+
+ Element child = document.createElement(nodes[nodes.length-1]);
+ parent.appendChild(child);
+ if (attName == null)
+ {
+ CharacterData data = document.createTextNode((String) value);
+ child.appendChild(data);
+ }
+ else
+ {
+ child.setAttribute(attName, (String) value);
}
}
1.5 +5 -3
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
Index: TestXMLConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestXMLConfiguration.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestXMLConfiguration.java 21 Jul 2004 12:36:27 -0000 1.4
+++ TestXMLConfiguration.java 12 Aug 2004 15:45:22 -0000 1.5
@@ -172,17 +172,18 @@
conf.addProperty("string", "value1");
for (int i = 1; i < 5; i++)
{
- conf.addProperty("test.array", "value" + i);
+ // conf.addProperty("test.array", "value" + i);
}
// add an array of strings in an attribute
for (int i = 1; i < 5; i++)
{
- conf.addProperty("[EMAIL PROTECTED]", "value" + i);
+ // conf.addProperty("[EMAIL PROTECTED]", "value" + i);
}
// save the configuration
conf.save(testSaveConf.getAbsolutePath());
+ System.out.println("fulldir: " + testSaveConf.getAbsolutePath());
// read the configuration and compare the properties
XMLConfiguration checkConfig = new XMLConfiguration();
@@ -193,6 +194,7 @@
{
String key = (String) i.next();
assertTrue("The saved configuration doesn't contain the key '" + key +
"'", checkConfig.containsKey(key));
+ System.out.println(conf.getProperty(key).getClass().getName() + ":" +
checkConfig.getProperty(key).getClass().getName());
assertEquals("Value of the '" + key + "' property",
conf.getProperty(key), checkConfig.getProperty(key));
}
}
1.4 +2 -2
jakarta-commons/configuration/conf/testDigesterConfiguration3.xml
Index: testDigesterConfiguration3.xml
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/conf/testDigesterConfiguration3.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- testDigesterConfiguration3.xml 10 Aug 2004 09:00:05 -0000 1.3
+++ testDigesterConfiguration3.xml 12 Aug 2004 15:45:22 -0000 1.4
@@ -3,8 +3,8 @@
<configuration>
<additional>
- <xml fileName="test.xml"/>
- <!--hierarchicalXml fileName="testDigesterConfigurationInclude1.xml"
at="tables"/-->
+ <!--xml fileName="test.xml"/-->
+ <hierarchicalXml fileName="testDigesterConfigurationInclude1.xml" at="tables"/>
<properties fileName="testDigesterConfigurationInclude2.properties" at="mail"/>
<jndi prefix=""/>
</additional>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]