001
014
015 package com.liferay.util;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import java.text.MessageFormat;
021
022 import java.util.Locale;
023 import java.util.ResourceBundle;
024
025
028 public class ResourceBundleUtil {
029
030 public static String getString(
031 ResourceBundle resourceBundle, Locale locale, String key,
032 Object[] arguments) {
033
034 String value = null;
035
036 if (resourceBundle == null) {
037 if (_log.isErrorEnabled()) {
038 _log.error("Resource bundle is null");
039 }
040 }
041 else {
042
043
044
045
046
047 value = resourceBundle.getString(key);
048
049 if (value == null) {
050 if (_log.isWarnEnabled()) {
051 _log.warn("No value found for key " + key);
052 }
053 }
054 else {
055 if ((arguments != null) && (arguments.length > 0)) {
056 MessageFormat messageFormat = new MessageFormat(
057 value, locale);
058
059 value = messageFormat.format(arguments);
060 }
061 }
062 }
063
064 if (value == null) {
065 value = key;
066 }
067
068 return value;
069 }
070
071 private static Log _log = LogFactoryUtil.getLog(ResourceBundleUtil.class);
072
073 }