You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2020/04/19 11:22:25 UTC
[myfaces] branch master updated: MYFACES-4330
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new aa72287 MYFACES-4330
aa72287 is described below
commit aa722874a15913d3b17859c11c95b4cde33a3d40
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Sun Apr 19 13:22:18 2020 +0200
MYFACES-4330
---
.../java/javax/faces/component/_MessageUtils.java | 9 +-
.../javax/faces/component/html/_MessageUtils.java | 9 +-
.../java/javax/faces/convert/_MessageUtils.java | 9 +-
.../java/javax/faces/validator/_MessageUtils.java | 11 +-
.../myfaces/application/ResourceHandlerImpl.java | 7 +-
.../apache/myfaces/taglib/core/LoadBundleTag.java | 31 +++--
.../java/org/apache/myfaces/util/MessageUtils.java | 125 +++++++++++++--------
.../facelets/tag/jsf/core/LoadBundleHandler.java | 22 ++--
8 files changed, 141 insertions(+), 82 deletions(-)
diff --git a/api/src/main/java/javax/faces/component/_MessageUtils.java b/api/src/main/java/javax/faces/component/_MessageUtils.java
index 431f84f..21fd8e1 100755
--- a/api/src/main/java/javax/faces/component/_MessageUtils.java
+++ b/api/src/main/java/javax/faces/component/_MessageUtils.java
@@ -128,12 +128,17 @@ class _MessageUtils
{
try
{
- return bundle == null ? null : bundle.getString(key);
+ if (bundle != null && bundle.containsKey(key))
+ {
+ return bundle.getString(key);
+ }
}
catch (MissingResourceException e)
{
- return null;
+ // NOOP
}
+
+ return null;
}
diff --git a/api/src/main/java/javax/faces/component/html/_MessageUtils.java b/api/src/main/java/javax/faces/component/html/_MessageUtils.java
index 69cb770..69a27d9 100755
--- a/api/src/main/java/javax/faces/component/html/_MessageUtils.java
+++ b/api/src/main/java/javax/faces/component/html/_MessageUtils.java
@@ -129,12 +129,17 @@ class _MessageUtils
{
try
{
- return bundle == null ? null : bundle.getString(key);
+ if (bundle != null && bundle.containsKey(key))
+ {
+ return bundle.getString(key);
+ }
}
catch (MissingResourceException e)
{
- return null;
+ // NOOP
}
+
+ return null;
}
diff --git a/api/src/main/java/javax/faces/convert/_MessageUtils.java b/api/src/main/java/javax/faces/convert/_MessageUtils.java
index 86012bf..d96f577 100755
--- a/api/src/main/java/javax/faces/convert/_MessageUtils.java
+++ b/api/src/main/java/javax/faces/convert/_MessageUtils.java
@@ -111,12 +111,17 @@ class _MessageUtils
{
try
{
- return bundle == null ? null : bundle.getString(key);
+ if (bundle != null && bundle.containsKey(key))
+ {
+ return bundle.getString(key);
+ }
}
catch (MissingResourceException e)
{
- return null;
+ // NOOP
}
+
+ return null;
}
diff --git a/api/src/main/java/javax/faces/validator/_MessageUtils.java b/api/src/main/java/javax/faces/validator/_MessageUtils.java
index abc20e3..c78d9a2 100755
--- a/api/src/main/java/javax/faces/validator/_MessageUtils.java
+++ b/api/src/main/java/javax/faces/validator/_MessageUtils.java
@@ -116,12 +116,17 @@ class _MessageUtils
{
try
{
- return bundle == null ? null : bundle.getString(key);
+ if (bundle != null && bundle.containsKey(key))
+ {
+ return bundle.getString(key);
+ }
}
catch (MissingResourceException e)
{
- return null;
+ // NOOP
}
+
+ return null;
}
@@ -175,7 +180,7 @@ class _MessageUtils
Thread.currentThread().getContextClassLoader());
}
}
- catch(PrivilegedActionException pae)
+ catch (PrivilegedActionException pae)
{
throw new FacesException(pae);
}
diff --git a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
index 1125064..2d84a36 100644
--- a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
@@ -695,8 +695,7 @@ public class ResourceHandlerImpl extends ResourceHandler
}
String bundleName = context.getApplication().getMessageBundle();
-
- if (null != bundleName)
+ if (bundleName != null)
{
Locale locale = null;
@@ -713,8 +712,7 @@ public class ResourceHandlerImpl extends ResourceHandler
{
ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale,
ClassUtils.getContextClassLoader());
-
- if (bundle != null)
+ if (bundle != null && bundle.containsKey(ResourceHandler.LOCALE_PREFIX))
{
localePrefix = bundle.getString(ResourceHandler.LOCALE_PREFIX);
}
@@ -724,6 +722,7 @@ public class ResourceHandlerImpl extends ResourceHandler
// Ignore it and return null
}
}
+
return localePrefix;
}
diff --git a/impl/src/main/java/org/apache/myfaces/taglib/core/LoadBundleTag.java b/impl/src/main/java/org/apache/myfaces/taglib/core/LoadBundleTag.java
index 6b72490..eac521a 100755
--- a/impl/src/main/java/org/apache/myfaces/taglib/core/LoadBundleTag.java
+++ b/impl/src/main/java/org/apache/myfaces/taglib/core/LoadBundleTag.java
@@ -162,6 +162,7 @@ public class LoadBundleTag extends TagSupport
// Optimized methods
+ @Override
public String get(Object key)
{
try
@@ -174,30 +175,26 @@ public class LoadBundleTag extends TagSupport
}
}
+ @Override
public boolean isEmpty()
{
return !_bundle.getKeys().hasMoreElements();
}
+ @Override
public boolean containsKey(Object key)
{
- try
- {
- return _bundle.getObject(key.toString()) != null;
- }
- catch (MissingResourceException e)
- {
- return false;
- }
+ return _bundle.containsKey(key.toString());
}
// Unoptimized methods
+ @Override
public Collection<String> values()
{
if (_values == null)
{
- _values = new ArrayList<String>();
+ _values = new ArrayList<>();
for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements();)
{
String v = _bundle.getString(enumer.nextElement());
@@ -207,34 +204,40 @@ public class LoadBundleTag extends TagSupport
return _values;
}
+ @Override
public int size()
{
return values().size();
}
+ @Override
public boolean containsValue(Object value)
{
return values().contains(value);
}
+ @Override
public Set<Map.Entry<String, String>> entrySet()
{
- Set<Entry<String, String>> set = new HashSet<Entry<String, String>>();
+ Set<Entry<String, String>> set = new HashSet<>();
for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements();)
{
final String k = enumer.nextElement();
set.add(new Map.Entry<String, String>()
{
+ @Override
public String getKey()
{
return k;
}
+ @Override
public String getValue()
{
return (String)_bundle.getObject(k);
}
+ @Override
public String setValue(String value)
{
throw new UnsupportedOperationException(this.getClass().getName()
@@ -245,9 +248,10 @@ public class LoadBundleTag extends TagSupport
return set;
}
+ @Override
public Set<String> keySet()
{
- Set<String> set = new HashSet<String>();
+ Set<String> set = new HashSet<>();
for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements();)
{
set.add(enumer.nextElement());
@@ -257,26 +261,29 @@ public class LoadBundleTag extends TagSupport
// Unsupported methods
+ @Override
public String remove(Object key)
{
throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
}
+ @Override
public void putAll(Map<? extends String, ? extends String> t)
{
throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
}
+ @Override
public String put(String key, String value)
{
throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
}
+ @Override
public void clear()
{
throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
}
-
}
}
diff --git a/impl/src/main/java/org/apache/myfaces/util/MessageUtils.java b/impl/src/main/java/org/apache/myfaces/util/MessageUtils.java
index ce86c93..dfe5790 100755
--- a/impl/src/main/java/org/apache/myfaces/util/MessageUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/util/MessageUtils.java
@@ -280,7 +280,10 @@ public final class MessageUtils
{
bundle = ResourceBundle.getBundle(bundleName, locale,
ClassUtils.getCurrentLoader(bundleName));
- summary = bundle.getString(messageId);
+ if (bundle.containsKey(messageId))
+ {
+ summary = bundle.getString(messageId);
+ }
}
catch (MissingResourceException e)
{
@@ -294,11 +297,15 @@ public final class MessageUtils
{
bundle = ResourceBundle.getBundle(DEFAULT_BUNDLE, locale,
ClassUtils.getCurrentLoader(DEFAULT_BUNDLE));
- if(bundle == null)
+ if (bundle == null)
{
throw new NullPointerException();
}
- summary = bundle.getString(messageId);
+
+ if (bundle.containsKey(messageId))
+ {
+ summary = bundle.getString(messageId);
+ }
}
catch(MissingResourceException e)
{
@@ -306,7 +313,7 @@ public final class MessageUtils
}
}
- if(summary == null)
+ if (summary == null)
{
summary = messageId;
}
@@ -316,11 +323,16 @@ public final class MessageUtils
throw new NullPointerException(
"Unable to locate ResourceBundle: bundle is null");
}
+
+ String detailMessageId = messageId + DETAIL_SUFFIX;
if (params != null && locale != null)
{
try
{
- detail = bundle.getString(messageId + DETAIL_SUFFIX);
+ if (bundle.containsKey(detailMessageId))
+ {
+ detail = bundle.getString(detailMessageId);
+ }
}
catch(MissingResourceException e)
{
@@ -333,8 +345,11 @@ public final class MessageUtils
summary = substituteParams(locale, summary, params);
try
{
- detail = substituteParams(locale,
- bundle.getString(messageId + DETAIL_SUFFIX), params);
+ if (bundle.containsKey(detailMessageId))
+ {
+ detail = substituteParams(locale,
+ bundle.getString(detailMessageId), params);
+ }
}
catch(MissingResourceException e)
{
@@ -358,7 +373,10 @@ public final class MessageUtils
{
bundle = ResourceBundle.getBundle(bundleName, locale,
ClassUtils.getCurrentLoader(bundleName));
- summary = bundle.getString(messageId);
+ if (bundle.containsKey(messageId))
+ {
+ summary = bundle.getString(messageId);
+ }
}
catch (MissingResourceException e)
{
@@ -372,11 +390,15 @@ public final class MessageUtils
{
bundle = ResourceBundle.getBundle(bundleBaseName, locale,
ClassUtils.getCurrentLoader(bundleBaseName));
- if(bundle == null)
+ if (bundle == null)
{
throw new NullPointerException();
}
- summary = bundle.getString(messageId);
+
+ if (bundle.containsKey(messageId))
+ {
+ summary = bundle.getString(messageId);
+ }
}
catch(MissingResourceException e)
{
@@ -390,11 +412,15 @@ public final class MessageUtils
{
bundle = ResourceBundle.getBundle(DEFAULT_BUNDLE, locale,
ClassUtils.getCurrentLoader(DEFAULT_BUNDLE));
- if(bundle == null)
+ if (bundle == null)
{
throw new NullPointerException();
}
- summary = bundle.getString(messageId);
+
+ if (bundle.containsKey(messageId))
+ {
+ summary = bundle.getString(messageId);
+ }
}
catch(MissingResourceException e)
{
@@ -402,7 +428,7 @@ public final class MessageUtils
}
}
- if(summary == null)
+ if (summary == null)
{
summary = messageId;
}
@@ -413,11 +439,15 @@ public final class MessageUtils
"Unable to locate ResourceBundle: bundle is null");
}
+ String detailMessageId = messageId + DETAIL_SUFFIX;
if (params != null && locale != null)
{
try
{
- detail = bundle.getString(messageId + DETAIL_SUFFIX);
+ if (bundle.containsKey(detailMessageId))
+ {
+ detail = bundle.getString(detailMessageId);
+ }
}
catch(MissingResourceException e)
{
@@ -430,8 +460,11 @@ public final class MessageUtils
summary = substituteParams(locale, summary, params);
try
{
- detail = substituteParams(locale,
- bundle.getString(messageId + DETAIL_SUFFIX), params);
+ if (bundle.containsKey(detailMessageId))
+ {
+ detail = substituteParams(locale,
+ bundle.getString(detailMessageId), params);
+ }
}
catch(MissingResourceException e)
{
@@ -529,38 +562,42 @@ public final class MessageUtils
*/
public static FacesMessage getMessage(ResourceBundle bundle, String messageId, Object params[])
{
+ String summary = null;
+ String detail = null;
- String summary = null;
- String detail = null;
-
- try
- {
- summary = bundle.getString(messageId);
- }
- catch (MissingResourceException e)
- {
- // NoOp
- }
-
-
- if(summary == null)
- {
- summary = messageId;
- }
+ try
+ {
+ if (bundle.containsKey(messageId))
+ {
+ summary = bundle.getString(messageId);
+ }
+ }
+ catch (MissingResourceException e)
+ {
+ // NoOp
+ }
- summary = substituteParams(bundle.getLocale(), summary, params);
+ if (summary == null)
+ {
+ summary = messageId;
+ }
+ summary = substituteParams(bundle.getLocale(), summary, params);
- try
- {
- detail = substituteParams(bundle.getLocale(),
- bundle.getString(messageId + DETAIL_SUFFIX), params);
- }
- catch(MissingResourceException e)
- {
- // NoOp
- }
+ try
+ {
+ String detailMessageId = messageId + DETAIL_SUFFIX;
+ if (bundle.containsKey(detailMessageId))
+ {
+ detail = substituteParams(bundle.getLocale(),
+ bundle.getString(detailMessageId), params);
+ }
+ }
+ catch(MissingResourceException e)
+ {
+ // NoOp
+ }
- return new FacesMessage(summary, detail);
+ return new FacesMessage(summary, detail);
}
/**
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/LoadBundleHandler.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/LoadBundleHandler.java
index dc7b767..4474aff 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/LoadBundleHandler.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/LoadBundleHandler.java
@@ -24,7 +24,6 @@ import java.util.Enumeration;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
-import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
@@ -118,15 +117,7 @@ public final class LoadBundleHandler extends TagHandler
@Override
public boolean containsKey(Object key)
{
- try
- {
- bundle.getString(key.toString());
- return true;
- }
- catch (MissingResourceException e)
- {
- return false;
- }
+ return bundle.containsKey(key.toString());
}
@Override
@@ -139,7 +130,7 @@ public final class LoadBundleHandler extends TagHandler
public Set<Map.Entry<String, String>> entrySet()
{
Enumeration<String> e = this.bundle.getKeys();
- Set<Map.Entry<String, String>> s = new HashSet<Map.Entry<String, String>>();
+ Set<Map.Entry<String, String>> s = new HashSet<>();
String k;
while (e.hasMoreElements())
{
@@ -154,12 +145,17 @@ public final class LoadBundleHandler extends TagHandler
{
try
{
- return this.bundle.getString((String) key);
+ if (this.bundle.containsKey((String) key))
+ {
+ return this.bundle.getString((String) key);
+ }
}
catch (java.util.MissingResourceException mre)
{
- return "???" + key + "???";
+ // NOOP
}
+
+ return "???" + key + "???";
}
@Override