in common/src/main/java/flex/messaging/util/PropertyStringResourceLoader.java [123:190]
public String getString(String key, Locale locale, Object[] arguments) {
synchronized (strings) {
if (defaultLocale == null) {
defaultLocale = getDefaultLocale();
}
}
String value = null;
String stringKey = null;
String localeKey = (locale != null) ?
generateLocaleKey(locale) :
generateLocaleKey(defaultLocale);
String originalStringKey = generateStringKey(key, localeKey);
int trimIndex = 0;
/*
* Attempt to get a string for the target locale - fail back to less specific
* versions of the locale.
*/
while (true) {
loadStrings(localeKey);
stringKey = generateStringKey(key, localeKey);
synchronized (strings) {
value = (String) strings.get(stringKey);
if (value != null) {
if (!stringKey.equals(originalStringKey)) {
strings.put(originalStringKey, value);
}
return substituteArguments(value, arguments);
}
}
trimIndex = localeKey.lastIndexOf('_');
if (trimIndex != -1) {
localeKey = localeKey.substring(0, trimIndex);
} else {
break;
}
}
/*
* Attempt to get the string in our default locale if it is
* different than the requested locale.
*/
if ((locale != null) && (!locale.equals(defaultLocale))) {
localeKey = generateLocaleKey(defaultLocale);
stringKey = generateStringKey(key, localeKey);
synchronized (strings) {
value = (String) strings.get(stringKey);
if (value != null) {
strings.put(originalStringKey, value);
return substituteArguments(value, arguments);
}
}
}
// As a last resort, try to get a non-locale-specific string.
loadStrings("");
stringKey = generateStringKey(key, "");
synchronized (strings) {
value = (String) strings.get(stringKey);
if (value != null) {
strings.put(originalStringKey, value);
return substituteArguments(value, arguments);
}
}
// No string is available. Return a formatted missing string value.
return ("???" + key + "???");
}