commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Robinson <est.ergo....@gmail.com>
Subject Re: [Configuration] Call me a moron, but I just can't make it work!
Date Tue, 15 Jul 2008 10:37:43 GMT
Hello again,

I've spent some time with the test class, and managed to get to the  
data I need.

I still don't have any idea how to use  
"config.getProperty("stringleadingtoproperty")" though.

And thus, I suspect I will be unable to use  
"config.setProperty("stringleadingtoproperty", "newproperty")"...

This is what I used to find the data I need:

***CODE***

public void testNestedArray()
     {
         String key = "SandwichFillings";

         Object array = config.getProperty(key);

         // root array
         assertNotNull("array not found", array);
         ObjectAssert.assertInstanceOf("the array element is not  
parsed as a List", List.class, array);
         List list = config.getList(key);

         System.out.println(list.size());

         assertFalse("empty array", list.isEmpty());
         assertEquals("size", 1, list.size());

         XMLPropertyListConfiguration o  =  
(XMLPropertyListConfiguration) list.get(0);

         Iterator k = o.getKeys();

         while(k.hasNext()){

             key = (String) k.next();

             if(o.getProperty(key) instanceof String){
                 System.out.println(o.getString(key));
             }
             System.out.println();
         }

     }

***/CODE***

Output is:

***OUTPUT***

1
self
html
Original
High
Default
SIDE TITLE
utf-8

***/OUTPUT***

When I saw that I almost cried, I was so happy.

So my question now is, what string would one use to access SIDETITLE  
directly?

It is in a Dictionary, which is in an Array - the property of  
SandwichFillings.

I've tried a few strings, but I don't really know the syntax, or what  
is possible so it's like stumbling around in the dark.

Could someone please let me know how I am able to 1) access this data,  
2) change the value.

Thank you for your time and patience,

Mike

All animals are equal but some animals are more equal than others.
	-- George Orwell (1903 - 1950), "Animal Farm"

On 15/07/2008, at 7:40 AM, Oliver Heger wrote:

> simon.kitching@chello.at schrieb:
>> Michael Robinson schrieb:
>>> Hi,
>>>
>>> I'm writing a program that must load, search, edit and save Mac OS  
>>> X plist files.
>>>
>>> I was attempting to use apple's NS* foundation classes, but I  
>>> couldn't work out how to write to the plist files (maybe I'm just  
>>> stupid).
>>>
>>> I searched around the internet and was overjoyed to find  
>>> apache.commons.configuration.
>>>
>>> I've played with it for the past few days, trying to figure out  
>>> how I'm meant to get data out of the plist files I'm working with.
>> Have you looked at the unit tests for the configuration project?
>> Commons projects generally have pretty good unit test coverage,  
>> which means that there is almost certainly an example of reading  a  
>> plist file and extracting a value from it in there somewhere.
>> In general, the unit tests for a project are a good source of  
>> examples when the explicit user examples and tutorials don't cover  
>> what you need to do.
>> The unit tests can be fetched from the Apache subversion system  
>> using the url that is in the left-hand navigation bar.
>> Regards,
>> Simon
>
> You can find the test class for XMLPropertyListConfiguration at [1].  
> It reads a test file [2] and evaluates the properties contained.
>
> I assume your concrete problem is due to the fact that the value of  
> the "SandwichFillings" key is an array, which obviously complicates  
> things. Have a look at the testNestedArray() method in [1], which  
> deals with nested arrays.
>
> Querying the value of an array should result in a List. You can dump  
> the content of this list to see how it is structured.
>
> HTH
> Oliver
>
> [1] http://svn.apache.org/repos/asf/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
> [2] http://svn.apache.org/repos/asf/commons/proper/configuration/trunk/conf/test.plist.xml
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message