com.ptc.windchill.structconf.util
Class LocaleUtilities

java.lang.Object
  extended bycom.ptc.windchill.structconf.util.LocaleUtilities

public class LocaleUtilities
extends Object

Framework Locale Utilities class This class should be used by the various parts of the framework for handling and resolving localization type stuff. Resources loaded by this class are java.util.ListResourceBundle's with the following naming convention: packagenameResource.class located in the packagename directory. So for example say I want to create a resource bundle class for com.ptc.windchill.install.InstallAction. The location/name of the ListResourceBundle class would be /com/ptc/windchill/install/installResource.class


Field Summary
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.
 
Constructor Summary
LocaleUtilities()
           
 
Method Summary
static Locale getLocaleFromString(String n)
          Takes a string (en_US for example) and turns it into a java locale object.
static String localize(Class caller_class, String message_key, Object[] arguments)
          Same as localize(java.lang.Class,java.lang.String,java.lang.Object[],java.util.Locale) but uses Locale.getDefault() to determine the local automatically.
static String localize(Class caller_class, String message_key, Object[] arguments, ClassLoader classLoader)
          Same as localize(java.lang.Class,java.lang.String,java.lang.Object[],java.util.Locale,java.lang.ClassLoader) but uses Locale.getDefault() to determine the local automatically.
static String localize(Class caller_class, String message_key, Object[] arguments, Locale locale)
          Use the caller's class to derive a Windchill-ish resource name(see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale).
static String localize(Class caller_class, String message_key, Object[] arguments, Locale locale, ClassLoader classLoader)
          Use the caller's class to derive a Windchill-ish resource name(see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale).
static String localize(Object caller, String message_key, Object[] arguments)
          Same as localize(java.lang.Object,java.lang.String,java.lang.Object[],java.util.Locale) but uses Locale.getDefault() to determine the local automatically.
static String localize(Object caller, String message_key, Object[] arguments, ClassLoader classLoader)
          Same as localize(java.lang.Object,java.lang.String,java.lang.Object[],java.util.Locale, java.lang.ClassLoader) but uses Locale.getDefault() to determine the local automatically.
static String localize(Object caller, String message_key, Object[] arguments, Locale locale)
          Use the caller's class to derive a Windchill-ish resource name (see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale)
static String localize(Object caller, String message_key, Object[] arguments, Locale locale, ClassLoader classLoader)
          Use the caller's class to derive a Windchill-ish resource name (see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale)
static String localize(String resource_name, String message_key, Object[] arguments)
          Same as localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale) but uses Locale.getDefault() to determine the local automatically.
static String localize(String resource_name, String message_key, Object[] arguments, ClassLoader classLoader)
          Same as localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale,java.lang.ClassLoader) but uses Locale.getDefault() to determine the local automatically.
static String localize(String resource_name, String message_key, Object[] arguments, Locale locale)
          Use the specified resource, to find a message with the specified key and localize it for the locale using the provided arguments.
static String localize(String resource_name, String message_key, Object[] arguments, Locale locale, ClassLoader classLoader)
          Use the specified resource, to find a message with the specified key and localize it for the locale using the provided arguments.
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 ￿.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUBSTITUTION_CHAR

private static final 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. Tests have shown it to be excepted by MessageFormat

See Also:
Constant Field Values
Constructor Detail

LocaleUtilities

public LocaleUtilities()
Method Detail

getLocaleFromString

public static Locale getLocaleFromString(String n)
Takes a string (en_US for example) and turns it into a java locale object. This is a sort of convienence method as Install Anywhere gives us the .toString() representation of a locale, this actually turns that String into a Locale object.

Parameters:
n - the String representation of our locale in the form language_COUNTRY, optionally you can do language_COUNTRY_VARIANT

localize

public static String localize(Object caller,
                              String message_key,
                              Object[] arguments,
                              Locale locale)
Use the caller's class to derive a Windchill-ish resource name (see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale)

Parameters:
arguments - may be null if the message does not have any parameters

localize

public static String localize(Object caller,
                              String message_key,
                              Object[] arguments,
                              Locale locale,
                              ClassLoader classLoader)
Use the caller's class to derive a Windchill-ish resource name (see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale)

Parameters:
arguments - may be null if the message does not have any parameters

localize

public static String localize(Class caller_class,
                              String message_key,
                              Object[] arguments,
                              Locale locale)
Use the caller's class to derive a Windchill-ish resource name(see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale). If the caller_class is actually a resource bundle class then use it directly.

Parameters:
arguments - may be null if the message does not have any parameters

localize

public static String localize(Class caller_class,
                              String message_key,
                              Object[] arguments,
                              Locale locale,
                              ClassLoader classLoader)
Use the caller's class to derive a Windchill-ish resource name(see top for detail), then call localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale). If the caller_class is actually a resource bundle class then use it directly.

Parameters:
arguments - may be null if the message does not have any parameters

localize

public static String localize(String resource_name,
                              String message_key,
                              Object[] arguments,
                              Locale locale)
Use the specified resource, to find a message with the specified key and localize it for the locale using the provided arguments.

Parameters:
arguments - may be null if the message does not have any parameters

localize

public static String localize(String resource_name,
                              String message_key,
                              Object[] arguments,
                              Locale locale,
                              ClassLoader classLoader)
Use the specified resource, to find a message with the specified key and localize it for the locale using the provided arguments.

Parameters:
arguments - may be null if the message does not have any parameters.

localize

public static String localize(Object caller,
                              String message_key,
                              Object[] arguments)
Same as localize(java.lang.Object,java.lang.String,java.lang.Object[],java.util.Locale) but uses Locale.getDefault() to determine the local automatically.


localize

public static String localize(Object caller,
                              String message_key,
                              Object[] arguments,
                              ClassLoader classLoader)
Same as localize(java.lang.Object,java.lang.String,java.lang.Object[],java.util.Locale, java.lang.ClassLoader) but uses Locale.getDefault() to determine the local automatically.


localize

public static String localize(Class caller_class,
                              String message_key,
                              Object[] arguments)
Same as localize(java.lang.Class,java.lang.String,java.lang.Object[],java.util.Locale) but uses Locale.getDefault() to determine the local automatically.


localize

public static String localize(Class caller_class,
                              String message_key,
                              Object[] arguments,
                              ClassLoader classLoader)
Same as localize(java.lang.Class,java.lang.String,java.lang.Object[],java.util.Locale,java.lang.ClassLoader) but uses Locale.getDefault() to determine the local automatically.


localize

public static String localize(String resource_name,
                              String message_key,
                              Object[] arguments)
Same as localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale) but uses Locale.getDefault() to determine the local automatically.


localize

public static String localize(String resource_name,
                              String message_key,
                              Object[] arguments,
                              ClassLoader classLoader)
Same as localize(java.lang.String,java.lang.String,java.lang.Object[],java.util.Locale,java.lang.ClassLoader) but uses Locale.getDefault() to determine the local automatically.


preFormatMessage

private static final String preFormatMessage(String msg)
This method will pre format a message so that all the unescaping ' characters are replaced with the unicode character ￿. THIS METHOD IS PULLED FROM wt.util.WTMessage

Parameters:
msg - The message the pre format.
Returns:
The formatted message.

postFormatMessage

private static final String postFormatMessage(String msg)
This method will post format a message so that all the escaped ' characters are restored. THIS METHOD IS PULLED FROM wt.util.WTMessage

Parameters:
msg - The message the post format.
Returns:
The restored message.