static FacesMessage getMessage(FacesContext facesContext,
Locale locale,
Severity severity,
String messageId,
Object[] args) {
ResourceBundle appBundle;
ResourceBundle defBundle;
String summary;
String detail;
appBundle = getApplicationBundle(facesContext, locale);
summary = getBundleString(appBundle, messageId);
if (summary != null)
{
detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
}
else
{
defBundle = getDefaultBundle(facesContext, locale);
summary = getBundleString(defBundle, messageId);
if (summary != null)
{
detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
}
else
{
//Try to find detail alone
detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
if (detail != null)
{
summary = null;
}
else
{
detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
if (detail != null)
{
summary = null;
}
else
{
//Neither detail nor summary found
return null;
}
}
}
}
if (args != null && args.length > 0)
{
MessageFormat format;
if (summary != null)
{
format = new MessageFormat(summary, locale);
summary = format.format(args);
}
if (detail != null)
{
format = new MessageFormat(detail, locale);
detail = format.format(args);
}
}
return new FacesMessage(severity, summary, detail);
}
|