maven-xrts-plugin - Generating Message Bundles from XML

Posted by Mike Haller on Monday, July 30. 2007 at 13:38 in Java
Apache MyFaces Trinidad is using its maven-xrts-plugin to generate Message Bundle classes out of a XML file for internationalization (i18n). (X)RTS is a proprietary XML format to represent key/value pairs with namespaces. I'll show how to add the plugin to your pom.xml and how to use the format to generate Message Bundle classes.
See rts.dtd in trinidad-api for details about the format, although there is not much more than the example below shows.

First, create a src/main/xrts/MyMessages.xrts:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources SYSTEM "rts.dtd">
<resources xmlns="http://mhaller.de/rts" package="de.mhaller.resource">
  <resource key="foo">bar</resource>
</resources>
 


To use the maven-xrts-plugin, you need to add it to the generate-sources lifecycle goal of your project's Maven pom.xml:


<plugin>
 <groupId>org.apache.myfaces.trinidadbuild</groupId>
 <artifactId>maven-xrts-plugin</artifactId>
 <version>1.0.2-SNAPSHOT</version>
 <executions>
  <execution>
   <goals>
    <goal>generate-sources</goal>
    <goal>generate-test-sources</goal>
   </goals>
  </execution>
 </executions>
</plugin>
 


As the generated source uses the Java 5 @Override annotation, you should also set the Java Source Level version to 1.5, if
not already done in your project.

Now, run Maven: mvn package

The following Java Source Code is automatically generated and packaged for each *.xrts resource found within your projects src/main/xrts folder:

// Do not edit this file!
// This file has been automatically generated.
// Edit MyMessages.xrts and run the XRTSMakeBundle tool instead.
//
package de.mhaller.resource;

import java.util.{FNAMEL}+java.sun.com&btnI=I%27m%20Feeling%20Lucky">ListResourceBundle;

public class MyMessages extends {FNAMEL}+java.sun.com&btnI=I%27m%20Feeling%20Lucky">ListResourceBundle {
  @Override
  public {FNAMEL}+java.sun.com&btnI=I%27m%20Feeling%20Lucky">Object[][] getContents() {
    return new {FNAMEL}+java.sun.com&btnI=I%27m%20Feeling%20Lucky">Object[][] {
    {"foo", "bar"},
    };
  }
}





Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications
 
Submitted comments will be subject to moderation before being displayed.
 

About

My name is Mike Haller and I'm a software developer and architect at Bosch Software Innovations in Germany. I love programming, playing games and reading books. I like good food, making photos and learning and mentoring about the craftsmanship of commercial software development. Stack Overflow profile for mhaller

Quicksearch