Repository: struts
Updated Branches:
  refs/heads/develop eecd90763 -> 583234b8c


Adds additional logging of missing keys in resource bundles


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/583234b8
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/583234b8
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/583234b8

Branch: refs/heads/develop
Commit: 583234b8ccc24dc52c1b718a153126f7319de262
Parents: eecd907
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Mon Aug 25 08:42:50 2014 +0200
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Mon Aug 25 08:42:50 2014 +0200

----------------------------------------------------------------------
 .../apache/struts2/dispatcher/Dispatcher.java   |  3 ++
 .../xwork2/util/LocalizedTextUtil.java          | 38 +++++++++++++++-----
 2 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/583234b8/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java 
b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
index 95dc308..436490e 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
@@ -439,6 +439,9 @@ public class Dispatcher {
         boolean reloadi18n = 
Boolean.valueOf(container.getInstance(String.class, 
StrutsConstants.STRUTS_I18N_RELOAD));
         LocalizedTextUtil.setReloadBundles(reloadi18n);
 
+        boolean devMode = Boolean.valueOf(container.getInstance(String.class, 
StrutsConstants.STRUTS_DEVMODE));
+        LocalizedTextUtil.setDevMode(devMode);
+
         return container;
     }
 

http://git-wip-us.apache.org/repos/asf/struts/blob/583234b8/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
----------------------------------------------------------------------
diff --git 
a/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java 
b/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
index 9aad928..ec7860e 100644
--- 
a/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
+++ 
b/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
@@ -86,9 +86,13 @@ import java.util.concurrent.ConcurrentMap;
  */
 public class LocalizedTextUtil {
 
-    private static final ConcurrentMap<Integer, List<String>> classLoaderMap = 
new ConcurrentHashMap<Integer, List<String>>();
     private static final Logger LOG = 
LoggerFactory.getLogger(LocalizedTextUtil.class);
+
+    private static final ConcurrentMap<Integer, List<String>> classLoaderMap = 
new ConcurrentHashMap<Integer, List<String>>();
+
     private static boolean reloadBundles = false;
+    private static boolean devMode;
+
     private static final ConcurrentMap<String, ResourceBundle> bundlesMap = 
new ConcurrentHashMap<String, ResourceBundle>();
     private static final ConcurrentMap<MessageFormatKey, MessageFormat> 
messageFormats = new ConcurrentHashMap<MessageFormatKey, MessageFormat>();
     private static final ConcurrentMap<Integer, ClassLoader> 
delegatedClassLoaderMap = new ConcurrentHashMap<Integer, ClassLoader>();
@@ -120,6 +124,10 @@ public class LocalizedTextUtil {
         LocalizedTextUtil.reloadBundles = reloadBundles;
     }
 
+    public static void setDevMode(boolean devMode) {
+        LocalizedTextUtil.devMode = devMode;
+    }
+
     /**
      * Add's the bundle to the internal list of default bundles.
      * <p/>
@@ -129,7 +137,7 @@ public class LocalizedTextUtil {
      */
     public static void addDefaultResourceBundle(String resourceBundleName) {
         //make sure this doesn't get added more than once
-        ClassLoader ccl = null;
+        ClassLoader ccl;
         synchronized (XWORK_MESSAGES_BUNDLE) {
             ccl = getCurrentThreadContextClassLoader();
             List<String> bundles = classLoaderMap.get(ccl.hashCode());
@@ -207,7 +215,11 @@ public class LocalizedTextUtil {
                 try {
                     return bundle.getString(aTextName);
                 } catch (MissingResourceException e) {
-                    // ignore and try others
+                    if (devMode) {
+                        LOG.warn("Missing key [#0] in bundle [#1]!", 
aTextName, bundleName);
+                    } else if (LOG.isDebugEnabled()) {
+                        LOG.debug("Missing key [#0] in bundle [#1]!", 
aTextName, bundleName);
+                    }
                 }
             }
         }
@@ -265,6 +277,9 @@ public class LocalizedTextUtil {
                         bundle = bundlesMap.get(key);
                     }
                 } catch (MissingResourceException e) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Missing resource bundle [#0]!", 
aBundleName);
+                    }
                 }
             }
         }
@@ -273,8 +288,6 @@ public class LocalizedTextUtil {
 
     /**
      * 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 (bundlesMap) {
@@ -284,8 +297,6 @@ public class LocalizedTextUtil {
 
     /**
      * Removes the bundle from any cached "misses"
-     *
-     * @param bundleName
      */
     public static void clearBundle(final String bundleName) {
         bundlesMap.remove(getCurrentThreadContextClassLoader().hashCode() + 
bundleName);
@@ -524,7 +535,7 @@ public class LocalizedTextUtil {
         }
 
         // get default
-        GetDefaultMessageReturnArg result = null;
+        GetDefaultMessageReturnArg result;
         if (indexedTextName == null) {
             result = getDefaultMessage(aTextName, locale, valueStack, args, 
defaultMessage);
         } else {
@@ -627,7 +638,11 @@ public class LocalizedTextUtil {
 
             return formatWithNullDetection(mf, args);
         } catch (MissingResourceException ex) {
-            // ignore
+            if (devMode) {
+                LOG.warn("Missing key [#0] in bundle [#1]!", aTextName, 
bundle);
+            } else if (LOG.isDebugEnabled()) {
+                LOG.debug("Missing key [#0] in bundle [#1]!", aTextName, 
bundle);
+            }
         }
 
         GetDefaultMessageReturnArg result = getDefaultMessage(aTextName, 
locale, valueStack, args, defaultMessage);
@@ -679,6 +694,11 @@ public class LocalizedTextUtil {
             MessageFormat mf = buildMessageFormat(message, locale);
             return formatWithNullDetection(mf, args);
         } catch (MissingResourceException e) {
+            if (devMode) {
+                LOG.warn("Missing key [#0] in bundle [#1]!", key, bundleName);
+            } else if (LOG.isDebugEnabled()) {
+                LOG.debug("Missing key [#0] in bundle [#1]!", key, bundleName);
+            }
             return null;
         }
     }

Reply via email to