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 02:58:25 GMT

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


Mime
View raw message