The textresource property

For each of the existing renderers used with Pods a 'textresource' attribute can be set that defines a resource property file. The code extract in Example 8.1 shows a renderer reading a property from a text resource file. The file name is passed in the XML received by the renderer (See example 8.2)

Figure 1. A Renderer reading a property from a text resource file
private static final String RESOURCE_FILE_PATH = "@textresource";
  ...
  ...
  String textResource = context.getDataAccessor().get(
    field.getBinding().getSourcePath().extendPath(
      RESOURCE_FILE_PATH));
  Path textPath = 
    ClientPaths.GENERAL_RESOURCES_PATH.extendPath(textResource);
  ...
  ...
  final String saveButtonText = 
    context.getDataAccessor().get(
      textPath.extendPath("button.save.text"));

In the example above the Renderer is expecting to receive the name of the text resource file in the 'textresource' attribute of the document Node it receives.

Figure 2. Example of a document Node input to a Pod renderer
<pod textresource="sample.i18n.MyFavouriteMovies" ...>
    <config>
      ...
    </config>
    <data>
      ...
    </data>
  </pod>

The Renderer uses the ClientPaths class to create a pointer to the text resource file. The value of the property is retrieved by extending the path into the file to point at the specific property. The path extension is the property key. The value returned is the property value. If the request is made for a specific locale, and the resource file for that locale has been provided then ClientPaths class will access the property in the appropriate resource file.

Figure 3. MyFavouriteMovies.properties
pod.title=My Favourite Movies
  pod.filter.genre.label=Genre
  ....

The location of the properties file must be on the classpath of the client project. Adding the properties file to the javasource folder will achieve this. The convention is to add property files to a folder called i18n to differentiate them.