Return-Path: Delivered-To: apmail-struts-commits-archive@locus.apache.org Received: (qmail 72524 invoked from network); 14 Apr 2008 04:50:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Apr 2008 04:50:30 -0000 Received: (qmail 86534 invoked by uid 500); 14 Apr 2008 04:50:30 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 86076 invoked by uid 500); 14 Apr 2008 04:50:29 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Delivered-To: moderator for commits@struts.apache.org Received: (qmail 8124 invoked by uid 99); 14 Apr 2008 02:11:19 -0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r647647 - in /struts/struts2/trunk/core/src/main/java/org/apache/struts2: components/Label.java components/UIBean.java util/TextProviderHelper.java Date: Mon, 14 Apr 2008 02:10:56 -0000 To: commits@struts.apache.org From: jeromy@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080414021057.C65461A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jeromy Date: Sun Apr 13 19:10:42 2008 New Revision: 647647 URL: http://svn.apache.org/viewvc?rev=647647&view=rev Log: Added useful WARNs to the TextProviderHelper when a message resource is not found and the default value is used/evaluated WW-2592 Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Label.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/TextProviderHelper.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Label.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Label.java?rev=647647&r1=647646&r2=647647&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Label.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Label.java Sun Apr 13 19:10:42 2008 @@ -83,8 +83,8 @@ if (value != null) { addParameter("nameValue", findString(value)); } else if (key != null) { - // get the label from a TextProvider - String providedLabel = TextProviderHelper.getText(key, "", stack); + // get the label from a TextProvider (default value is the key) + String providedLabel = TextProviderHelper.getText(key, key, stack); addParameter("nameValue", providedLabel); } else if (name != null) { String expr = name; Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java?rev=647647&r1=647646&r2=647647&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java Sun Apr 13 19:10:42 2008 @@ -626,8 +626,8 @@ } if(this.label == null) { - // lookup the label from a TextProvider - providedLabel = TextProviderHelper.getText(key, "", stack); + // lookup the label from a TextProvider (default value is the key) + providedLabel = TextProviderHelper.getText(key, key, stack); } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/TextProviderHelper.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/TextProviderHelper.java?rev=647647&r1=647646&r2=647647&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/TextProviderHelper.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/TextProviderHelper.java Sun Apr 13 19:10:42 2008 @@ -1,6 +1,8 @@ package org.apache.struts2.util; import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.logging.Logger; +import com.opensymphony.xwork2.util.logging.LoggerFactory; import com.opensymphony.xwork2.TextProvider; import java.util.Iterator; @@ -12,6 +14,8 @@ */ public class TextProviderHelper { + private static final Logger LOG = LoggerFactory.getLogger(TextProviderHelper.class); + /** *

Get a message from the first TextProvider encountered in the stack. * If the first TextProvider doesn't provide the message the default message is returned.

@@ -19,23 +23,46 @@ *

This method was refactored from {@link org.apache.struts2.components.Text} to use a * consistent implementation across UIBean components.

* @param key the message key in the resource bundle - * @param defaultMessage the message to return if not found + * @param defaultMessage the message to return if not found (evaluated for OGNL) * @param args an array args to be used in a {@link java.text.MessageFormat} message * @param stack the value stack to use for finding the text * * @return the message if found, otherwise the defaultMessage */ public static String getText(String key, String defaultMessage, List args, ValueStack stack) { - String msg = defaultMessage; + String msg = null; + TextProvider tp = null; for (Iterator iterator = stack.getRoot().iterator(); iterator.hasNext();) { Object o = iterator.next(); if (o instanceof TextProvider) { - TextProvider tp = (TextProvider) o; - msg = tp.getText(key, defaultMessage, args, stack); + tp = (TextProvider) o; + msg = tp.getText(key, null, args, stack); break; + } + } + + if (msg == null) { + // evaluate the defaultMesage as an OGNL expression + 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."); + } else { + LOG.warn("The default value expression '"+defaultMessage+"' evaluated to '"+msg+"'"); + } } } return msg;