Prep required for the o.a.tomcat.util.res.StringManager to replace the o.a.c.util...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 13 Jul 2009 21:49:14 +0000 (21:49 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 13 Jul 2009 21:49:14 +0000 (21:49 +0000)
Adds handling for when classloaders common != server != shared

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@793722 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/res/StringManager.java

index 1b6381f..a7b8765 100644 (file)
@@ -68,9 +68,25 @@ public class StringManager {
      */
     private StringManager(String packageName) {
         String bundleName = packageName + ".LocalStrings";
-        bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
+        try {
+            bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
+        } catch( MissingResourceException ex ) {
+            // Try from the current loader (that's the case for trusted apps)
+            // Should only be required if using a TC5 style classloader structure
+            // where common != shared != server
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            if( cl != null ) {
+                try {
+                    bundle = ResourceBundle.getBundle(
+                            bundleName, Locale.getDefault(), cl);
+                } catch(MissingResourceException ex2) {
+                }
+            }
+        }
         // Get the actual locale, which may be different from the requested one
-        locale = bundle.getLocale();
+        if (bundle != null) {
+            locale = bundle.getLocale();
+        }
     }
 
     /**