struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/actions LookupDispatchAction.java
Date Sat, 27 Jul 2002 23:49:59 GMT
craigmcc    2002/07/27 16:49:58

  Modified:    .        STATUS
               src/share/org/apache/struts/actions
                        LookupDispatchAction.java
  Log:
  Fix LookupDispatchAction to work when the button labels are generated
  from other locales.
  
  PR: Bugzilla #10322
    Bug report submitted by Henning Schmidt <h.schmidt at mkg-bank.de>
    Patch (thanks!) submitted by Scott Carlson <scott.carlson at yahoo.com>
  
  Revision  Changes    Path
  1.45      +2 -3      jakarta-struts/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/STATUS,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- STATUS	27 Jul 2002 23:26:08 -0000	1.44
  +++ STATUS	27 Jul 2002 23:49:58 -0000	1.45
  @@ -6,7 +6,7 @@
               OUTSTANDING BUGS IN STRUTS 1.1-b1 AND NIGHTLY BUILDS
               ====================================================
   
  -                           12 open bugs to swat!!
  +                           11 open bugs to swat!!
   
   
   Controller:
  @@ -36,7 +36,6 @@
   
   Standard Actions:
   ----------------
  -10322 Problems with LookupDispatchAction and other locales
   
   
   Tiles Framework:
  
  
  
  1.6       +29 -15    jakarta-struts/src/share/org/apache/struts/actions/LookupDispatchAction.java
  
  Index: LookupDispatchAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/actions/LookupDispatchAction.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LookupDispatchAction.java	25 Jun 2002 18:26:15 -0000	1.5
  +++ LookupDispatchAction.java	27 Jul 2002 23:49:58 -0000	1.6
  @@ -60,6 +60,7 @@
   import java.lang.reflect.Method;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Locale;
   import java.util.Map;
   
   import javax.servlet.ServletException;
  @@ -143,6 +144,7 @@
    *  is found then an exception will be thrown.
    *
    *@author     Erik Hatcher
  + *@author     Scott Carlson
    */
   
   public abstract class LookupDispatchAction extends DispatchAction {
  @@ -150,7 +152,7 @@
       /**
        * Reverse lookup map from resource value to resource key.
        */
  -    protected Map lookupMap = null;
  +    protected Map localeMap = new HashMap();
   
       /**
        * Resource key to method name lookup
  @@ -198,20 +200,32 @@
               throw new ServletException(message);
           }
   
  -        if (lookupMap == null) {
  -            // Build the key lookup map
  -            lookupMap = new HashMap();
  -            MessageResources resources = (MessageResources)
  -                request.getAttribute(Action.MESSAGES_KEY);
  -
  -            keyMethodMap = getKeyMethodMap();
  -
  -            Iterator iter = keyMethodMap.keySet().iterator();
  -            while (iter.hasNext()) {
  -                String key = (String) iter.next();
  -                String text = resources.getMessage(key);
  -                if ((text != null) && !lookupMap.containsKey(text)) {
  -                    lookupMap.put(text, key);
  +        // Based on this request's Locale get the lookupMap
  +        Map lookupMap = null;
  +        Locale userLocale = getLocale(request);
  +        boolean newLookupMap = false;
  +        synchronized (localeMap) {
  +            lookupMap = (Map) localeMap.get(userLocale);
  +            if (lookupMap == null) {
  +                newLookupMap = true;
  +                lookupMap = new HashMap();
  +                localeMap.put(userLocale, lookupMap);
  +            }
  +        }
  +        synchronized (lookupMap) {
  +            if (newLookupMap) {
  +                // This is the first time this Locale is used
  +                // Build the reverse lookup Map.
  +                MessageResources resources = (MessageResources)
  +                    request.getAttribute(Action.MESSAGES_KEY);
  +                keyMethodMap = getKeyMethodMap();
  +                Iterator iter = keyMethodMap.keySet().iterator();
  +                while (iter.hasNext()) {
  +                    String key = (String) iter.next();
  +                    String text = resources.getMessage(userLocale, key);
  +                    if ((text != null) && !lookupMap.containsKey(text)) {
  +                        lookupMap.put(text, key);
  +                    }
                   }
               }
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message