Commits

Anonymous committed 16e5693

Add delegating class loader to text resolution
XW-682

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2@1938e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (1)

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

     private static final Collection misses = new HashSet();
     private static final Map messageFormats = new HashMap();
 
+    /**
+     * @GuardedBy #misses
+     */
+    private static ClassLoader delegatedClassLoader;
+
     static {
         clearDefaultResourceBundles();
     }
      * Finds the given resorce bundle by it's name.
      * <p/>
      * Will use <code>Thread.currentThread().getContextClassLoader()</code> as the classloader.
+     * If {@link #delegatedClassLoader} is defined and the bundle cannot be found the current classloader it will delegate to that.
      * 
      * @param aBundleName  the name of the bundle (usually it's FQN classname).
      * @param locale       the locale.
                     return ResourceBundle.getBundle(aBundleName, locale, Thread.currentThread().getContextClassLoader());
                 }
             } catch (MissingResourceException ex) {
-                misses.add(aBundleName);
+
+                if (delegatedClassLoader != null)
+                {
+                    try
+                    {
+                        return ResourceBundle.getBundle(aBundleName, locale, delegatedClassLoader);
+                    }
+                    catch (MissingResourceException e)
+                    {
+                        misses.add(aBundleName);
+                    }
+                }
+                else
+                {
+                    misses.add(aBundleName);
+                }
             }
         }
 
     }
 
     /**
+     * Sets a {@link ClassLoader} to look up the bundle from if none can be found on the current thread's classloader
+     *
+     * @param classLoader
+     */
+    public static void setDelegatedClassLoader(final ClassLoader classLoader)
+    {
+        synchronized (misses)
+        {
+            delegatedClassLoader = classLoader;
+        }
+    }
+
+    /**
+     * Removes the bundle from any cached "misses"
+     *
+     * @param bundleName
+     */
+    public static void clearBundle(final String bundleName)
+    {
+        synchronized (misses)
+        {
+            misses.remove(bundleName);
+        }
+    }
+
+
+    /**
      * Calls {@link #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)}
      * with aTextName as the default message.
      *
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.