You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Wieland Gmeiner <wi...@gmail.com> on 2011/09/13 18:19:12 UTC

[CONFIGURATION] preserve mulitline property over load and save

Hi,

i have property values spanning multiple lines like

      value = aaa, \
                   bbb

When I load this into a PropertiesConfiguration and later store to a
file I can only achieve two results,

* having everything on one line like

     value = aaa,bbb

* or a mulitvalue property like

     value = aaa
     value = bbb

Is there a possiblity to tweak the PropertiesConfiguration so that it
preserves the original layout over a load/store cycle?

Thanks,
Wieland

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by Wieland Gmeiner <wi...@gmail.com>.
Thank you guys for the input. I see there are some ways to get this
into configurations, but none of them trivial. I will discuss this
with my customer if they are willing to spend time on this feature.

Regards,
Wieland


On Wed, Sep 14, 2011 at 10:07 PM, Oliver Heger
<ol...@oliver-heger.de> wrote:
> Am 14.09.2011 13:18, schrieb Wieland Gmeiner:
>>
>> On Wed, Sep 14, 2011 at 12:37 PM, sebb<se...@gmail.com>  wrote:
>>>
>>> On 14 September 2011 09:23, Wieland Gmeiner<wi...@gmail.com>
>>>  wrote:
>>>>
>>>> On Wed, Sep 14, 2011 at 1:15 AM, sebb<se...@gmail.com>  wrote:
>>>>>
>>>>> On 13 September 2011 23:19, Wieland Gmeiner<wi...@gmail.com>
>>>>>  wrote:
>>>>>>
>>>>>> On Wed, Sep 14, 2011 at 12:06 AM, sebb<se...@gmail.com>  wrote:
>>>>>>>
>>>>>>> On 13 September 2011 21:31, Oliver
>>>>>>> Heger<ol...@oliver-heger.de>  wrote:
>>>>>>>>>
>>>>>>>>> Is there a possiblity to tweak the PropertiesConfiguration so that
>>>>>>>>> it
>>>>>>>>> preserves the original layout over a load/store cycle?
>>>>>>>
>>>>>>> Why do you want to do this?
>>>>>>
>>>>>> Because I'm programmatically changing configuration files (e.g.
>>>>>> inserting additional properties) and it would be nice not to mess up
>>>>>> the layout of the original files. A sysadmin won't be pleased if some
>>>>>> update program changes the layout of his handcrafted config files. I
>>>>>> wouldn't.
>>>>>
>>>>> In that case, I think you are going to have to write your own output
>>>>> method.
>>>>>
>>>>> So long as you don't change any of the input settings, you should just
>>>>> be able to append the new ones to the end.
>>>>
>>>> I also have to change values of already existing properties, so
>>>> appending only is not a choice.
>>>
>>> Fixing property values in place is going to be a lot harder in general.
>>>
>>> As already noted, the original formatting is dropped when the file is
>>> loaded.
>>> But even if the format were retained, it's still tricky to rewrite the
>>> file with the new values if spacing is significant.
>>> What if the new values are longer or shorter? Should spacing be adjusted?
>>> If the original property has a single value, and another value is
>>> added, should this be on the same line or the next?
>>> And what spacing should be used?
>>>
>>> Try writing down the rules for updating the file assuming that the
>>> person doing it has no knowledge of what the format is trying to
>>> achieve.
>>
>> I know it's hard, because I tried to do that for xml and properties
>> with the Java SE alone. While handling the "real" work (i.e. merging
>> nodes/properties) is not so hard, the layout problem was driving me
>> nuts, thats why I started to search some library where someone already
>> solved that problem for me. But it seems that will remain on the todo
>> list at the moment.
>
> A possible approach could be to extend PropertiesConfigurationLayout to
> store the unprocessed property values. (This is similar to what sebb had
> already suggested.) It should be feasible to extend the special properties
> reader class so that it can provide the original data.
>
> As long as property values are not changed, the original layout of the file
> could be retained (at least to a better degree).
> PropertiesConfigurationLayout uses a linked hash map to store its data so
> the order is also kept. (IIRC multiple occurrences of properties are an
> exception, they are always grouped together.)
>
> If there are really specific needs for formatting property values, maybe the
> layout object could be extended to provide a method for setting a formatted
> property value.
>
> But all of this is not trivial and will also increase memory consumption. So
> it should be possible to disable this feature if it is not needed (or maybe
> even disabled per default).
>
> Just some thoughts - I am still unsure whether this is worth the effort.
>
> Oliver
>
>>
>>>> Btw, for appending only I don't need configurations at all.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by Oliver Heger <ol...@oliver-heger.de>.
Am 14.09.2011 13:18, schrieb Wieland Gmeiner:
> On Wed, Sep 14, 2011 at 12:37 PM, sebb<se...@gmail.com>  wrote:
>> On 14 September 2011 09:23, Wieland Gmeiner<wi...@gmail.com>  wrote:
>>> On Wed, Sep 14, 2011 at 1:15 AM, sebb<se...@gmail.com>  wrote:
>>>> On 13 September 2011 23:19, Wieland Gmeiner<wi...@gmail.com>  wrote:
>>>>> On Wed, Sep 14, 2011 at 12:06 AM, sebb<se...@gmail.com>  wrote:
>>>>>> On 13 September 2011 21:31, Oliver Heger<ol...@oliver-heger.de>  wrote:
>>>>>>>> Is there a possiblity to tweak the PropertiesConfiguration so that it
>>>>>>>> preserves the original layout over a load/store cycle?
>>>>>>
>>>>>> Why do you want to do this?
>>>>>
>>>>> Because I'm programmatically changing configuration files (e.g.
>>>>> inserting additional properties) and it would be nice not to mess up
>>>>> the layout of the original files. A sysadmin won't be pleased if some
>>>>> update program changes the layout of his handcrafted config files. I
>>>>> wouldn't.
>>>>
>>>> In that case, I think you are going to have to write your own output method.
>>>>
>>>> So long as you don't change any of the input settings, you should just
>>>> be able to append the new ones to the end.
>>>
>>> I also have to change values of already existing properties, so
>>> appending only is not a choice.
>>
>> Fixing property values in place is going to be a lot harder in general.
>>
>> As already noted, the original formatting is dropped when the file is loaded.
>> But even if the format were retained, it's still tricky to rewrite the
>> file with the new values if spacing is significant.
>> What if the new values are longer or shorter? Should spacing be adjusted?
>> If the original property has a single value, and another value is
>> added, should this be on the same line or the next?
>> And what spacing should be used?
>>
>> Try writing down the rules for updating the file assuming that the
>> person doing it has no knowledge of what the format is trying to
>> achieve.
>
> I know it's hard, because I tried to do that for xml and properties
> with the Java SE alone. While handling the "real" work (i.e. merging
> nodes/properties) is not so hard, the layout problem was driving me
> nuts, thats why I started to search some library where someone already
> solved that problem for me. But it seems that will remain on the todo
> list at the moment.

A possible approach could be to extend PropertiesConfigurationLayout to 
store the unprocessed property values. (This is similar to what sebb had 
already suggested.) It should be feasible to extend the special 
properties reader class so that it can provide the original data.

As long as property values are not changed, the original layout of the 
file could be retained (at least to a better degree). 
PropertiesConfigurationLayout uses a linked hash map to store its data 
so the order is also kept. (IIRC multiple occurrences of properties are 
an exception, they are always grouped together.)

If there are really specific needs for formatting property values, maybe 
the layout object could be extended to provide a method for setting a 
formatted property value.

But all of this is not trivial and will also increase memory 
consumption. So it should be possible to disable this feature if it is 
not needed (or maybe even disabled per default).

Just some thoughts - I am still unsure whether this is worth the effort.

Oliver

>
>>> Btw, for appending only I don't need configurations at all.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by Wieland Gmeiner <wi...@gmail.com>.
On Wed, Sep 14, 2011 at 12:37 PM, sebb <se...@gmail.com> wrote:
> On 14 September 2011 09:23, Wieland Gmeiner <wi...@gmail.com> wrote:
>> On Wed, Sep 14, 2011 at 1:15 AM, sebb <se...@gmail.com> wrote:
>>> On 13 September 2011 23:19, Wieland Gmeiner <wi...@gmail.com> wrote:
>>>> On Wed, Sep 14, 2011 at 12:06 AM, sebb <se...@gmail.com> wrote:
>>>>> On 13 September 2011 21:31, Oliver Heger <ol...@oliver-heger.de> wrote:
>>>>>>> Is there a possiblity to tweak the PropertiesConfiguration so that it
>>>>>>> preserves the original layout over a load/store cycle?
>>>>>
>>>>> Why do you want to do this?
>>>>
>>>> Because I'm programmatically changing configuration files (e.g.
>>>> inserting additional properties) and it would be nice not to mess up
>>>> the layout of the original files. A sysadmin won't be pleased if some
>>>> update program changes the layout of his handcrafted config files. I
>>>> wouldn't.
>>>
>>> In that case, I think you are going to have to write your own output method.
>>>
>>> So long as you don't change any of the input settings, you should just
>>> be able to append the new ones to the end.
>>
>> I also have to change values of already existing properties, so
>> appending only is not a choice.
>
> Fixing property values in place is going to be a lot harder in general.
>
> As already noted, the original formatting is dropped when the file is loaded.
> But even if the format were retained, it's still tricky to rewrite the
> file with the new values if spacing is significant.
> What if the new values are longer or shorter? Should spacing be adjusted?
> If the original property has a single value, and another value is
> added, should this be on the same line or the next?
> And what spacing should be used?
>
> Try writing down the rules for updating the file assuming that the
> person doing it has no knowledge of what the format is trying to
> achieve.

I know it's hard, because I tried to do that for xml and properties
with the Java SE alone. While handling the "real" work (i.e. merging
nodes/properties) is not so hard, the layout problem was driving me
nuts, thats why I started to search some library where someone already
solved that problem for me. But it seems that will remain on the todo
list at the moment.

>> Btw, for appending only I don't need configurations at all.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by sebb <se...@gmail.com>.
On 14 September 2011 09:23, Wieland Gmeiner <wi...@gmail.com> wrote:
> On Wed, Sep 14, 2011 at 1:15 AM, sebb <se...@gmail.com> wrote:
>> On 13 September 2011 23:19, Wieland Gmeiner <wi...@gmail.com> wrote:
>>> On Wed, Sep 14, 2011 at 12:06 AM, sebb <se...@gmail.com> wrote:
>>>> On 13 September 2011 21:31, Oliver Heger <ol...@oliver-heger.de> wrote:
>>>>>> Is there a possiblity to tweak the PropertiesConfiguration so that it
>>>>>> preserves the original layout over a load/store cycle?
>>>>
>>>> Why do you want to do this?
>>>
>>> Because I'm programmatically changing configuration files (e.g.
>>> inserting additional properties) and it would be nice not to mess up
>>> the layout of the original files. A sysadmin won't be pleased if some
>>> update program changes the layout of his handcrafted config files. I
>>> wouldn't.
>>
>> In that case, I think you are going to have to write your own output method.
>>
>> So long as you don't change any of the input settings, you should just
>> be able to append the new ones to the end.
>
> I also have to change values of already existing properties, so
> appending only is not a choice.

Fixing property values in place is going to be a lot harder in general.

As already noted, the original formatting is dropped when the file is loaded.
But even if the format were retained, it's still tricky to rewrite the
file with the new values if spacing is significant.
What if the new values are longer or shorter? Should spacing be adjusted?
If the original property has a single value, and another value is
added, should this be on the same line or the next?
And what spacing should be used?

Try writing down the rules for updating the file assuming that the
person doing it has no knowledge of what the format is trying to
achieve.

> Btw, for appending only I don't need configurations at all.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by Wieland Gmeiner <wi...@gmail.com>.
On Wed, Sep 14, 2011 at 1:15 AM, sebb <se...@gmail.com> wrote:
> On 13 September 2011 23:19, Wieland Gmeiner <wi...@gmail.com> wrote:
>> On Wed, Sep 14, 2011 at 12:06 AM, sebb <se...@gmail.com> wrote:
>>> On 13 September 2011 21:31, Oliver Heger <ol...@oliver-heger.de> wrote:
>>>>> Is there a possiblity to tweak the PropertiesConfiguration so that it
>>>>> preserves the original layout over a load/store cycle?
>>>
>>> Why do you want to do this?
>>
>> Because I'm programmatically changing configuration files (e.g.
>> inserting additional properties) and it would be nice not to mess up
>> the layout of the original files. A sysadmin won't be pleased if some
>> update program changes the layout of his handcrafted config files. I
>> wouldn't.
>
> In that case, I think you are going to have to write your own output method.
>
> So long as you don't change any of the input settings, you should just
> be able to append the new ones to the end.

I also have to change values of already existing properties, so
appending only is not a choice.
Btw, for appending only I don't need configurations at all.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by sebb <se...@gmail.com>.
On 13 September 2011 23:19, Wieland Gmeiner <wi...@gmail.com> wrote:
> On Wed, Sep 14, 2011 at 12:06 AM, sebb <se...@gmail.com> wrote:
>> On 13 September 2011 21:31, Oliver Heger <ol...@oliver-heger.de> wrote:
>>>> Is there a possiblity to tweak the PropertiesConfiguration so that it
>>>> preserves the original layout over a load/store cycle?
>>
>> Why do you want to do this?
>
> Because I'm programmatically changing configuration files (e.g.
> inserting additional properties) and it would be nice not to mess up
> the layout of the original files. A sysadmin won't be pleased if some
> update program changes the layout of his handcrafted config files. I
> wouldn't.

In that case, I think you are going to have to write your own output method.

So long as you don't change any of the input settings, you should just
be able to append the new ones to the end.

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by Wieland Gmeiner <wi...@gmail.com>.
On Wed, Sep 14, 2011 at 12:06 AM, sebb <se...@gmail.com> wrote:
> On 13 September 2011 21:31, Oliver Heger <ol...@oliver-heger.de> wrote:
>>> Is there a possiblity to tweak the PropertiesConfiguration so that it
>>> preserves the original layout over a load/store cycle?
>
> Why do you want to do this?

Because I'm programmatically changing configuration files (e.g.
inserting additional properties) and it would be nice not to mess up
the layout of the original files. A sysadmin won't be pleased if some
update program changes the layout of his handcrafted config files. I
wouldn't.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by sebb <se...@gmail.com>.
On 13 September 2011 21:31, Oliver Heger <ol...@oliver-heger.de> wrote:
> Hi Wieland,
>
> Am 13.09.2011 18:19, schrieb Wieland Gmeiner:
>>
>> Hi,
>>
>> i have property values spanning multiple lines like
>>
>>       value = aaa, \
>>                    bbb
>>
>> When I load this into a PropertiesConfiguration and later store to a
>> file I can only achieve two results,
>>
>> * having everything on one line like
>>
>>      value = aaa,bbb
>>
>> * or a mulitvalue property like
>>
>>      value = aaa
>>      value = bbb
>>
>> Is there a possiblity to tweak the PropertiesConfiguration so that it
>> preserves the original layout over a load/store cycle?

Why do you want to do this?

> unfortunately, there is no such possibility currently. When the properties
> file is read the backslash as line combiner is processed, and the value is
> stored without any information about a line break.
>
> I fear that implementing such a feature would not be trivial. You would
> probably have to invent a format which tells the configuration that a
> property should span multiple lines, but the line break character must not
> be mixed up with regular content of the property value.
>
> If you have concrete ideas how to solve this, you might want to open a
> feature request in our bug tracking system [1].

It would be quite easy to save all multi-valued properties with \ and
line-break between values (as 3rd option), but that would not
necessarily preserve the exact original format.

And of course the order would almost certainly be different.

> Oliver
>
> [1] http://commons.apache.org/configuration/issue-tracking.html
>
>>
>> Thanks,
>> Wieland
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [CONFIGURATION] preserve mulitline property over load and save

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Wieland,

Am 13.09.2011 18:19, schrieb Wieland Gmeiner:
> Hi,
>
> i have property values spanning multiple lines like
>
>        value = aaa, \
>                     bbb
>
> When I load this into a PropertiesConfiguration and later store to a
> file I can only achieve two results,
>
> * having everything on one line like
>
>       value = aaa,bbb
>
> * or a mulitvalue property like
>
>       value = aaa
>       value = bbb
>
> Is there a possiblity to tweak the PropertiesConfiguration so that it
> preserves the original layout over a load/store cycle?

unfortunately, there is no such possibility currently. When the 
properties file is read the backslash as line combiner is processed, and 
the value is stored without any information about a line break.

I fear that implementing such a feature would not be trivial. You would 
probably have to invent a format which tells the configuration that a 
property should span multiple lines, but the line break character must 
not be mixed up with regular content of the property value.

If you have concrete ideas how to solve this, you might want to open a 
feature request in our bug tracking system [1].

Oliver

[1] http://commons.apache.org/configuration/issue-tracking.html

>
> Thanks,
> Wieland
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org