{8.2.0-updated} Messages

The {@link oajr.annotation.Rest#messages @Rest(messages)} annotation identifies the location of the resource bundle for a @Rest-annotated class if it's different from the class name.

By default, the resource bundle name is assumed to match the class name. For example, given the class MyClass.java, the resource bundle is assumed to be MyClass.properties. This property allows you to override this setting to specify a different location such as MyMessages.properties by specifying a value of "MyMessages".

Resource bundles are searched using the following base name patterns:

This annotation is used to provide request-localized (based on Accept-Language) messages for the following methods:

Request-localized messages are also available by passing either of the following parameter types into your Java method:

The value can be a relative path like "nls/Messages", indicating to look for the resource bundle "com.foo.sample.nls.Messages" if the resource class is in "com.foo.sample", or it can be an absolute path like "com.foo.sample.nls.Messages"

Examples:

#-------------------------------------------------------------------------------- # Contents of org/apache/foo/nls/MyMessages.properties #-------------------------------------------------------------------------------- HelloMessage = Hello {0}!

// Contents of org/apache/foo/MyResource.java @Rest(messages="nls/MyMessages") public class MyResource {...} @RestMethod(name="GET", path="/hello/{you}") public Object helloYou(RestRequest req, Messages messages, @Path("name") String you) { String s; // Get it from the RestRequest object. s = req.getMessage("HelloMessage", you); // Or get it from the method parameter. s = messages.getString("HelloMessage", you); // Or get the message in a locale different from the request. s = messages.forLocale(Locale.UK).getString("HelloMessage", you); return s; } }

When using shared resource bundles, keys can be prefixed by class names like so and still retrieve by simple key names:

#-------------------------------------------------------------------------------- # Contents of shared org/apache/foo/nls/MyMessages.properties #-------------------------------------------------------------------------------- MyResource.HelloMessage = Hello {0}!

Messages are automatically inherited from super classes. If a string cannot be found in the bundle of the current class, it will be searched for up the class hierarchy.