Package org.apache.aries.util.nls
Class MessageUtil
- java.lang.Object
-
- org.apache.aries.util.nls.MessageUtil
-
public final class MessageUtil extends java.lang.Object
This is a helper class for loading messages for logging and exception messages. It supports translating the message into the default Locale. It works out the calling Bundle and uses it to load any resources. If the resource bundle is of type java.properties then it tries to find the bundle first via the bundle getResources method, then via the getEntry method. If it is of type java.class then it'll use the bundle to load the class.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MessageUtil
createMessageUtil(java.lang.Class<?> context, java.lang.String baseName)
Loads the MessageUtil using the given context.static MessageUtil
createMessageUtil(java.lang.String baseName)
This method uses the Bundle associated with the caller of this method.static MessageUtil
createMessageUtil(Bundle b, java.lang.String baseName)
This method loads the resource bundle backing the MessageUtil from the provided Bundle.java.lang.String
getMessage(java.lang.String key, java.lang.Object... inserts)
This method translates the message and puts the inserts into the message before returning it.
-
-
-
Method Detail
-
getMessage
public java.lang.String getMessage(java.lang.String key, java.lang.Object... inserts)
This method translates the message and puts the inserts into the message before returning it. If the message key does not exist then the key itself is returned.- Parameters:
key
- the message key.inserts
- the inserts into the resolved message.- Returns:
- the message in the correct language, or the key if the message does not exist.
-
createMessageUtil
public static MessageUtil createMessageUtil(java.lang.Class<?> context, java.lang.String baseName)
Loads the MessageUtil using the given context. It resolves the Class to an OSGi bundle.- Parameters:
context
- the bundle this class is in will be used to resolve the base name.baseName
- the resource bundle base name- Returns:
- the message util instance.
- Throws:
java.util.MissingResourceException
- If the resource bundle cannot be located
-
createMessageUtil
public static MessageUtil createMessageUtil(java.lang.String baseName)
This method uses the Bundle associated with the caller of this method.- Parameters:
baseName
- the resource bundle base name- Returns:
- the message util instance.
- Throws:
java.util.MissingResourceException
- If the resource bundle cannot be located
-
createMessageUtil
public static MessageUtil createMessageUtil(Bundle b, java.lang.String baseName)
This method loads the resource bundle backing the MessageUtil from the provided Bundle.- Parameters:
b
- the bundle to load the resource bundle frombaseName
- the resource bundle base name- Returns:
- the message util instance.
- Throws:
java.util.MissingResourceException
- If the resource bundle cannot be located
-
-