001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.text.MessageFormat;
018
019 import java.util.Locale;
020 import java.util.MissingResourceException;
021 import java.util.ResourceBundle;
022
023
027 public class ResourceBundleUtil {
028
029 public static String getString(
030 ResourceBundle resourceBundle, Locale locale, String key,
031 Object[] arguments) {
032
033 String value = getString(resourceBundle, key);
034
035 if (value == null) {
036 return null;
037 }
038
039
040
041
042
043 if (ArrayUtil.isNotEmpty(arguments)) {
044 MessageFormat messageFormat = new MessageFormat(value, locale);
045
046 value = messageFormat.format(arguments);
047 }
048
049 return value;
050 }
051
052 public static String getString(ResourceBundle resourceBundle, String key) {
053 if (!resourceBundle.containsKey(key)) {
054 return null;
055 }
056
057 try {
058 return resourceBundle.getString(key);
059 }
060 catch (MissingResourceException mre) {
061 return null;
062 }
063 }
064
065 }