1
14
15 package com.liferay.util;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19
20 import java.text.MessageFormat;
21
22 import java.util.Locale;
23 import java.util.ResourceBundle;
24
25
30 public class ResourceBundleUtil {
31
32 public static String getString(
33 ResourceBundle resourceBundle, Locale locale, String key,
34 Object[] arguments) {
35
36 String value = null;
37
38 if (resourceBundle == null) {
39 if (_log.isErrorEnabled()) {
40 _log.error("Resource bundle is null");
41 }
42 }
43 else {
44
45
49 value = resourceBundle.getString(key);
50
51 if (value == null) {
52 if (_log.isWarnEnabled()) {
53 _log.warn("No value found for key " + key);
54 }
55 }
56 else {
57 if ((arguments != null) && (arguments.length > 0)) {
58 MessageFormat messageFormat = new MessageFormat(
59 value, locale);
60
61 value = messageFormat.format(arguments);
62 }
63 }
64 }
65
66 if (value == null) {
67 value = key;
68 }
69
70 return value;
71 }
72
73 private static Log _log = LogFactoryUtil.getLog(ResourceBundleUtil.class);
74
75 }