You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2017/09/17 12:30:02 UTC

[myfaces-trinidad] 04/07: TRINIDAD-2196

This is an automated email from the ASF dual-hosted git repository.

deki pushed a commit to branch 1.2.12.5.0-branch
in repository https://gitbox.apache.org/repos/asf/myfaces-trinidad.git

commit ace05230e7ffa7c44ca222909ef1c033249a6898
Author: Scott Bryan <so...@apache.org>
AuthorDate: Wed Jan 18 20:22:27 2012 +0000

    TRINIDAD-2196
---
 .../apache/myfaces/trinidad/menu/MenuUtils.java    | 65 ++++++++-------------
 .../myfaces/trinidadinternal/menu/MenuUtils.java   | 66 ++++++++--------------
 2 files changed, 45 insertions(+), 86 deletions(-)

diff --git a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/menu/MenuUtils.java b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/menu/MenuUtils.java
index 441c183..60c6da4 100644
--- a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/menu/MenuUtils.java
+++ b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/menu/MenuUtils.java
@@ -33,7 +33,6 @@ import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.util.ContainerUtils;
-import org.apache.myfaces.trinidad.util.ThreadLocalUtils;
 
 /**
  * Menu Utilities used by the Menu Model internal code.
@@ -203,18 +202,17 @@ public class MenuUtils
   }
   
   /**
-   * Create a ResourceBundle and put it on the Session map.
-   * 
-   * @param resBundle - String containing name of class containing the resource
-   *                    bundle.
-   * @param key - ThreadLocal key for the resource bundle being put on the
-   *              requestMap
+   * Create a ResourceBundle and put it in an EL-reachable scope.
+   *
+   * @param resBundleName - String containing name of class containing the 
+   *                        resource bundle.
+   * @param resBundleKey - String key for the resource bundle
    */
   @SuppressWarnings("unchecked")
-  static void loadBundle(String resBundle, ThreadLocal<String> key)
+  static public void loadBundle(String resBundleName, String resBundleKey)
   {
     FacesContext facesContext = FacesContext.getCurrentInstance();
-    Map<String, Object> applicationMap = 
+    Map<String, Object> applicationMap =
       facesContext.getExternalContext().getApplicationMap();
 
     // Get the view root locale
@@ -225,22 +223,22 @@ public class MenuUtils
     {
       requestLocale = facesContext.getApplication().getDefaultLocale();
     }
-    
+
     // Is there a bundle with this key already on the session map?
-    _BundleMap bundleMap = (_BundleMap) applicationMap.get(key.get());
-    
-    // if so, get its locale.  If the locale has not 
+    _BundleMap bundleMap = (_BundleMap) applicationMap.get(resBundleKey);
+
+    // if so, get its locale.  If the locale has not
     // changed, just return, i.e. use the existing bundle
     if (bundleMap != null)
     {
       Locale bundleLocale = bundleMap.getLocale();
-      
+
       if (bundleLocale == null)
       {
         ResourceBundle rb = bundleMap.getBundle();
         bundleLocale = rb.getLocale();
       }
-      
+
       if (requestLocale == bundleLocale)
       {
         // the bundle on the applicationMap is ok so just return
@@ -250,21 +248,21 @@ public class MenuUtils
 
     String bundleName = null;
 
-    if (resBundle != null) 
+    if (resBundleName != null)
     {
       // if _bundleName is an EL, then get its value
-      if (ContainerUtils.isValueReference(resBundle)) 
+      if (ContainerUtils.isValueReference(resBundleName))
       {
-        bundleName = MenuUtils.getBoundValue(resBundle, String.class);
-      } 
+        bundleName = MenuUtils.getBoundValue(resBundleName, String.class);
+      }
       else
       {
-        bundleName = resBundle ;
+        bundleName = resBundleName ;
       }
     }
 
     final ResourceBundle bundle;
-    
+
     try
     {
       bundle = ResourceBundle.getBundle(bundleName, requestLocale);
@@ -275,30 +273,11 @@ public class MenuUtils
       _LOG.severe(e);
       return;
     }
- 
-    // Put the bundle in the map.  At this point the key is 
+
+    // Put the bundle in the map.  At this point the key is
     // unique because of the handler Id we inserted when loadBundle
     // was called.
-    applicationMap.put(key.get(), new _BundleMap(bundle, requestLocale));
-  }
-
-  /**
-   * Create a ResourceBundle and put it on the Session map.
-   * The key is made into a ThreadLocal to ensure that this the resource
-   * bundle is threadsafe.
-   * 
-   * @param resBundleName - String containing name of class containing the 
-   *                        resource bundle.
-   * @param resBundleKey - String key for the resource bundle being put on the
-   *                       requestMap
-   */
-  @SuppressWarnings("unchecked")
-  static public void loadBundle(String resBundleName, String resBundleKey)
-  {
-    ThreadLocal<String> bundleKey = ThreadLocalUtils.newRequestThreadLocal();
-    
-    bundleKey.set(resBundleKey);    
-    loadBundle(resBundleName, bundleKey);
+    applicationMap.put(resBundleKey, new _BundleMap(bundle, requestLocale));
   }
   
   /**
diff --git a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuUtils.java b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuUtils.java
index 1e9060f..8e9da3d 100644
--- a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuUtils.java
+++ b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuUtils.java
@@ -201,20 +201,19 @@ class MenuUtils
     }
     return Integer.parseInt(propVal);
   }
-  
+
   /**
-   * Create a ResourceBundle and put it on the Session map.
-   * 
-   * @param resBundle - String containing name of class containing the resource
-   *                    bundle.
-   * @param key - ThreadLocal key for the resource bundle being put on the
-   *              requestMap
+   * Create a ResourceBundle and put it an EL-reachable scope.
+   *
+   * @param resBundleName - String containing name of class containing the 
+   *                        resource bundle.
+   * @param resBundleKey - String key for the resource bundle\
    */
   @SuppressWarnings("unchecked")
-  static void loadBundle(String resBundle, ThreadLocal<String> key)
+  static void loadBundle(String resBundleName, String resBundleKey)
   {
     FacesContext facesContext = FacesContext.getCurrentInstance();
-    Map<String, Object> applicationMap = 
+    Map<String, Object> applicationMap =
       facesContext.getExternalContext().getApplicationMap();
 
     // Get the view root locale
@@ -225,22 +224,22 @@ class MenuUtils
     {
       requestLocale = facesContext.getApplication().getDefaultLocale();
     }
-    
+
     // Is there a bundle with this key already on the session map?
-    _BundleMap bundleMap = (_BundleMap) applicationMap.get(key.get());
-    
-    // if so, get its locale.  If the locale has not 
+    _BundleMap bundleMap = (_BundleMap) applicationMap.get(resBundleKey);
+
+    // if so, get its locale.  If the locale has not
     // changed, just return, i.e. use the existing bundle
     if (bundleMap != null)
     {
       Locale bundleLocale = bundleMap.getLocale();
-      
+
       if (bundleLocale == null)
       {
         ResourceBundle rb = bundleMap.getBundle();
         bundleLocale = rb.getLocale();
       }
-      
+
       if (requestLocale == bundleLocale)
       {
         // the bundle on the applicationMap is ok so just return
@@ -250,21 +249,21 @@ class MenuUtils
 
     String bundleName = null;
 
-    if (resBundle != null) 
+    if (resBundleName != null)
     {
       // if _bundleName is an EL, then get its value
-      if (ContainerUtils.isValueReference(resBundle)) 
+      if (ContainerUtils.isValueReference(resBundleName))
       {
-        bundleName = MenuUtils.getBoundValue(resBundle, String.class);
-      } 
+        bundleName = MenuUtils.getBoundValue(resBundleName, String.class);
+      }
       else
       {
-        bundleName = resBundle ;
+        bundleName = resBundleName ;
       }
     }
 
     final ResourceBundle bundle;
-    
+
     try
     {
       bundle = ResourceBundle.getBundle(bundleName, requestLocale);
@@ -275,30 +274,11 @@ class MenuUtils
       _LOG.severe(e);
       return;
     }
- 
-    // Put the bundle in the map.  At this point the key is 
+
+    // Put the bundle in the map.  At this point the key is
     // unique because of the handler Id we inserted when loadBundle
     // was called.
-    applicationMap.put(key.get(), new _BundleMap(bundle, requestLocale));
-  }
-
-  /**
-   * Create a ResourceBundle and put it on the Session map.
-   * The key is made into a ThreadLocal to ensure that this the resource
-   * bundle is threadsafe.
-   * 
-   * @param resBundleName - String containing name of class containing the 
-   *                        resource bundle.
-   * @param resBundleKey - String key for the resource bundle being put on the
-   *                       requestMap
-   */
-  @SuppressWarnings("unchecked")
-  static void loadBundle(String resBundleName, String resBundleKey)
-  {
-    ThreadLocal<String> bundleKey = ThreadLocalUtils.newRequestThreadLocal();
-    
-    bundleKey.set(resBundleKey);    
-    loadBundle(resBundleName, bundleKey);
+    applicationMap.put(resBundleKey, new _BundleMap(bundle, requestLocale));
   }
   
   /**

-- 
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.