Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 41043 invoked from network); 2 Nov 2001 21:58:22 -0000 Received: from unknown (HELO osaka.betaversion.org) (192.18.49.133) by daedalus.apache.org with SMTP; 2 Nov 2001 21:58:22 -0000 Received: (qmail 17892 invoked from network); 2 Nov 2001 22:00:42 -0000 Received: from nagoya.betaversion.org (192.18.49.131) by osaka.betaversion.org with SMTP; 2 Nov 2001 22:00:42 -0000 Received: (qmail 25945 invoked by uid 97); 2 Nov 2001 21:58:21 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 25928 invoked by uid 97); 2 Nov 2001 21:58:20 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 25883 invoked from network); 2 Nov 2001 21:58:20 -0000 Message-Id: <200111022157.fA2Lvhv04500@smtpout.mac.com> Date: Fri, 2 Nov 2001 21:58:59 +0000 Content-Type: multipart/alternative; boundary=Apple-Mail-982909581-1 X-Mailer: Apple Mail (2.388) From: robert burrell donkin To: "Jakarta Commons Developers List" Mime-Version: 1.0 (Apple Message framework v388) In-Reply-To: Subject: Re: earth to digester X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --Apple-Mail-982909581-1 Content-Transfer-Encoding: 7bit Content-Type: text/plain; format=flowed; charset=us-ascii On Friday, November 2, 2001, at 09:48 PM, Jason van Zyl wrote: > On 11/2/01 3:44 PM, "Scott Sanders" wrote: >> That's Castor all right. I suppose we could start down that road, but I' >> m >> not sure why we would want to re-invent the wheel, since Castor is even >> 2 >> way. > > I decided 6 months ago that I was going to use digester for everything > XML. > I looked at Castor and the Digester and Castor seemed rather complex. I > also > will always favour an apache product, and it seems that robert has a rule > that will do what I need. To boot, Craig is meticulous with the code that > he > releases and is highly responsive to requests for change so I'm not really > interested in looking at Castor anymore. jason you might want to give this a spin. (i'll come back later with a better version and a test case later) you'll need to use the ExtendedBaseRules, and so you'll need something like digester.setRules(new ExtendedBaseRules); you need to use a child match rule something like digester.addRule("alpha/?", new BeanPropertySetterRule(digester)); this should set properties with names matching the names of child elements of with the body text of those elements. eg. ... Text ... will set property beta with 'Text' on the top object on the stack (which should be alpha). in other words, what you wanted. and without changing digester :) - robert --Apple-Mail-982909581-1 Content-Type: multipart/mixed; boundary=Apple-Mail-1823751234-2 --Apple-Mail-1823751234-2 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii; format=flowed On Friday, November 2, 2001, at 09:48 PM, Jason van Zyl wrote: > On 11/2/01 3:44 PM, "Scott Sanders" wrote: >> That's Castor all right. I suppose we could start down that road, but I' >> m >> not sure why we would want to re-invent the wheel, since Castor is even >> 2 >> way. > > I decided 6 months ago that I was going to use digester for everything > XML. > I looked at Castor and the Digester and Castor seemed rather complex. I > also > will always favour an apache product, and it seems that robert has a rule > that will do what I need. To boot, Craig is meticulous with the code that > he > releases and is highly responsive to requests for change so I'm not really > interested in looking at Castor anymore. jason you might want to give this a spin. (i'll come back later with a better version and a test case later) you'll need to use the ExtendedBaseRules, and so you'll need something like digester.setRules(new ExtendedBaseRules); you need to use a child match rule something like digester.addRule("alpha/?", new BeanPropertySetterRule(digester)); this should set properties with names matching the names of child elements of with the body text of those elements. eg. ... Text ... will set property beta with 'Text' on the top object on the stack (which should be alpha). in other words, what you wanted. and without changing digester :) - robert --Apple-Mail-1823751234-2 Content-Disposition: attachment Content-Type: multipart/appledouble; boundary=Apple-Mail-270922835-3 --Apple-Mail-270922835-3 Content-Disposition: attachment; filename="BeanPropertySetterRule.java" Content-Type: application/applefile; name="BeanPropertySetterRule.java" Content-Transfer-Encoding: base64 AAUWBwACAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAJAAAAMgAAAAoAAAADAAAAPAAAABs/Pz8/Pz8/ PwEAQmVhblByb3BlcnR5U2V0dGVyUnVsZS5qYXZh --Apple-Mail-270922835-3 Content-Disposition: attachment; filename="BeanPropertySetterRule.java" Content-Type: application/octet-stream; name="BeanPropertySetterRule.java"; x-mac-type=3F3F3F3F; x-mac-creator=3F3F3F3F; x-unix-mode=0664 Content-Transfer-Encoding: quoted-printable /*=0A=20*=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20*=0A=20*=20= The=20Apache=20Software=20License,=20Version=201.1=0A=20*=0A=20*=20= Copyright=20(c)=201999-2001=20The=20Apache=20Software=20Foundation.=20=20= All=20rights=0A=20*=20reserved.=0A=20*=0A=20*=20Redistribution=20and=20= use=20in=20source=20and=20binary=20forms,=20with=20or=20without=0A=20*=20= modification,=20are=20permitted=20provided=20that=20the=20following=20= conditions=0A=20*=20are=20met:=0A=20*=0A=20*=201.=20Redistributions=20of=20= source=20code=20must=20retain=20the=20above=20copyright=0A=20*=20=20=20=20= notice,=20this=20list=20of=20conditions=20and=20the=20following=20= disclaimer.=0A=20*=0A=20*=202.=20Redistributions=20in=20binary=20form=20= must=20reproduce=20the=20above=20copyright=0A=20*=20=20=20=20notice,=20= this=20list=20of=20conditions=20and=20the=20following=20disclaimer=20in=0A= =20*=20=20=20=20the=20documentation=20and/or=20other=20materials=20= provided=20with=20the=0A=20*=20=20=20=20distribution.=0A=20*=0A=20*=203.=20= The=20end-user=20documentation=20included=20with=20the=20redistribution,=20= if=0A=20*=20=20=20=20any,=20must=20include=20the=20following=20= acknowlegement:=0A=20*=20=20=20=20=20=20=20"This=20product=20includes=20= software=20developed=20by=20the=0A=20*=20=20=20=20=20=20=20=20Apache=20= Software=20Foundation=20(http://www.apache.org/)."=0A=20*=20=20=20=20= Alternately,=20this=20acknowlegement=20may=20appear=20in=20the=20= software=20itself,=0A=20*=20=20=20=20if=20and=20wherever=20such=20= third-party=20acknowlegements=20normally=20appear.=0A=20*=0A=20*=204.=20= The=20names=20"The=20Jakarta=20Project",=20"Commons",=20and=20"Apache=20= Software=0A=20*=20=20=20=20Foundation"=20must=20not=20be=20used=20to=20= endorse=20or=20promote=20products=20derived=0A=20*=20=20=20=20from=20= this=20software=20without=20prior=20written=20permission.=20For=20= written=0A=20*=20=20=20=20permission,=20please=20contact=20= apache@apache.org.=0A=20*=0A=20*=205.=20Products=20derived=20from=20this=20= software=20may=20not=20be=20called=20"Apache"=0A=20*=20=20=20=20nor=20= may=20"Apache"=20appear=20in=20their=20names=20without=20prior=20written=0A= =20*=20=20=20=20permission=20of=20the=20Apache=20Group.=0A=20*=0A=20*=20= THIS=20SOFTWARE=20IS=20PROVIDED=20``AS=20IS''=20AND=20ANY=20EXPRESSED=20= OR=20IMPLIED=0A=20*=20WARRANTIES,=20INCLUDING,=20BUT=20NOT=20LIMITED=20= TO,=20THE=20IMPLIED=20WARRANTIES=0A=20*=20OF=20MERCHANTABILITY=20AND=20= FITNESS=20FOR=20A=20PARTICULAR=20PURPOSE=20ARE=0A=20*=20DISCLAIMED.=20=20= IN=20NO=20EVENT=20SHALL=20THE=20APACHE=20SOFTWARE=20FOUNDATION=20OR=0A=20= *=20ITS=20CONTRIBUTORS=20BE=20LIABLE=20FOR=20ANY=20DIRECT,=20INDIRECT,=20= INCIDENTAL,=0A=20*=20SPECIAL,=20EXEMPLARY,=20OR=20CONSEQUENTIAL=20= DAMAGES=20(INCLUDING,=20BUT=20NOT=0A=20*=20LIMITED=20TO,=20PROCUREMENT=20= OF=20SUBSTITUTE=20GOODS=20OR=20SERVICES;=20LOSS=20OF=0A=20*=20USE,=20= DATA,=20OR=20PROFITS;=20OR=20BUSINESS=20INTERRUPTION)=20HOWEVER=20CAUSED=20= AND=0A=20*=20ON=20ANY=20THEORY=20OF=20LIABILITY,=20WHETHER=20IN=20= CONTRACT,=20STRICT=20LIABILITY,=0A=20*=20OR=20TORT=20(INCLUDING=20= NEGLIGENCE=20OR=20OTHERWISE)=20ARISING=20IN=20ANY=20WAY=20OUT=0A=20*=20= OF=20THE=20USE=20OF=20THIS=20SOFTWARE,=20EVEN=20IF=20ADVISED=20OF=20THE=20= POSSIBILITY=20OF=0A=20*=20SUCH=20DAMAGE.=0A=20*=20= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=20*=0A=20*=20= This=20software=20consists=20of=20voluntary=20contributions=20made=20by=20= many=0A=20*=20individuals=20on=20behalf=20of=20the=20Apache=20Software=20= Foundation.=20=20For=20more=0A=20*=20information=20on=20the=20Apache=20= Software=20Foundation,=20please=20see=0A=20*=20.=0A= =20*=0A=20*/=0A=0A=0Apackage=20org.apache.commons.digester;=0A=0Aimport=20= java.util.HashMap;=0Aimport=20org.xml.sax.Attributes;=0Aimport=20= org.apache.commons.beanutils.BeanUtils;=0A=0A=0A/**=0A=20*=20

=20Rule=20= implements=20sets=20bean=20properties=20from=20child=20element=20body=20= text.=0A=20*=0A=20*/=0A=0Apublic=20class=20BeanPropertySetterRule=20= extends=20Rule=20{=0A=0A=0A=20=20=20=20//=20= -----------------------------------------------------------=20= Constructors=0A=0A=0A=20=20=20=20/**=20=0A=20=20=20=20=20*=20

=20= Construct=20rule=20that=20sets=20a=20particular=20property=20from=20the=20= body=20text.=0A=20=20=20=20=20*=20=0A=20=20=20=20=20*=20@param=20= digester=20associated=20Digester=0A=20=20=20=20=20*=20= @param=20propertyName=20name=20of=20property=20to=20set=20=0A=20=20=20=20= =20*/=0A=20=20=20=20public=20BeanPropertySetterRule(Digester=20digester,=20= String=20propertyName)=20{=0A=20=20=20=20=20=20=20=20=20=20=20=20=0A=20=20= =20=20=20=20=20=20=20=20=20=20super(digester);=0A=20=20=20=20=20=20=20=20= =20=20=20=20this.propertyName=3DpropertyName;=0A=0A=20=20=20=20}=0A=0A=20= =20=20=20/**=20=0A=20=20=20=20=20*=20

=20Construct=20a=20rule=20that=20= sets=20property=20match=20child=20element=20name.=0A=20=20=20=20=20*=0A=20= =20=20=20=20*=20@param=20digester=20associated=20Digester=0A= =20=20=20=20=20*/=0A=20=20=20=20public=20BeanPropertySetterRule(Digester=20= digester)=20{=0A=0A=20=20=20=20=20=20=20=20=20=20=20=20this(digester,=20= null);=0A=0A=20=20=20=20}=0A=20=0A=0A=20=20=20=20//=20= -----------------------------------------------------=20Instance=20= Variables=0A=0A=20=20=20=20/**=0A=20=20=20=20=20*=20The=20name=20of=20= the=20property=20to=20set=20on=20the=20parent=20object.=0A=20=20=20=20=20= */=0A=20=20=20=20protected=20String=20propertyName=20=3D=20null;=0A=0A=20= =20=20=20/**=0A=20=20=20=20=20*=20The=20body=20text=20used=20to=20set=20= the=20property=0A=20=20=20=20=20*/=0A=20=20=20=20protected=20String=20= bodyText=20=3D=20null;=0A=0A=20=20=20=20//=20= ---------------------------------------------------------=20Public=20= Methods=0A=0A=0A=0A=20=20=20=20/**=0A=20=20=20=20=20*=20Process=20the=20= body=20text=20of=20this=20element.=0A=20=20=20=20=20*=0A=20=20=20=20=20*=20= @param=20bodyText=20The=20body=20text=20of=20this=20element=0A=20=20=20=20= =20*/=0A=20=20=20=20public=20void=20body(String=20bodyText)=20throws=20= Exception=20{=0A=0A=09=20=20=20=20this.bodyText=20=3D=20bodyText.trim();=0A= =0A=20=20=20=20}=0A=0A=0A=20=20=20=20/**=0A=20=20=20=20=20*=20Process=20= the=20end=20of=20this=20element.=0A=20=20=20=20=20*/=0A=20=20=20=20= public=20void=20end()=20throws=20Exception=20{=0A=0A=20=20=20=20=20=20=20= =20String=20property=3DpropertyName;=0A=0A=20=20=20=20=20=20=20=20if=20= (property=3D=3Dnull)=20{=0A=20=20=20=20=20=20=20=20=20=20=20=20//=20= Recover=20the=20previous=20match=20expression=0A=20=20=20=20=20=20=20=20=20= =20=20=20String=20match=20=3D=20digester.match;=0A=20=20=20=20=20=20=20=20= =20=20=20=20int=20slash=20=3D=20match.lastIndexOf('/');=0A=20=20=20=20=20= =20=20=20=20=20=20=20if=20(slash=20>=3D=200)=0A=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20match=20=3D=20match.substring(slash+1);=0A=20=20=20=20= =20=20=20=20=20=20=20=20else=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20match=20=3D=20"";=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =0A=20=20=20=20=20=20=20=20=20=20=20=20property=3Dmatch;=0A=09}=0A=20=20=20= =20=20=20=20=20=0A=20=20=20=20=20=20=20=20HashMap=20map=3Dnew=20= HashMap();=0A=20=20=20=20=20=20=20=20map.put(property,bodyText);=0A=20=20= =20=20=20=20=20=20=0A=20=20=20=20=20=20=20=20= BeanUtils.populate(digester.peek(),map);=0A=20=20=20=20=20=20=20=20=0A=20= =20=20=20}=0A=0A=0A=20=20=20=20/**=0A=20=20=20=20=20*=20Clean=20up=20= after=20parsing=20is=20complete.=0A=20=20=20=20=20*/=0A=20=20=20=20= public=20void=20finish()=20throws=20Exception=20{=0A=0A=09bodyText=20=3D=20= null;=0A=0A=20=20=20=20}=0A=0A=0A=20=20=20=20/**=0A=20=20=20=20=20*=20= Render=20a=20printable=20version=20of=20this=20Rule.=0A=20=20=20=20=20*/=0A= =20=20=20=20public=20String=20toString()=20{=0A=20=20=20=20=20=20=20=20=0A= =20=20=20=20=20=20=20=20StringBuffer=20sb=20=3D=20new=20= StringBuffer("BeanPropertySetterRule[");=0A=20=20=20=20=20=20=20=20= sb.append("propertyName=3D");=0A=20=20=20=20=20=20=20=20= sb.append(propertyName);=0A=20=20=20=20=20=20=20=20sb.append("]");=0A=20=20= =20=20=20=20=20=20return=20(sb.toString());=0A=0A=20=20=20=20}=0A=0A}=0A= --Apple-Mail-270922835-3-- --Apple-Mail-1823751234-2-- --Apple-Mail-982909581-1--