Author: lukaszlenart Date: Mon Apr 12 11:28:09 2010 New Revision: 933195 URL: http://svn.apache.org/viewvc?rev=933195&view=rev Log: Resolved WW-3322 - proper way for handling missing values in text formatting messages
Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java?rev=933195&r1=933194&r2=933195&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java Mon Apr 12 11:28:09 2010 @@ -219,7 +219,7 @@ public class LocalizedTextUtil { String defaultText = findDefaultText(aTextName, locale); if (defaultText != null) { MessageFormat mf = buildMessageFormat(defaultText, locale); - return mf.format(params); + return formatWithNullDetection(mf, params); } return null; } @@ -662,7 +662,7 @@ public class LocalizedTextUtil { String message = TextParseUtil.translateVariables(bundle.getString(aTextName), valueStack); MessageFormat mf = buildMessageFormat(message, locale); - return mf.format(args); + return formatWithNullDetection(mf, args); } catch (MissingResourceException ex) { // ignore } @@ -698,7 +698,7 @@ public class LocalizedTextUtil { if (message != null) { MessageFormat mf = buildMessageFormat(TextParseUtil.translateVariables(message, valueStack), locale); - String msg = mf.format(args); + String msg = formatWithNullDetection(mf, args); result = new GetDefaultMessageReturnArg(msg, found); } } @@ -725,12 +725,21 @@ public class LocalizedTextUtil { try { String message = TextParseUtil.translateVariables(bundle.getString(key), valueStack); MessageFormat mf = buildMessageFormat(message, locale); - return mf.format(args); + return formatWithNullDetection(mf, args); } catch (MissingResourceException e) { return null; } } + private static String formatWithNullDetection(MessageFormat mf, Object[] args) { + String message = mf.format(args); + if ("null".equals(message)) { + return null; + } else { + return message; + } + } + private static MessageFormat buildMessageFormat (String pattern, Locale