WW-4762 Extracts common method
Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/fd168c42 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/fd168c42 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/fd168c42 Branch: refs/heads/master Commit: fd168c423f70383a6240cba9809a87b661ef39de Parents: 7360b5e Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Wed May 10 14:12:39 2017 +0200 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Wed May 10 14:12:39 2017 +0200 ---------------------------------------------------------------------- .../util/AbstractLocalizedTextProvider.java | 59 ++++++++++++++++++++ .../util/DefaultLocalizedTextProvider.java | 48 ---------------- .../util/StrutsLocalizedTextProvider.java | 58 ------------------- 3 files changed, 59 insertions(+), 106 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/fd168c42/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java index 1c11fec..fcef47e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java @@ -148,6 +148,55 @@ abstract class AbstractLocalizedTextProvider implements LocalizedTextProvider { return null; } + + /** + * <p> + * Finds a localized text message for the given key, aTextName, in the specified resource + * bundle. + * </p> + * + * <p> + * If a message is found, it will also be interpolated. Anything within <code>${...}</code> + * will be treated as an OGNL expression and evaluated as such. + * </p> + * + * <p> + * If a message is <b>not</b> found a WARN log will be logged. + * </p> + * + * @param bundle the bundle + * @param aTextName the key + * @param locale the locale + * @param defaultMessage the default message to use if no message was found in the bundle + * @param args arguments for the message formatter. + * @param valueStack the OGNL value stack. + * @return the localized text, or null if none can be found and no defaultMessage is provided + */ + @Override + public String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, + ValueStack valueStack) { + try { + reloadBundles(valueStack.getContext()); + + String message = TextParseUtil.translateVariables(bundle.getString(aTextName), valueStack); + MessageFormat mf = buildMessageFormat(message, locale); + + return formatWithNullDetection(mf, args); + } catch (MissingResourceException ex) { + if (devMode) { + LOG.warn("Missing key [{}] in bundle [{}]!", aTextName, bundle); + } else { + LOG.debug("Missing key [{}] in bundle [{}]!", aTextName, bundle); + } + } + + GetDefaultMessageReturnArg result = getDefaultMessage(aTextName, locale, valueStack, args, defaultMessage); + if (unableToFindTextForKey(result)) { + LOG.warn("Unable to find text for key '{}' in ResourceBundles for locale '{}'", aTextName, locale); + } + return result != null ? result.message : null; + } + /** * @param classLoader a {@link ClassLoader} to look up the bundle from if none can be found on the current thread's classloader */ @@ -320,6 +369,16 @@ abstract class AbstractLocalizedTextProvider implements LocalizedTextProvider { } return bundle; } + + /** + * Clears all the internal lists. + * + * @deprecated used only in tests + */ + @Deprecated + public void reset() { + // no-op + } /** * Determines if we found the text in the bundles. http://git-wip-us.apache.org/repos/asf/struts/blob/fd168c42/core/src/main/java/com/opensymphony/xwork2/util/DefaultLocalizedTextProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/com/opensymphony/xwork2/util/DefaultLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/DefaultLocalizedTextProvider.java index acd3943..a709180 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/DefaultLocalizedTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/DefaultLocalizedTextProvider.java @@ -259,52 +259,4 @@ public class DefaultLocalizedTextProvider extends AbstractLocalizedTextProvider return findText(bundle, aTextName, locale, defaultMessage, args, valueStack); } - /** - * <p> - * Finds a localized text message for the given key, aTextName, in the specified resource - * bundle. - * </p> - * - * <p> - * If a message is found, it will also be interpolated. Anything within <code>${...}</code> - * will be treated as an OGNL expression and evaluated as such. - * </p> - * - * <p> - * If a message is <b>not</b> found a WARN log will be logged. - * </p> - * - * @param bundle the bundle - * @param aTextName the key - * @param locale the locale - * @param defaultMessage the default message to use if no message was found in the bundle - * @param args arguments for the message formatter. - * @param valueStack the OGNL value stack. - * @return the localized text, or null if none can be found and no defaultMessage is provided - */ - @Override - public String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, - ValueStack valueStack) { - try { - reloadBundles(valueStack.getContext()); - - String message = TextParseUtil.translateVariables(bundle.getString(aTextName), valueStack); - MessageFormat mf = buildMessageFormat(message, locale); - - return formatWithNullDetection(mf, args); - } catch (MissingResourceException ex) { - if (devMode) { - LOG.warn("Missing key [{}] in bundle [{}]!", aTextName, bundle); - } else { - LOG.debug("Missing key [{}] in bundle [{}]!", aTextName, bundle); - } - } - - GetDefaultMessageReturnArg result = getDefaultMessage(aTextName, locale, valueStack, args, defaultMessage); - if (unableToFindTextForKey(result)) { - LOG.warn("Unable to find text for key '{}' in ResourceBundles for locale '{}'", aTextName, locale); - } - return result != null ? result.message : null; - } - } http://git-wip-us.apache.org/repos/asf/struts/blob/fd168c42/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java index 0b97279..a31c4ae 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/StrutsLocalizedTextProvider.java @@ -419,62 +419,4 @@ public class StrutsLocalizedTextProvider extends AbstractLocalizedTextProvider { return findText(bundle, aTextName, locale, defaultMessage, args, valueStack); } - /** - * <p> - * Finds a localized text message for the given key, aTextName, in the specified resource - * bundle. - * </p> - * - * <p> - * If a message is found, it will also be interpolated. Anything within <code>${...}</code> - * will be treated as an OGNL expression and evaluated as such. - * </p> - * - * <p> - * If a message is <b>not</b> found a WARN log will be logged. - * </p> - * - * @param bundle the bundle - * @param aTextName the key - * @param locale the locale - * @param defaultMessage the default message to use if no message was found in the bundle - * @param args arguments for the message formatter. - * @param valueStack the OGNL value stack. - * @return the localized text, or null if none can be found and no defaultMessage is provided - */ - @Override - public String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, - ValueStack valueStack) { - try { - reloadBundles(valueStack.getContext()); - - String message = TextParseUtil.translateVariables(bundle.getString(aTextName), valueStack); - MessageFormat mf = buildMessageFormat(message, locale); - - return formatWithNullDetection(mf, args); - } catch (MissingResourceException ex) { - if (devMode) { - LOG.warn("Missing key [{}] in bundle [{}]!", aTextName, bundle); - } else { - LOG.debug("Missing key [{}] in bundle [{}]!", aTextName, bundle); - } - } - - GetDefaultMessageReturnArg result = getDefaultMessage(aTextName, locale, valueStack, args, defaultMessage); - if (unableToFindTextForKey(result)) { - LOG.warn("Unable to find text for key '{}' in ResourceBundles for locale '{}'", aTextName, locale); - } - return result != null ? result.message : null; - } - - /** - * Clears all the internal lists. - * - * @deprecated used only in tests - */ - @Deprecated - public void reset() { - // no-op - } - }