commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <craig...@gmail.com>
Subject Re: Question About Digester
Date Thu, 02 Sep 2004 04:32:58 GMT
In addition to Simon's comments, the XML you're trying to parse looks
suspiciously like the metadata used to define JNDI resources in a
Tomcat server.xml file :-).  If that's what you are really trying to
do, it would be worth downloading the Tomcat source code, and looking
at the Digester rules that Tomcat itself uses to parse this file (in
package org.apache.catalina.startup).  You might get some helpful
ideas for your own use.

Craig

On Wed,  1 Sep 2004 06:12:46 -0700, Andrew Steiger
<andrew@andrewsteiger.com> wrote:
> Hello everyone,
> 
> I am trying to use Digester to load a Properties object from an XML file.  When
> I run the parse method off of the Digester object, the Object that is returned
> doesn't have anything in it.  I am not sure if this is a bug or that I am
> missing something in the implementation.  Here is my code:
> 
> //create digester based on the rules
> digester = DigesterLoader.createDigester(rulesUrl);
> 
> //add properties to object stack --
> //this is so you can get the properties object that was created
> digester.push(result);
> 
> //parse xml files against rules
> result = (Stack)digester.parse(propertiesXml);
> 
> //get properties object
> props = (Properties)result.pop();
> -----------------------
> 
> My rules xml files looks like this:
> 
> <digester-rules>
>         <pattern value="NamingResources">
>                 <!--create a Stack object to hold a reference to the Properties object
created
> in the 'ResourceParams' pattern -->
>                 <object-create-rule classname="java.util.Stack"/>
> 
>                 <pattern value="ResourceParams">
>                         <!-- instantiate a Properties object -->
>                         <object-create-rule classname="java.util.Properties"/>
> 
>                         <!-- each parameter node is a key-value pair in the Properties
object -->
>                         <pattern value="parameter">
>                                 <!-- call the 'setProperty' method -->
>                                 <call-method-rule methodname="setProperty" paramcount="2"/>
>                                 <call-param-rule pattern="name" paramnumber="0"/>
>                                 <call-param-rule pattern="value" paramnumber="1"/>
>                         </pattern>
> 
>                         <!-- push the Properties object created onto the Stack object
-->
>                         <set-next-rule methodname="push" />
>                 </pattern>
>         </pattern>
> </digester-rules>
> -----------------------
> 
> The following excepts from the log generated so that all the pieces seem to be
> functioning:
> 
> 2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester  - Popping params
> 2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester  -
> [CallMethodRule](0)testWhileIdle
> 2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester  -
> [CallMethodRule](1)false
> 2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester  -
> [CallMethodRule]{NamingResources/ResourceParams/parameter} Call
> java.util.Properties.setProperty(testWhileIdle/java.lang.String,false/java.lang.String)
> 2004/08/31 17:48:01 DEBUG org.apache.commons.beanutils.MethodUtils  - Matching
> name=setProperty on class java.util.Properties
> 2004/08/31 17:48:01 DEBUG org.apache.commons.beanutils.MethodUtils  - Found
> straight match: public synchronized java.lang.Object
> java.util.Properties.setProperty(java.lang.String,java.lang.String)
> 2004/08/31 17:48:01 DEBUG org.apache.commons.beanutils.MethodUtils  -
> isPublic:true
> 
> ...
> 
> 2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils  - Matching
> name=push on class java.util.Stack
> 2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils  - Found
> matching name:
> 2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils  - public
> java.lang.Object java.util.Stack.push(java.lang.Object)
> 2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils  -
> Param=java.util.Properties
> 2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils  -
> Method=java.lang.Object
> 2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils  - public
> java.lang.Object java.util.Stack.push(java.lang.Object) accessible version of
> public java.lang.Object java.util.Stack.push(java.lang.Object)
> 
> ...
> 
> 2004/09/01 09:07:19 DEBUG org.apache.commons.digester.Digester  -
> [ObjectCreateRule]{NamingResources} Pop java.util.Stack
> -----------------------
> 
> Any help would be greatly appreciated.
> 
> Thanks,
> Andrew.
> 
> --
> Andrew Steiger
> EMail:   andrew@andrewsteiger.com
> Web:     http://www.andrewsteiger.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
>

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


Mime
View raw message