String key = null;
LocalizationContext locCtxt = null;
// determine the message key by...
if (keySpecified) {
// ... reading 'key' attribute
key = keyAttrValue;
} else {
// ... retrieving and trimming our body
if (bodyContent != null && bodyContent.getString() != null)
key = bodyContent.getString().trim();
}
if ((key == null) || key.equals("")) {
try {
pageContext.getOut().print("??????");
} catch (IOException ioe) {
throw new JspTagException(ioe.toString(), ioe);
}
return EVAL_PAGE;
}
String prefix = null;
if (!bundleSpecified) {
Tag t = findAncestorWithClass(this, BundleSupport.class);
if (t != null) {
// use resource bundle from parent <bundle> tag
BundleSupport parent = (BundleSupport) t;
locCtxt = parent.getLocalizationContext();
prefix = parent.getPrefix();
} else {
locCtxt = BundleSupport.getLocalizationContext(pageContext);
}
} else {
// localization context taken from 'bundle' attribute
locCtxt = bundleAttrValue;
if (locCtxt.getLocale() != null) {
SetLocaleSupport.setResponseLocale(pageContext,
locCtxt.getLocale());
}
}
String message = UNDEFINED_KEY + key + UNDEFINED_KEY;
if (locCtxt != null) {
ResourceBundle bundle = locCtxt.getResourceBundle();
if (bundle != null) {
try {
// prepend 'prefix' attribute from parent bundle
if (prefix != null)
key = prefix + key;
message = bundle.getString(key);
// Perform parametric replacement if required
if (!params.isEmpty()) {
Object[] messageArgs = params.toArray();
MessageFormat formatter = new MessageFormat(""); // empty pattern, default Locale
if (locCtxt.getLocale() != null) {
formatter.setLocale(locCtxt.getLocale());
} else {
// For consistency with the <fmt:formatXXX> actions,
// we try to get a locale that matches the user's preferences
// as well as the locales supported by 'date' and 'number'.
//System.out.println("LOCALE-LESS LOCCTXT: GETTING FORMATTING LOCALE");
Locale locale = SetLocaleSupport.getFormattingLocale(pageContext);
//System.out.println("LOCALE: " + locale);
if (locale != null) {
formatter.setLocale(locale);
}
}
formatter.applyPattern(message);
message = formatter.format(messageArgs);
}
} catch (MissingResourceException mre) {
message = UNDEFINED_KEY + key + UNDEFINED_KEY;
}
}
}
if (var != null) {
pageContext.setAttribute(var, message, scope);
} else {
try {
pageContext.getOut().print(message);
} catch (IOException ioe) {
throw new JspTagException(ioe.toString(), ioe);
}
}
return EVAL_PAGE;