You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Paul Benedict (JIRA)" <ji...@apache.org> on 2006/11/26 06:59:57 UTC

[jira] Updated: (STR-2923) PropertyMessageResources.getMessage uses loadLocale in wrong order

     [ http://issues.apache.org/struts/browse/STR-2923?page=all ]

Paul Benedict updated STR-2923:
-------------------------------

          Component/s: Core
        Fix Version/s: 1.3.6
    Affects Version/s: 1.3.5
                       1.2.9

> PropertyMessageResources.getMessage uses loadLocale in wrong order
> ------------------------------------------------------------------
>
>                 Key: STR-2923
>                 URL: http://issues.apache.org/struts/browse/STR-2923
>             Project: Struts 1
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.9, 1.2 Family, 1.3.5
>         Environment: default locale on windows platform is fi_FI
>            Reporter: Antti Tirkkonen
>            Priority: Minor
>             Fix For: 1.3.6
>
>
> if you have following messagebundles:
> bundle_fi.properties
> bundle.properties
> And want to any other locale except fi to use bundle.properties.  It is not possible  without setting JVM default locale something else than fi locale. Problem with this approach is that you possible end up effecting behaviour of other software running on the same JVM.
> To solve this problem PropertyMessageResources.getMessage implementation
> could be changed to do locale loading in different order.
> current order is: asked locale, asked locale minus underscore, JVM default locale, no locale
> proposed order: asked locale, asked locale minus underscore, no locale, JVM default locale
> Current code:
>    public String getMessage(Locale locale, String key) { 
>           if (log.isDebugEnabled()) { 
>               log.debug("getMessage(" + locale + "," + key + ")"); 
>           } 
>           String localeKey = localeKey(locale); 
>           String originalKey = messageKey(localeKey, key); 
>           String messageKey = null; 
>           String message = null; 
>           int underscore = 0; 
>           boolean addIt = false; 
>           while (true) { 
>               loadLocale(localeKey); 
>               messageKey = messageKey(localeKey, key); 
>               synchronized (messages) { 
>                   message = (String)messages.get(messageKey); 
>                   if (message != null) { 
>                       if (addIt) { 
>                           messages.put(originalKey, message); 
>                       } 
>                       return (message); 
>                   } 
>               } 
>               addIt = true; 
>               underscore = localeKey.lastIndexOf("_"); 
>               if (underscore < 0) { 
>                   break; 
>               } 
>               localeKey = localeKey.substring(0, underscore); 
>           } 
>           if (!defaultLocale.equals(locale)) { 
>               localeKey = localeKey(defaultLocale); 
>               messageKey = messageKey(localeKey, key); 
>               loadLocale(localeKey); 
>               synchronized (messages) { 
>                   message = (String)messages.get(messageKey); 
>                   if (message != null) { 
>                       messages.put(originalKey, message); 
>                       return (message); 
>                   } 
>               } 
>           } 
>           localeKey = ""; 
>           messageKey = messageKey(localeKey, key); 
>           loadLocale(localeKey); 
>           synchronized (messages) { 
>               message = (String)messages.get(messageKey); 
>               if (message != null) { 
>                   messages.put(originalKey, message); 
>                   return (message); 
>               } 
>           } 
>           if (returnNull) { 
>               return (null); 
>           } else  { 
>               return ("???" + messageKey(locale, key) + "???"); 
>          } 
>      } 
> proposed code:
>    public String getMessage(Locale locale, String key) { 
>           if (log.isDebugEnabled()) { 
>               log.debug("getMessage(" + locale + "," + key + ")"); 
>           } 
>           String localeKey = localeKey(locale); 
>           String originalKey = messageKey(localeKey, key); 
>           String messageKey = null; 
>           String message = null; 
>           int underscore = 0; 
>           boolean addIt = false; 
>           while (true) { 
>               loadLocale(localeKey); 
>               messageKey = messageKey(localeKey, key); 
>               synchronized (messages) { 
>                   message = (String)messages.get(messageKey); 
>                   if (message != null) { 
>                       if (addIt) { 
>                           messages.put(originalKey, message); 
>                       } 
>                       return (message); 
>                   } 
>               } 
>               addIt = true; 
>               underscore = localeKey.lastIndexOf("_"); 
>               if (underscore < 0) { 
>                   break; 
>               } 
>               localeKey = localeKey.substring(0, underscore); 
>           } 
>           localeKey = ""; 
>           messageKey = messageKey(localeKey, key); 
>           loadLocale(localeKey); 
>           synchronized (messages) { 
>               message = (String)messages.get(messageKey); 
>               if (message != null) { 
>                   messages.put(originalKey, message); 
>                   return (message); 
>               } 
>           } 
>           if (!defaultLocale.equals(locale)) { 
>               localeKey = localeKey(defaultLocale); 
>               messageKey = messageKey(localeKey, key); 
>               loadLocale(localeKey); 
>               synchronized (messages) { 
>                   message = (String)messages.get(messageKey); 
>                   if (message != null) { 
>                       messages.put(originalKey, message); 
>                       return (message); 
>                   } 
>               } 
>           } 
>           if (returnNull) { 
>               return (null); 
>           } else  { 
>               return ("???" + messageKey(locale, key) + "???"); 
>          } 
>      } 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira