Class ServletNLS

java.lang.Object
com.sodius.oslc.server.util.ServletNLS

public class ServletNLS extends Object
Provides facilities to handle internationalization for servlets.

This class requires OSGi to be running.

  • Method Details

    • getResourceBundle

      public static ResourceBundle getResourceBundle(org.osgi.framework.Bundle plugin)
      Returns the resource bundle containing localized messages for the specified plug-in, depends on the Locales preferred locale.

      The plug-in must have a /OSGI-INF/I10n/ folder containing *.properties files:

      • bundle.properties: contains English messages
      • bundle_fr.properties: contains French messages

      A class can retrieve a bundle localized message using:

       String localizedMessage = ServletNLS.getResourceBundle(bundle).getString("my_message_key");
       

      The language to use is determined using the Locales API. ServletNLS iterates on the provided locales, in order of preference, and returns the translations if a properties file is found for the locale. It returns the default translations provided by bundle.properties if there's no match.

      Parameters:
      plugin - a plug-in having a /OSGI-INF/I10n/bundle.properties resource.
      Returns:
      the resource bundle declared in the specified plug-in, null if none.
    • getResourceBundle

      public static ResourceBundle getResourceBundle(IConfigurationElement element)
      Returns the resource bundle containing localized messages for the plug-in contributing the specified element, depending on the Locales preferred locale.
      Parameters:
      element - an extension whose contributing plug-in defines translations.
      Returns:
      the resource bundle declared in the specified plug-in, null if none.
      See Also:
    • createMessagesProvider

      public static <M> MessagesProvider<M> createMessagesProvider(Class<M> messagesClass)
      Returns a MessagesProvider implementation for the specified class.
      Type Parameters:
      M - a subclass of NLS providing message keys and translations.
      Parameters:
      messagesClass - a class extending NLS.
      Returns:
      a MessagesProvider implementation for the specified class.