commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simone Tripodi" <simone.trip...@gmail.com>
Subject Re: Commons betwixt 0.8 - reading Map from XML
Date Sat, 06 Sep 2008 12:16:06 GMT
Hi Dimitry,
my pleasure :)
Best regards,
Simone

2008/9/5 Dmitriy Kuznetsov <heaven-seven@yandex.ru>:
>
>
> Simone Tripodi wrote:
>>
>> Hi Dmitriy,
>> you don't you use just the commons-digester rules to map the xml to your
>> map?
>> It's also a betwixt dependency library, and maybe it could be easier.
>> Best regards,
>> Simone
>>
> Well, i've made some changes since first time. The XML now looks like
> following:
>
> <metadata>
>        <group name="...">
>                <entry name="...">
>                        <header>...</header>
>                        <width>...</width>
>                </entry>
>                <entry name="...">
>                        <hideable>...</hideable>
>                        <tooltip>...</tooltip>
>                </entry>
>        </group>
>        <group name="...">
>                <entry name="...">
>                        <align>...</align>
>                        <width>...</width>
>                </entry>
>        </group>
> </metadata>
>
> And as Simone suggested, i've used commons Digester instead of Betwixt:
>
>        Digester digester = new Digester();
>
>        digester.setValidating(false);
>
>        digester.addObjectCreate("metadata", Hashtable.class);
>
>        digester.addObjectCreate("metadata/group", ListOrderedMap.class);
>
>        Rule r = new CallMethodRule(1, "put", 2);
>        digester.addRule("metadata/group", r);
>        digester.addCallParam("metadata/group", 0, "name");
>        digester.addCallParam("metadata/group", 1, true);
>
>        // MetadataEntry is a simple bean that holds values of <entry/> section
>        digester.addObjectCreate("metadata/group/entry", MetadataEntry.class);
>
>        r = new SetNestedPropertiesRule();
>        digester.addRule("metadata/group/entry", r);
>
>        r = new CallMethodRule(1, "put", 2);
>        digester.addRule("metadata/group/entry", r);
>        digester.addCallParam("metadata/group/entry", 0, "name");
>        digester.addCallParam("metadata/group/entry", 1, true);
>
>        // a little later
>
>        InputStream is =
> servletContext.getResourceAsStream("WEB-INF/classes/metadata.xml");
>        Object result = digester.parse(is);
>
> And it works. The resulting data structure is: Map<String, Map<String,
> MetadataEntry>>
> Simone, thanks! =)
> --
> View this message in context: http://www.nabble.com/Commons-betwixt-0.8---reading-Map-from-XML-tp19255879p19336473.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>



-- 
My LinkedIn profile: http://www.linkedin.com/in/simonetripodi
My GoogleCode profile: http://code.google.com/u/simone.tripodi/
My Sourceforge: https://sourceforge.net/users/stripodi
My Picasa: http://picasaweb.google.com/simone.tripodi/
My Tube: http://www.youtube.com/user/stripodi
My Del.icio.us: http://del.icio.us/simone.tripodi

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


Mime
View raw message