Commits

plightbo  committed abaa12f

- null check
- formatting fixes (enough with the foo,bar!)

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@414e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 9c38d00

Comments (0)

Files changed (2)

File src/java/com/opensymphony/xwork/DefaultTextProvider.java

  */
 package com.opensymphony.xwork;
 
-import com.opensymphony.xwork.util.OgnlValueStack;
 import com.opensymphony.xwork.util.LocalizedTextUtil;
+import com.opensymphony.xwork.util.OgnlValueStack;
 
+import java.io.ObjectStreamException;
+import java.io.Serializable;
 import java.util.List;
 import java.util.ResourceBundle;
-import java.io.Serializable;
-import java.io.ObjectStreamException;
 
 /**
  * DefaultTextProvider gets texts from only the default resource bundles associated with the
  * LocalizedTextUtil.
  *
- * @see LocalizedTextUtil#addDefaultResourceBundle(String)
- *
  * @author Jason Carreira <jcarreira@gmail.com>
+ * @see LocalizedTextUtil#addDefaultResourceBundle(String)
  */
 public class DefaultTextProvider implements TextProvider, Serializable, Unchainable {
 
     }
 
     public String getText(String key) {
-        return LocalizedTextUtil.findDefaultText(key,ActionContext.getContext().getLocale());
+        return LocalizedTextUtil.findDefaultText(key, ActionContext.getContext().getLocale());
     }
 
     public String getText(String key, String defaultValue) {
     }
 
     public String getText(String key, List args) {
-        return LocalizedTextUtil.findDefaultText(key,ActionContext.getContext().getLocale(),args.toArray());
+        Object[] params;
+        if (args != null) {
+            params = args.toArray();
+        } else {
+            params = new Object[0];
+        }
+
+        return LocalizedTextUtil.findDefaultText(key, ActionContext.getContext().getLocale(), params);
     }
 
     public String getText(String key, String defaultValue, List args) {
-        String text = getText(key,args);
+        String text = getText(key, args);
         if (text == null) {
             return defaultValue;
         }
 
     public String getText(String key, String defaultValue, List args, OgnlValueStack stack) {
         //we're not using the value stack here
-        return getText(key,defaultValue,args);
+        return getText(key, defaultValue, args);
     }
 
     public ResourceBundle getTexts(String bundleName) {
-        return LocalizedTextUtil.findResourceBundle(bundleName,ActionContext.getContext().getLocale());
+        return LocalizedTextUtil.findResourceBundle(bundleName, ActionContext.getContext().getLocale());
     }
 
     public ResourceBundle getTexts() {

File src/java/com/opensymphony/xwork/util/LocalizedTextUtil.java

 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.ModelDriven;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-
 import java.text.MessageFormat;
-
 import java.util.*;
 
 
      * @param locale         the locale the message should be for
      * @param defaultMessage the message to be returned if no text message can be found in any
      *                       resource bundle
-     * @param valueStack the value stack to use to evaluate expressions instead of the
-     * one in the ActionContext ThreadLocal
+     * @param valueStack     the value stack to use to evaluate expressions instead of the
+     *                       one in the ActionContext ThreadLocal
      * @return the localized text, or null if none can be found and no defaultMessage is provided
      */
     public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack) {
 
         // nothing still? alright, search the package hierarchy now
         for (Class clazz = aClass;
-                (clazz != null) && !clazz.equals(Object.class);
-                clazz = clazz.getSuperclass()) {
+             (clazz != null) && !clazz.equals(Object.class);
+             clazz = clazz.getSuperclass()) {
             if (clazz.getPackage() != null) {
                 String packageName = clazz.getPackage().getName() + ".package";
                 msg = getMessage(packageName, locale, aTextName, valueStack, args);
         MessageFormatKey key = new MessageFormatKey(pattern, locale);
         MessageFormat format = (MessageFormat) messageFormats.get(key);
         if (format == null) {
-            synchronized(messageFormats) {
+            synchronized (messageFormats) {
                 format = new MessageFormat(pattern, locale);
                 messageFormats.put(key, format);
             }