Package com.sodius.oslc.server.util
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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <M> MessagesProvider<M>createMessagesProvider(Class<M> messagesClass)Returns aMessagesProviderimplementation for the specified class.static ResourceBundlegetResourceBundle(IConfigurationElement element)Returns the resource bundle containing localized messages for the plug-in contributing the specified element, depending on theLocalespreferred locale.static ResourceBundlegetResourceBundle(org.osgi.framework.Bundle plugin)Returns the resource bundle containing localized messages for the specified plug-in, depends on theLocalespreferred locale.
-
-
-
Method Detail
-
getResourceBundle
public static ResourceBundle getResourceBundle(org.osgi.framework.Bundle plugin)
Returns the resource bundle containing localized messages for the specified plug-in, depends on theLocalespreferred locale.The plug-in must have a
/OSGI-INF/I10n/folder containing*.propertiesfiles:bundle.properties: contains English messagesbundle_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
LocalesAPI. 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 bybundle.propertiesif there's no match.- Parameters:
plugin- a plug-in having a/OSGI-INF/I10n/bundle.propertiesresource.- Returns:
- the resource bundle declared in the specified plug-in,
nullif 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 theLocalespreferred locale.- Parameters:
element- an extension whose contributing plug-in defines translations.- Returns:
- the resource bundle declared in the specified plug-in,
nullif none. - See Also:
getResourceBundle(Bundle)
-
createMessagesProvider
public static <M> MessagesProvider<M> createMessagesProvider(Class<M> messagesClass)
Returns aMessagesProviderimplementation for the specified class.- Type Parameters:
M- a subclass of NLS providing message keys and translations.- Parameters:
messagesClass- a class extending NLS.- Returns:
- a
MessagesProviderimplementation for the specified class.
-
-