*
* @return the message if found, otherwise the defaultMessage
*/
public static String getText(String key, String defaultMessage, List<Object> args, ValueStack stack, boolean searchStack) {
String msg = null;
TextProvider tp = null;
for (Iterator iterator = stack.getRoot().iterator(); iterator.hasNext();) {
Object o = iterator.next();
if (o instanceof TextProvider) {
tp = (TextProvider) o;
msg = tp.getText(key, null, args, stack);
break;
}
}
if (msg == null) {
// evaluate the defaultMesage as an OGNL expression
if (searchStack)
msg = stack.findString(defaultMessage);
if (msg == null) {
// use the defaultMessage literal value
msg = defaultMessage;
}
if (LOG.isWarnEnabled()) {
if (tp != null) {
LOG.warn("The first TextProvider in the ValueStack ("+tp.getClass().getName()+") could not locate the message resource with key '"+key+"'");
} else {
LOG.warn("Could not locate the message resource '"+key+"' as there is no TextProvider in the ValueStack.");
}
if (msg.equals(defaultMessage)) {
LOG.warn("The default value expression '"+defaultMessage+"' was evaluated and did not match a property. The literal value '"+defaultMessage+"' will be used.");