01: /*
02: Copyright 2004 Philip Jacob <phil@whirlycott.com>
03: Seth Fitzsimmons <seth@note.amherst.edu>
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: */
17:
18: /*
19: * Created on Dec 20, 2004 by pjacob
20: *
21: */
22: package com.whirlycott.cache;
23:
24: import java.text.MessageFormat;
25: import java.util.Locale;
26: import java.util.MissingResourceException;
27: import java.util.ResourceBundle;
28:
29: /**
30: * Utility class for getting access to internationalized log messages.
31: *
32: * @author pjacob
33: */
34: public class Messages {
35:
36: private static final String BUNDLE_NAME = "com.whirlycott.cache.MessagesBundle"; //$NON-NLS-1$
37:
38: private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
39: .getBundle(BUNDLE_NAME, Locale.getDefault());
40:
41: private Messages() {
42: }
43:
44: public static String getString(final String _key) {
45: try {
46: return RESOURCE_BUNDLE.getString(_key);
47: } catch (final MissingResourceException e) {
48: return '!' + _key + '!';
49: }
50: }
51:
52: public static String getCompoundString(final String key,
53: final Object... args) {
54: final MessageFormat formatter = new MessageFormat(Messages
55: .getString(key));
56: return formatter.format(args);
57: }
58: }
|