DECAFFMEYER MATHIEU wrote:
Hi,
I am trying to delete a property with this structure :
<conf>
....
<indexList>
<index default="false" name="test1_en">
<dir>C:/UserTemp/test1_en/search_index</dir>
</index>
<index default="false" name="test2_en">
<dir>C:/UserTemp/test2_en/search_index</dir>
</index>
<index default="false" name="test3_en">
<dir>C:/UserTemp/test3_en/search_index</dir>
</index>
</indexList>
....
</conf>
Now let's say I want to delete the idnex named test3_en
I tried this :
*for*(*int* i=0;* true*; ++i) {
* if*(writerSearchmask.getString("indexList.index("+i+")[EMAIL PROTECTED]")
==* null*)* break*;
*
if*(writerSearchmask.getString("indexList.index("+i+")[EMAIL PROTECTED]").equals("test3_en"))
{
((HierarchicalConfiguration)writerSearchmask).clearTree("indexList.index("+i+")");
//writerSearchmask.clearProperty("indexList.index("+i+")"); <- I tried
this too
* break*;
}
}
But it just won't delete,
what am I doing wrong ? any help here :) ?
Thank u.
*__________________________________*
* Matt*////
I can see nothing wrong in this code fragment; deleting should work this
way. To verify I have written the following unit test based on your
structures:
/**
* Tests removing more complex node structures.
*/
public void testClearTreeComplex()
{
final int count = 5;
// create the structure
for (int idx = 0; idx < count; idx++)
{
config.addProperty("indexList.index(-1)[EMAIL PROTECTED]",
Boolean.FALSE);
config.addProperty("[EMAIL PROTECTED]", "test" + idx);
config.addProperty("indexList.index.dir", "testDir" + idx);
}
assertEquals("Wrong number of nodes", count - 1, config
.getMaxIndex("[EMAIL PROTECTED]"));
// Remove a sub tree
boolean found = false;
for (int idx = 0; true; idx++)
{
String name = config.getString("indexList.index(" + idx
+ ")[EMAIL PROTECTED]");
if (name == null)
{
break;
}
if ("test3".equals(name))
{
config.clearTree("indexList.index(" + idx + ")");
found = true;
}
}
assertTrue("Key to remove not found", found);
assertEquals("Wrong number of nodes after remove", count - 2,
config
.getMaxIndex("[EMAIL PROTECTED]"));
assertEquals("Wrong number of dir nodes after remove", count - 2,
config.getMaxIndex("indexList.index.dir"));
// Verify
for (int idx = 0; true; idx++)
{
String name = config.getString("indexList.index(" + idx
+ ")[EMAIL PROTECTED]");
if (name == null)
{
break;
}
if ("test3".equals(name))
{
fail("Key was not removed!");
}
}
}
This test passes. Maybe you can use this code to experiment a bit and
find out what is going wrong.
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]