commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitriy Kuznetsov <heaven-se...@yandex.ru>
Subject Re: Commons betwixt 0.8 - reading Map from XML
Date Fri, 05 Sep 2008 17:51:56 GMT


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


Mime
View raw message