}
}
}
}
MessageFormat formatter = new MessageFormat(pattern, this.getLocale());
Object retVal;
if(method.getReturnType().equals(SafeHtml.class)) {
Object[] safeArgs = null;
if(args != null) {
safeArgs = new Object[args.length];
for(int i = 0; i < args.length; i++) {
Object arg = args[i];
Class<?> argType = parameterTypes[i];
if(SafeHtml.class.isAssignableFrom(argType)) {
SafeHtml sh = (SafeHtml) arg;
safeArgs[i] = sh.asString();
} else if(Number.class.isAssignableFrom(argType)
|| Date.class.isAssignableFrom(argType)) {
// Because of the subformat pattern of dates and
// numbers, we cannot escape them.
safeArgs[i] = arg;
} else {
safeArgs[i] = SafeHtmlUtils.htmlEscape(arg.toString());
}
}
}
String formattedString = formatter.format(safeArgs, new StringBuffer(), null).toString();
// Would rather use fromSafeConstant() but doesn't work on server.
retVal = SafeHtmlUtils.fromTrustedString(formattedString);
} else {
retVal = formatter.format(args, new StringBuffer(), null).toString();
}
return retVal;
}