commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <>
Subject Re: Jakarta Configuration Question
Date Wed, 29 Nov 2006 21:40:26 GMT
Thomas Thomas wrote:
> Oliver,
> I could perfectly add elements and attributes how I want,
> But I have a problem that I can't solve with the doc.
> The "startlist" tag (included in the root tag) was below the proxy "tag",
> and when I do this :
>            ((HierarchicalConfiguration)writer).clearTree("startlist");
>            Iterator it = collection.getDirectoriesToParse();
>            while (it.hasNext()) {
>                writer.addProperty("startlist(-1).start(-1)",
> (String);
>                writer.addProperty("startlist.start[@parse]", Boolean.TRUE);
>                writer.addProperty("startlist.start[@index]", Boolean.TRUE);
>            }
> It adds the startlist as last element of the root tag.
> It lost its position.
> Do u have any idea on how to fix this ?
> Thank u for any help.

Okay, this is a hard one.

I think, what you can do is to override the values of the start elements 
instead of removing them and then adding them again. This can be done 
with the setProperty() method. With

int cnt = ((HierarchicalConfiguration) 

you can determine, how many <start> elements exist. Then in a loop you 
can do:

for (int i = 0; it.hasNext() && i < cnt; i++) {
                writer.setProperty("startlist.start(" + i + ")",
                writer.setProperty("startlist.start(" + i + ")[@parse]", 
                writer.setProperty("startlist.start(" + i + ")[@index]", 

If more elements have to be added then the file did contain before, the 
remaining ones can be added in the usual way (as in your code above). If 
some elements are no longer needed, they can be removed with clearTree() 
specifying the exact index (as in the setProperty() calls above).

Hope that helps. The configuration API gives you only a limited control 
over the order of the properties.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message