commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Torrance <>
Subject Re: [configuration] Character position of key in file
Date Wed, 16 Nov 2016 00:21:02 GMT
Thanks for the detailed suggestions, Oliver. I appreciate it. I'll dig 
around a bit and give it some thought; you've given me a good head start.

All the best,

On 11/15/2016 03:35 PM, Oliver Heger wrote:
> Hi Greg,
> Am 14.11.2016 um 22:34 schrieb Greg Torrance:
>> Thanks Oliver.
>> Regarding the Configuration API, is it possible to replace not just
>> values but keys, too? For example, could I replace
>> <ReplaceMe id="4"/>
>> with
>> <NewKey>
>>     <NewChildKey1>
>>        <NewChildKey2>Some Value</NewChildKey2>
>>     </NewChildKey1>
>> </NewKey>
>> If so, can you suggest what class to look at first (for accomplishing
>> this)?
> This is indeed a tough one. There are multiple options, but I am not
> sure whether they fully cover your use case; you will certainly need
> some experiments:
> - With the high-level API (offered by Configuration) you can delete the
> key to be replaced and then use the addNodes() method to insert a nodes
> structure as replacement. The tricky part is to get the key for
> addNodes() right, so the replacement goes to the desired position. The
> configuration's expression engine may help you here. It has methods to
> query for keys (and receive matching node objects) and to obtain a
> canonical key for a given node.
> - You may also operate on the hierarchical configuration's node
> structure directly. The root node can be queried via the node model
> getNodeModel()). As this structure is immutable, you cannot directly
> change it, but you have to create a copy which might not be that efficient.
> - Unfortunately, XMLConfiguration has no direct hooks to manipulate the
> node creation process. There are some helper methods, but these are private.
> The use case is interesting. It would be good to offer some generic
> support for configuration pre-processing, independent on a concrete
> implementation. However, this is probably not easy to implement, and it
> may still be insufficient for specific use cases.
> Oliver
>> Thanks,
>> Greg
>> On 11/14/2016 04:27 PM, Oliver Heger wrote:
>>> Hi Greg,
>>> Am 14.11.2016 um 19:01 schrieb Greg Torrance:
>>>> I hope I'm not asking too many questions...
>>>> I wonder if it is possible to determine the character/byte position
>>>> of a particular key in a configuration file?
>>> No, the original position from where data is read is not stored in the
>>> resulting configuration.
>>>> My intent is to do a pre-pass of an XML configuration file in which
>>>> certain configuration keys/values are replaced by other keys/values.
>>>> Once that is done the file will be reloaded. I realize this is
>>>> possible outside of Commons Configuration, but I was wondering if
>>>> there is a "hook" in the tool that might help simplify the process.
>>> But wouldn't it be easier to do this with the Configuration API? Load
>>> the configuration, iterate over its keys, replace data as appropriate
>>> and save the result?
>>> Oliver
>>>> Thanks,
>>>> Greg
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> For additional commands, e-mail:
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message