KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > whirlycott > cache > Messages


1 /*
2 Copyright 2004 Philip Jacob <phil@whirlycott.com>
3                   Seth Fitzsimmons <seth@note.amherst.edu>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     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 JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.MissingResourceException JavaDoc;
27 import java.util.ResourceBundle JavaDoc;
28
29 /**
30  * Utility class for getting access to internationalized log messages.
31  *
32  * @author pjacob
33  *
34  */

35 public class Messages {
36     
37     private static final String JavaDoc BUNDLE_NAME = "com.whirlycott.cache.MessagesBundle"; //$NON-NLS-1$
38

39     private static final ResourceBundle JavaDoc RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault());
40
41     private Messages() {
42     }
43
44     public static String JavaDoc getString(final String JavaDoc _key) {
45         try {
46             return RESOURCE_BUNDLE.getString(_key);
47         } catch (final MissingResourceException JavaDoc e) {
48             return '!' + _key + '!';
49         }
50     }
51     
52     
53     public static String JavaDoc getCompoundString(final String JavaDoc key, final Object JavaDoc[] args) {
54         final MessageFormat JavaDoc formatter = new MessageFormat JavaDoc(Messages.getString(key));
55         return formatter.format(args);
56     }
57 }
58
59
Popular Tags