Commits

Anonymous committed f551599

merging my Locale changes with Jason's -- I think this is a good mix :) (I removed a bunch of stuff, basically)

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

  • Participants
  • Parent commits 9640204

Comments (0)

Files changed (6)

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

 
 
 /**
- * Created by IntelliJ IDEA.
  * User: Mike
  * Date: May 27, 2003
  * Time: 3:45:29 PM
- * To change this template use Options | File Templates.
  */
 public class ActionSupport implements Action, Serializable, Validateable, ValidationAware, TextProvider, LocaleProvider {
     //~ Static fields/initializers /////////////////////////////////////////////
     }
 
     public Locale getLocale() {
-        return ActionContext.getContext().getLocale();
+        return (ActionContext.getContext() != null) ?
+                ActionContext.getContext().getLocale() :
+                null;
     }
 
+
     public String getText(String aTextName) {
         return textProvider.getText(aTextName);
     }

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

 import org.apache.commons.logging.LogFactory;
 
 import java.util.Map;
+import java.util.Locale;
 
 
 /**
             String message;
 
             if ((namespace != null) && (namespace.trim().length() > 0)) {
-                message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION, new String[] {
+                message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION,
+                        Locale.getDefault(),
+                        new String[] {
                             namespace, actionName
                         });
             } else {
-                message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION, new String[] {
+                message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION,
+                        Locale.getDefault(),
+                        new String[] {
                             actionName
                         });
             }

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

     * @return     value of named text
     */
     public String getText(String aTextName) {
-        return LocalizedTextUtil.findText(clazz, aTextName);
+        return LocalizedTextUtil.findText(clazz, aTextName, getLocale());
     }
 
     /**

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

         }
     }
 
-    public static String findDefaultText(String aTextName) throws MissingResourceException {
-        return findDefaultText(aTextName, ActionContext.getContext().getLocale());
-    }
-
     public static String findDefaultText(String aTextName, Locale locale) throws MissingResourceException {
         MissingResourceException e = null;
         List localList = new ArrayList(DEFAULT_RESOURCE_BUNDLES);
      * @return A formatted message based on the key specified
      * @throws MissingResourceException
      */
-    public static String findDefaultText(String aTextName, Object[] params) throws MissingResourceException {
-        return MessageFormat.format(findDefaultText(aTextName), params);
-    }
-
-    public static ResourceBundle findResourceBundle(String aBundleName) {
-        return findResourceBundle(aBundleName, ActionContext.getContext().getLocale());
+    public static String findDefaultText(String aTextName, Locale locale, Object[] params) throws MissingResourceException {
+        return MessageFormat.format(findDefaultText(aTextName, locale), params);
     }
 
     public static ResourceBundle findResourceBundle(String aBundleName, Locale locale) {
     }
 
     /**
-     * Calls {@link #findText(Class aClass, String aTextName, Locale locale)} with
-     * {@link com.opensymphony.xwork.ActionContext#getLocale()} as the locale.
-     * @see #findText(Class aClass, String aTextName, Locale locale)
-     * @see com.opensymphony.xwork.ActionContext#getLocale()
-     */
-    public static String findText(Class aClass, String aTextName) {
-        return findText(aClass, aTextName, ActionContext.getContext().getLocale());
-    }
-
-    /**
      * Calls {@link #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)} with
      * aTextName as the default message.
      * @see #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)

File src/test/com/opensymphony/xwork/util/LocalizedTextUtilTest.java

 
     public void testAddDefaultResourceBundle() {
         try {
-            String message = LocalizedTextUtil.findDefaultText("foo.range");
+            String message = LocalizedTextUtil.findDefaultText("foo.range", Locale.getDefault());
             fail("Found message when it should not be available.");
         } catch (MissingResourceException e) {
         }
 
     public void testDefaultMessage() {
         try {
-            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR);
+            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
             assertEquals("Error during Action invocation", message);
         } catch (MissingResourceException e) {
             e.printStackTrace();
 
     public void testDefaultMessageOverride() {
         try {
-            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR);
+            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
             assertEquals("Error during Action invocation", message);
         } catch (MissingResourceException e) {
             e.printStackTrace();
         LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork/test");
 
         try {
-            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR);
+            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
             assertEquals("Testing resource bundle override", message);
         } catch (MissingResourceException e) {
             e.printStackTrace();
 
     public void testParameterizedDefaultMessage() {
         try {
-            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION, new String[]{
+            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION,
+                    Locale.getDefault(),
+                    new String[]{
                 "AddUser"
             });
             assertEquals("There is no Action mapped for action name AddUser", message);
 
     public void testParameterizedDefaultMessageWithPackage() {
         try {
-            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION, new String[]{
+            String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION,
+                    Locale.getDefault(),
+                    new String[]{
                 "blah", "AddUser"
             });
             assertEquals("There is no Action mapped for namespace blah and action name AddUser", message);

File src/test/com/opensymphony/xwork/util/XWorkConverterTest.java

     protected void setUp() throws Exception {
         converter = XWorkConverter.getInstance();
         ConfigurationManager.destroyConfiguration();
-        ActionContext.setContext(null);
+        OgnlValueStack stack = new OgnlValueStack();
+        ActionContext ac = new ActionContext(stack.getContext());
+        ac.setLocale(Locale.US);
+        ActionContext.setContext(ac);
     }
 
     protected void tearDown() throws Exception {
         XWorkConverter.resetInstance();
+        ActionContext.setContext(null);
     }
 }