Code Monkeyism

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.

About the author: Stephan Schmidt is currently a team manager at ImmobilienScout24 in Berlin. Stephan has been working as a head of development and CTO. He has used a lot of different technologies in the last 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.

If you did like this article but you don't want to subscribe to new articles with your reader, you can follow me on Twitter or subscribe to new posts with your email:

Leave a Reply