You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Raymond, Brian" <br...@echostorm.net> on 2007/02/12 22:59:51 UTC

[Commons Configuration] using setProperty for element on XML plist

I have been banging my head against the wall for hours trying to  
write a <data/> element back into an OSX XML plist file. I use the  
following to successfully read the element:

byte[] tmpByte = (byte[])settings.getProperty("node.name")

I then modify it but I cannot for the life of me figure out how to  
cast it and write it back into the file using setProperty(). I'm at  
the point where I Base64 encode it and write it out as a string but I  
cannot get it back into <data>.  I have looked through the junit  
tests, javadocs and online and the closest thing I found was a nested  
class with an addDataValue() method that looks like it's built for  
this but it warns that it's for internal use by the digester.

Thanks for reading, if anyone can provide a pointer I would be grateful.

Thanks,

- Brian

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


Re: [Commons Configuration] using setProperty for element on XML plist

Posted by Oliver Heger <ol...@oliver-heger.de>.
Emmanuel Bourg wrote:
> Oliver Heger a écrit :
> 
>> Okay, I will have a look and write test cases for the events. From a 
>> first glance it seems that CLEAR_PROPERTY and AND_PROPERTY events are 
>> thrown instead of a SET_PROPERTY event.
> 
> Thank you. Is there a mechanism to disable the clear and add events ?
> 
Done. Yes, with a call to setDetailEvents(false) nested events can be 
disabled. As it is implemented now, the setProperty() method triggers 
only SET_PROPERTY events.

Oliver

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


Re: [Commons Configuration] using setProperty for element on XML plist

Posted by Emmanuel Bourg <eb...@apache.org>.
Oliver Heger a écrit :

> Okay, I will have a look and write test cases for the events. From a 
> first glance it seems that CLEAR_PROPERTY and AND_PROPERTY events are 
> thrown instead of a SET_PROPERTY event.

Thank you. Is there a mechanism to disable the clear and add events ?


> I haven't looked into this issue in detail, but wouldn't the 
> addProperty() methods be affected, too?

I think so, I haven't tested this case yet.

Emmanuel Bourg

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


Re: [Commons Configuration] using setProperty for element on XML plist

Posted by Oliver Heger <ol...@oliver-heger.de>.
Emmanuel Bourg wrote:
> Oliver Heger a écrit :
> 
>> I haven't used XMLPropertyListConfiguration myself. But from a short 
>> glance at the code I fear that there could be a bug related to the 
>> handling of arrays. What exactly is the result when you call 
>> setProperty() with the modified byte[]?
> 
> I commited a fix for this bug, it affected both plist configurations.
> 
> Oliver could you review my change please ? I'm not familiar with the new 
> event notification stuff, I don't know if the right events are fired 
> with this fix.
> 
> Emmanuel Bourg
> 
Okay, I will have a look and write test cases for the events. From a 
first glance it seems that CLEAR_PROPERTY and AND_PROPERTY events are 
thrown instead of a SET_PROPERTY event.

I haven't looked into this issue in detail, but wouldn't the 
addProperty() methods be affected, too?

Oliver

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


Re: [Commons Configuration] using setProperty for element on XML plist

Posted by Emmanuel Bourg <eb...@apache.org>.
Oliver Heger a écrit :

> I haven't used XMLPropertyListConfiguration myself. But from a short 
> glance at the code I fear that there could be a bug related to the 
> handling of arrays. What exactly is the result when you call 
> setProperty() with the modified byte[]?

I commited a fix for this bug, it affected both plist configurations.

Oliver could you review my change please ? I'm not familiar with the new 
event notification stuff, I don't know if the right events are fired 
with this fix.

Emmanuel Bourg


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


Re: [Commons Configuration] using setProperty for element on XML plist

Posted by Emmanuel Bourg <eb...@apache.org>.
Oliver Heger a écrit :

> I haven't used XMLPropertyListConfiguration myself. But from a short 
> glance at the code I fear that there could be a bug related to the 
> handling of arrays. What exactly is the result when you call 
> setProperty() with the modified byte[]?

I reproduced this issue, a byte[] is transformed into a list of integers 
by HierarchicalConfiguration.setProperty(). This code :

     FileConfiguration config = new XMLPropertyListConfiguration();
     config.setProperty("foo", new byte[] { 1, 2, 3, 4 });
     config.save("config.plist");

generates this :

<plist version="1.0">
     <dict>
         <key>foo</key>
         <integer>1</integer>

         <key>foo</key>
         <integer>2</integer>

         <key>foo</key>
         <integer>3</integer>

         <key>foo</key>
         <integer>4</integer>
     </dict>
</plist>

instead of

<plist version="1.0">
     <dict>
         <key>foo</key>
         <data>01020304</data>
     </dict>
</plist>

I don't know how to fix this easily. Maybe by adding a flag in 
HierarchicalConfiguration to prevent the arrays from being split into a 
list of nodes ?

Emmanuel Bourg


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


Re: [Commons Configuration] using setProperty for element on XML plist

Posted by Oliver Heger <ol...@oliver-heger.de>.
Raymond, Brian wrote:
> I have been banging my head against the wall for hours trying to write a 
> <data/> element back into an OSX XML plist file. I use the following to 
> successfully read the element:
> 
> byte[] tmpByte = (byte[])settings.getProperty("node.name")
> 
> I then modify it but I cannot for the life of me figure out how to cast 
> it and write it back into the file using setProperty(). I'm at the point 
> where I Base64 encode it and write it out as a string but I cannot get 
> it back into <data>.  I have looked through the junit tests, javadocs 
> and online and the closest thing I found was a nested class with an 
> addDataValue() method that looks like it's built for this but it warns 
> that it's for internal use by the digester.
> 
> Thanks for reading, if anyone can provide a pointer I would be grateful.
> 
> Thanks,
> 
> - Brian
> 
Brian,

I haven't used XMLPropertyListConfiguration myself. But from a short 
glance at the code I fear that there could be a bug related to the 
handling of arrays. What exactly is the result when you call 
setProperty() with the modified byte[]?

Oliver

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