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 95dc308ce..436490ea3 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; } 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 9aad92864..ec7860ec8 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> classLoaderMap = new ConcurrentHashMap>(); private static final Logger LOG = LoggerFactory.getLogger(LocalizedTextUtil.class); + + private static final ConcurrentMap> classLoaderMap = new ConcurrentHashMap>(); + private static boolean reloadBundles = false; + private static boolean devMode; + private static final ConcurrentMap bundlesMap = new ConcurrentHashMap(); private static final ConcurrentMap messageFormats = new ConcurrentHashMap(); private static final ConcurrentMap delegatedClassLoaderMap = new ConcurrentHashMap(); @@ -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. *

@@ -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 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; } }