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/14 16:02:16 UTC

[Configuration] Call me a moron, but I just can't make it work!

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.

So far, nothing I've tried has worked:

***CODE***

XMLPropertyListConfiguration sigh = new  
XMLPropertyListConfiguration(plistPath);

            sigh.load();

             
System.out.println(sigh.containsKey("SandwichFillings"));	//this  
prints "true" - great!

	//What I actually want, is the "SidebarTitle" string.  When I try:

sigh.containsKey("SidebarTitle");

//or

sigh.containsKey("SandwichFillings.Dictionary.SidebarTitle");

//or any other combination that I could think of - I get false.

***/CODE***

If I save the file with a different name, I can open it and see that  
the information has all been copied correctly.

I just haven't been able to figure out how to access/edit information  
in the file.

For the past two days I've been trawling the internet and trying  
everything I could think of, but I am yet to succeed.

Is what I want to do even possible?  If so, please tell me how!   
Please!  It's been driving me insane.

This is an example of the files I'll be reading (currently I want to  
get key = SidebarTitle, and change its value).

***PLIST FILE***

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd 
">
<plist version="1.0">
<dict>
	<key>SandwichFillings</key>
	<array>
		<dict>
			<key>Dictionary</key>
			<dict>
			
				<key>Changed</key>
				<true/>
				
				<key>ColourStyles</key>
				<dict/>
				
				<key>CreditRapidWeaver</key>
				<true/>
				
				<key>CustomCopyrightUsed</key>
				<false/>
				
				<key>CustomSiteTitleUsed</key>
				<false/>
				
				<key>CustomSloganUsed</key>
				<false/>
				
				<key>DefaultLinkTarget</key>
				<string>self</string>
				
				<key>FilenameExtension</key>
				<string>html</string>
				
				<key>HasCustomThemeStyle</key>
				<true/>
				
				<key>ImageFormat</key>
				<string>Original</string>
				
				<key>ImageQuality</key>
				<string>High</string>
				
				<key>IndexFilename</key>
				<string></string>
				
				<key>OutputFormat</key>
				<string>Default</string>
				
				<key>OutputXMLDeclaration</key>
				<false/>
				
				<key>SidebarEnabled</key>
				<integer>1</integer>
				
				<key>SidebarTitle</key>
				<string>SIDE TITLE</string>
				
				<key>TextEncoding</key>
				<string>utf-8</string>
			</dict>
			<key>Files</key>
			<array>
				<string>Sidebar.as</string>
			</array>
			<key>Subsandwiches</key>
			<array/>
		</dict>
	</array>
	<key>Type</key>
	<string>Page Attributes</string>
</dict>
</plist>

***/PLIST FILE***

I'm using Netbeans 6.01 with Mavenide, Maven2.  I get no errors at  
compile time, no error during my attempts to get the key/value (unless  
one counts "null" when you know it's damn-well there as an error!).

Thank you for taking the time to read my message,

Mike

-	-	-
Everything is gone;
Your life's work has been destroyed.
Squeeze trigger (yes/no)?
-	-	-
David Carlson

Re: [Configuration] Call me a moron, but I just can't make it work!

Posted by Ralph Goers <Ra...@dslextreme.com>.
Your problem is that you are searching for the value of an element, not 
the element name, i.e. there are no elements named SndwichFillings, 
Dictionary or SidebarTitle. Your element names are all named "key".  I 
can never remember how to filter based on the value of an element of a 
key using the default expression language. With XML I use the XPath 
expression lanaguage.

Michael Robinson wrote:
> 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.
>
> So far, nothing I've tried has worked:
>
> ***CODE***
>
> XMLPropertyListConfiguration sigh = new 
> XMLPropertyListConfiguration(plistPath);
>
>            sigh.load();
>
>            
> System.out.println(sigh.containsKey("SandwichFillings"));    //this 
> prints "true" - great!
>
>     //What I actually want, is the "SidebarTitle" string.  When I try:
>
> sigh.containsKey("SidebarTitle");
>
> //or
>
> sigh.containsKey("SandwichFillings.Dictionary.SidebarTitle");
>
> //or any other combination that I could think of - I get false.
>
> ***/CODE***
>
> If I save the file with a different name, I can open it and see that 
> the information has all been copied correctly.
>
> I just haven't been able to figure out how to access/edit information 
> in the file.
>
> For the past two days I've been trawling the internet and trying 
> everything I could think of, but I am yet to succeed.
>
> Is what I want to do even possible?  If so, please tell me how!  
> Please!  It's been driving me insane.
>
> This is an example of the files I'll be reading (currently I want to 
> get key = SidebarTitle, and change its value).
>
> ***PLIST FILE***
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
> <plist version="1.0">
> <dict>
>     <key>SandwichFillings</key>
>     <array>
>         <dict>
>             <key>Dictionary</key>
>             <dict>
>            
>                 <key>Changed</key>
>                 <true/>
>                
>                 <key>ColourStyles</key>
>                 <dict/>
>                
>                 <key>CreditRapidWeaver</key>
>                 <true/>
>                
>                 <key>CustomCopyrightUsed</key>
>                 <false/>
>                
>                 <key>CustomSiteTitleUsed</key>
>                 <false/>
>                
>                 <key>CustomSloganUsed</key>
>                 <false/>
>                
>                 <key>DefaultLinkTarget</key>
>                 <string>self</string>
>                
>                 <key>FilenameExtension</key>
>                 <string>html</string>
>                
>                 <key>HasCustomThemeStyle</key>
>                 <true/>
>                
>                 <key>ImageFormat</key>
>                 <string>Original</string>
>                
>                 <key>ImageQuality</key>
>                 <string>High</string>
>                
>                 <key>IndexFilename</key>
>                 <string></string>
>                
>                 <key>OutputFormat</key>
>                 <string>Default</string>
>                
>                 <key>OutputXMLDeclaration</key>
>                 <false/>
>                
>                 <key>SidebarEnabled</key>
>                 <integer>1</integer>
>                
>                 <key>SidebarTitle</key>
>                 <string>SIDE TITLE</string>
>                
>                 <key>TextEncoding</key>
>                 <string>utf-8</string>
>             </dict>
>             <key>Files</key>
>             <array>
>                 <string>Sidebar.as</string>
>             </array>
>             <key>Subsandwiches</key>
>             <array/>
>         </dict>
>     </array>
>     <key>Type</key>
>     <string>Page Attributes</string>
> </dict>
> </plist>
>
> ***/PLIST FILE***
>
> I'm using Netbeans 6.01 with Mavenide, Maven2.  I get no errors at 
> compile time, no error during my attempts to get the key/value (unless 
> one counts "null" when you know it's damn-well there as an error!).
>
> Thank you for taking the time to read my message,
>
> Mike
>
> -    -    -
> Everything is gone;
> Your life's work has been destroyed.
> Squeeze trigger (yes/no)?
> -    -    -
> David Carlson

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


Re: [Configuration] Call me a moron, but I just can't make it work!

Posted by Michael Robinson <es...@gmail.com>.
I wouldn't say Jamie is a evil genius. I'm not sure he's evil, and I'm  
not sure he's a genius
	-- Adam Savage

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
>

Hi Oliver, thanks again for that!

I've got both of the files, and set them up in Netbeans.

When I run the TestXMLPropertyListConfiguration.java file, as below, I  
get the following output:

...

  TestXMLPropertyListConfiguration test = new  
TestXMLPropertyListConfiguration();

   test.setUp();

...

Which runs:

...

  protected void setUp() throws Exception
     {

         config = new XMLPropertyListConfiguration();
         config.setFileName("/Users/faceleg/Downloads/ 
test.plist.xml");	//this is where I've put the file for now
         config.load();

     }

...

***OUTPUT***

Jul 15, 2008 2:53:42 PM  
com.bupa.RWFindReplace.pageSidebarPlistProcessor <init>
SEVERE: null
org.apache.commons.configuration.ConfigurationException: Unable to  
parse the configuration file
         at  
com 
.bupa 
.RWFindReplace 
.XMLPropertyListConfiguration.load(XMLPropertyListConfiguration.java: 
247)
         at  
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration 
$ 
FileConfigurationDelegate 
.load(AbstractHierarchicalFileConfiguration.java:443)
         at  
org 
.apache 
.commons 
.configuration 
.AbstractFileConfiguration.load(AbstractFileConfiguration.java:356)
         at  
org 
.apache 
.commons 
.configuration 
.AbstractFileConfiguration.load(AbstractFileConfiguration.java:322)
         at  
org 
.apache 
.commons 
.configuration 
.AbstractFileConfiguration.load(AbstractFileConfiguration.java:285)
         at  
org 
.apache 
.commons 
.configuration 
.AbstractFileConfiguration.load(AbstractFileConfiguration.java:217)
         at  
org 
.apache 
.commons 
.configuration 
.AbstractFileConfiguration.load(AbstractFileConfiguration.java:195)
         at  
org 
.apache 
.commons 
.configuration 
.AbstractHierarchicalFileConfiguration 
.load(AbstractHierarchicalFileConfiguration.java:164)
         at  
com 
.bupa 
.RWFindReplace 
.TestXMLPropertyListConfiguration 
.setUp(TestXMLPropertyListConfiguration.java:54)
         at  
com 
.bupa 
.RWFindReplace 
.pageSidebarPlistProcessor.<init>(pageSidebarPlistProcessor.java:32)
         at  
com.bupa.RWFindReplace.pageSidebar.setSidebar(pageSidebar.java:35)
         at  
com.bupa.RWFindReplace.pageTemplate.setSidebar(pageTemplate.java:31)
         at  
com.bupa.RWFindReplace.pageYHACPlugin.<init>(pageYHACPlugin.java:33)
         at  
com.bupa.RWFindReplace.RWRWProcessor.processPage(RWRWProcessor.java:147)
         at  
com 
.bupa.RWFindReplace.RWRWProcessor.processFileList(RWRWProcessor.java: 
113)
         at  
com.bupa.RWFindReplace.RWRWProcessor.processor(RWRWProcessor.java:37)
         at com.bupa.RWFindReplace.App.loadFile(App.java:586)
         at  
com.bupa.RWFindReplace.App.ChooseFileButtonMouseClicked(App.java:455)
         at com.bupa.RWFindReplace.App.access$000(App.java:23)
         at com.bupa.RWFindReplace.App$1.mouseClicked(App.java:121)
         at  
java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
         at java.awt.Component.processMouseEvent(Component.java:5605)
         at javax.swing.JComponent.processMouseEvent(JComponent.java: 
3135)
         at java.awt.Component.processEvent(Component.java:5367)
         at java.awt.Container.processEvent(Container.java:2010)
         at java.awt.Component.dispatchEventImpl(Component.java:4068)
         at java.awt.Container.dispatchEventImpl(Container.java:2068)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at  
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
         at  
java.awt.LightweightDispatcher.processMouseEvent(Container.java:3945)
         at  
java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
         at java.awt.Container.dispatchEventImpl(Container.java:2054)
         at java.awt.Window.dispatchEventImpl(Window.java:1791)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at  
java 
.awt 
.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java: 
269)
         at  
java 
.awt 
.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java: 
190)
         at  
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
         at  
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java: 
110)
Caused by: java.lang.NumberFormatException: For input string:  
"12345678900"
         at  
java 
.lang.NumberFormatException.forInputString(NumberFormatException.java: 
48)
         at java.lang.Integer.parseInt(Integer.java:459)
         at java.lang.Integer.<init>(Integer.java:620)
         at com.bupa.RWFindReplace.XMLPropertyListConfiguration 
$PListNode.addIntegerValue(XMLPropertyListConfiguration.java:627)
         at com.bupa.RWFindReplace.XMLPropertyListConfiguration 
$XMLPropertyListHandler.endElement(XMLPropertyListConfiguration.java: 
503)
         at  
org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
         at  
org.apache.xerces.impl.dtd.XMLDTDValidator.endNamespaceScope(Unknown  
Source)
         at  
org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown  
Source)
         at  
org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
         at  
org 
.apache 
.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown  
Source)
         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl 
$FragmentContentDispatcher.dispatch(Unknown Source)
         at  
org 
.apache 
.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown  
Source)
         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown  
Source)
         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
         at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown  
Source)
         at  
com 
.bupa 
.RWFindReplace 
.XMLPropertyListConfiguration.load(XMLPropertyListConfiguration.java: 
243)
         ... 39 more

***/OUTPUT***

Thanks again for your help, I'm not sure what I've done wrong here!

Mike

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


Re: [Configuration] Call me a moron, but I just can't make it work!

Posted by Michael Robinson <es...@gmail.com>.
Thank you all very much for your swift and helpful replies, I'll  
investigate the unit tests after breakfast, I'm sure they're just what  
I needed.

Mike

The future belongs to those who prepare for it today.
	-- Malcolm X (1925 - 1965)

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


Re: [Configuration] Call me a moron, but I just can't make it work!

Posted by Michael Robinson <es...@gmail.com>.
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


Re: [Configuration] Call me a moron, but I just can't make it work!

Posted by Michael Robinson <es...@gmail.com>.
WAR IS PEACE
FREEDOM IS SLAVERY
IGNORANCE IS STRENGTH
	-- George Orwell (1903 - 1950), "1984"

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
>

I've removed that line from the plist.xml file, and it loads now.

I should be able to learn enough from the test methods now, I don't  
need that line.

Again, thank you very much!


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


Re: [Configuration] Call me a moron, but I just can't make it work!

Posted by Oliver Heger <ol...@oliver-heger.de>.
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


Re: [Configuration] Call me a moron, but I just can't make it work!

Posted by "simon.kitching@chello.at" <si...@chello.at>.
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


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