You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Michael Robinson <es...@gmail.com> on 2008/07/15 22:40:45 UTC

[Commons Configuration] Just One More Thing!

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

One thing is for sure, Vista isn’t the answer.
	— Posted by Fenton 
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org