Programming is hard by Stephan Schmidt

XmlResourceBundle added to Messages

I have added a XmlResourceBundle to cintoo Messages.

<properties>
<property key=”mykey”>myvalue</property>
</properties>

The greatest benefits with XML are that you can easier use encodings in XML files than in the default Java properties bundles. And you can use XML-based tools for bundle creation and management. The bundle also shows the direction Messages is going. Easy adobtable to your project requirements.
The XmlResourceBundle is easy to extend. As an example for another Xml properties
format I chose one from Cocoon.

The format is different from the default properties xml format in Messages, so some adaptions are needed.

<categories>
<message key=”mykey”>myvalue</message>
</categories>

Messages xml uses Apache Jakarta Digester. We have to tell Digester how to map the xl tags to the properties class.

public class CocoonXmlResourceBundle extends XmlResourceBundle {
public CocoonXmlResourceBundle(String baseName, Locale locale) {
super(baseName, locale);
}

protected Digester configure(Digester digester) {
digester.addObjectCreate(”catalogue/message”, Property.class);
digester.addSetNext(”catalogue/message”, “addProperty”, “cintoo.messages.bundle.xml.Property”);
digester.addBeanPropertySetter(”catalogue/message”, “value”);
digester.addSetProperties(”catalogue/message”, “key”, “key”);
return digester;
}
}

That’s it. And it’s as easy to adapt XmlResourceBundle to other formats.

If you liked this post, subscribe to my free full RSS feed.
Filed under: Java, Software development

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

Get free updates by email

If you did like this article you can get free updates with your RSS reader, you can follow me on Twitter or get free update to new posts by email. Enter your email:

 
About the author: Stephan has been working as a head of development and CTO. He has experiences in different technologies since 20 years including Java, Rails and Python. Stephans main field of interest is maintainablity and productivity in software development. Want to know more? All views are only his own.

Leave a Reply