001
014
015 package com.liferay.portlet;
016
017 import com.liferay.portal.kernel.util.ResourceBundleThreadLocal;
018 import com.liferay.portal.kernel.util.ResourceBundleUtil;
019
020 import java.util.Enumeration;
021 import java.util.MissingResourceException;
022 import java.util.ResourceBundle;
023
024
027 public class NullSafeResourceBundle extends ResourceBundle {
028
029 public NullSafeResourceBundle(ResourceBundle resourceBundle) {
030 if (resourceBundle == null) {
031 throw new NullPointerException();
032 }
033
034 setParent(resourceBundle);
035 }
036
037 @Override
038 public Enumeration<String> getKeys() {
039 return parent.getKeys();
040 }
041
042 @Override
043 protected Object handleGetObject(String key) {
044 if (key == null) {
045 throw new NullPointerException();
046 }
047
048 try {
049 return parent.getString(key);
050 }
051 catch (MissingResourceException mre) {
052 if (ResourceBundleThreadLocal.isReplace()) {
053 return ResourceBundleUtil.NULL_VALUE;
054 }
055 else {
056 throw mre;
057 }
058 }
059 }
060
061 }