|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.util.WTMessage
WTMessage
is the wrapper class for getting a formatted,
localized message, from a resource bundle.
The following are examples of how WTMessage
would be used:
Static usage: Object[] textInserts = { getName() }; System.out.println( WTMessage.getLocalizedMessage( RESOURCE, "17", textInserts ) );Instance usage: Object[] textInserts = { getName() }; WTMessage wtMessage = new WTMessage( RESOURCE, "17", textInserts ); // ... other stuff wtMessage.getLocalizedMessage();
Localization of the WTMessage
messages relies on the resource
bundle and text formatting features of Java.
In the example above, RESOURCE
is a string constant that
identifies the resource bundle containing the localizable message.
Objects that act as text insert parameters of the message will make use
of the
getLocalizedMessage(Locale)
method, if those insert objects
implement the wt.util.LocalizableMessage
interface. This
enables the message inserts to be localized, along with the message itself,
at the time the localized message is requested.
Supported API: true
Extendable: false
ResourceBundle
,
MessageFormat
,
LocalizableMessage.getLocalizedMessage(java.util.Locale)
,
Serialized FormNested Class Summary | |
(package private) static class |
WTMessage.CacheKey
|
Field Summary | |
private static Cache |
cache
|
private static int |
cacheHits
|
private static int |
cacheSummaryInterval
|
private static String |
CLASSNAME
|
private String |
messageKey
|
private static String |
RESOURCE
|
private String |
resourceBundle
|
private static char |
SUBSTITUTION_CHAR
unicode FFFF was chosen since unicode.org lists this a Not A Character, and therefore is not used by any language etc. |
private Object[] |
textInserts
|
Constructor Summary | |
protected |
WTMessage()
|
|
WTMessage(String rb,
String key,
Object[] params)
Constructs a Windchill message with a localizable detailed message. |
Method Summary | |
static String |
formatLocalizedMessage(String localizedString,
Object[] inserts)
This method will process an already localized string by escaping any appropriate characters, and then call java.text.MessageFormat on the String to properly insert any inserts. |
private static Cache |
getCache()
|
String |
getLocalizedMessage()
Gets the localized message, for the instance. |
String |
getLocalizedMessage(Locale locale)
Obtain a message, localized to the specified locale. |
static String |
getLocalizedMessage(String resourceBundle,
String messageKey,
Object[] textInserts)
Gets the localized message, for passed arguments. |
static String |
getLocalizedMessage(String resourceBundle,
String messageKey,
Object[] textInserts,
Locale locale)
Gets the localized message, for passed arguments. |
String |
getMessageIdentifier()
Gets the identity of the message. |
static WTMessage[] |
getMessages(String rb,
String key,
Object[] params)
Loops over the arrayed elements of params to generate multiple WTMessages, one for each element. |
private static String |
postFormatMessage(String msg)
This method will post format a message so that all the escaped ' characters are restored. |
private static String |
preFormatMessage(String msg)
This method will pre format a message so that all the unescaping ' characters are replaced with the unicode character . |
protected static void |
preProcessArgs(Object[] textInserts,
Locale locale)
|
protected void |
setLocalizedMessage(String rb,
String key,
Object[] params)
Sets the localized message for this WTMessage . |
String |
toString()
Returns the localized message, for the instance. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final String RESOURCE
private static final String CLASSNAME
private static Cache cache
private static int cacheSummaryInterval
private static int cacheHits
private static final char SUBSTITUTION_CHAR
private String resourceBundle
private String messageKey
private Object[] textInserts
Constructor Detail |
public WTMessage(String rb, String key, Object[] params)
Param objects of type wt.util.LocalizableMessage
will be expanded
by invoking getLocalizedMessage(Locale)
on them.
Supported API: true
rb
- the name of the base resource bundle subclass containing the localizable message.key
- the key associated with the localizable messageparams
- an optional set of objects to be formatted into the localizable message text.ResourceBundle
,
MessageFormat
,
LocalizableMessage.getLocalizedMessage(java.util.Locale)
protected WTMessage()
Method Detail |
public String getLocalizedMessage(Locale locale)
getLocalizedMessage
in interface LocalizableMessage
locale
-
public static WTMessage[] getMessages(String rb, String key, Object[] params)
Param objects of type wt.util.LocalizableMessage
will be expanded
by invoking getLocalizedMessage(Locale)
on them.
Supported API: true
rb
- the name of the base resource bundle subclass containing the localizable message.key
- the key associated with the localizable messageparams
- an optional set of objects to be formatted into the localizable message text.
If an element of params is itself an array, loop over those elements to produce
multiple WTMessages, one for each element.ResourceBundle
,
MessageFormat
,
LocalizableMessage.getLocalizedMessage(java.util.Locale)
public String getLocalizedMessage()
ResourceBundle
,
MessageFormat
public static String getLocalizedMessage(String resourceBundle, String messageKey, Object[] textInserts)
Param objects of type wt.util.LocalizableMessage
will be expanded
by invoking getLocalizedMessage(Locale)
on them.
Supported API: true
ResourceBundle
,
MessageFormat
,
LocalizableMessage.getLocalizedMessage(java.util.Locale)
public static String formatLocalizedMessage(String localizedString, Object[] inserts)
getLocalizedMessage( )
should be used, since this allows
for caching of resources etc. However in some cases, to avoid rewriting
major pieces of code, MessageFormat.format( )
can be directly replaced
with WTMessage.formatLocalizedMessage( )
localizedString
- The localized String to formatinserts
- The inserts to insert via the MessageFormat
public static String getLocalizedMessage(String resourceBundle, String messageKey, Object[] textInserts, Locale locale)
Param objects of type wt.util.LocalizableMessage
will be expanded
by invoking getLocalizedMessage(Locale)
on them.
Implementation Notes: Any usage of "{" or "}" characters in which there
are intended to be used as "{" or "}" (and not inset delimiters) should be enclosed
in "'" (apostrophes). For example, if you would like to have a String
"My name in curly brackets {developer}"
"My name in curly brackets '{'developer'}'"
locale
- the locale for which to get the localized message.ResourceBundle
,
MessageFormat
,
LocalizableMessage.getLocalizedMessage(java.util.Locale)
private static final String preFormatMessage(String msg)
msg
- The message the pre format.
private static final String postFormatMessage(String msg)
msg
- The message the post format.
public String getMessageIdentifier()
protected static void preProcessArgs(Object[] textInserts, Locale locale)
protected void setLocalizedMessage(String rb, String key, Object[] params)
WTMessage
.
Param objects of type wt.util.LocalizableMessage
will be expanded
by invoking getLocalizedMessage(Locale)
on them.
Supported API: false
rb
- the name of the base resource bundle subclass containing the localizable message.key
- the key associated with the localizable messageparams
- an optional set of objects to be formatted into the localizable message text.ResourceBundle
,
MessageFormat
,
LocalizableMessage.getLocalizedMessage(java.util.Locale)
public String toString()
private static Cache getCache()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |