KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editorsupport > win32 > OleMessages


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.editorsupport.win32;
12
13 import com.ibm.icu.text.MessageFormat;
14 import java.util.MissingResourceException JavaDoc;
15 import java.util.ResourceBundle JavaDoc;
16
17 /**
18  * Utility class which helps managing messages
19  */

20 public class OleMessages {
21     private static final String JavaDoc RESOURCE_BUNDLE = "org.eclipse.ui.internal.editorsupport.win32.messages";//$NON-NLS-1$
22

23     private static ResourceBundle JavaDoc bundle = ResourceBundle
24             .getBundle(RESOURCE_BUNDLE);
25
26     private OleMessages() {
27         // prevent instantiation of class
28
}
29
30     /**
31      * Returns the formatted message for the given key in the resource bundle.
32      *
33      * @param key
34      * the resource name
35      * @param args
36      * the message arguments
37      * @return the string
38      */

39     public static String JavaDoc format(String JavaDoc key, Object JavaDoc[] args) {
40         return MessageFormat.format(getString(key), args);
41     }
42
43     /**
44      * Returns the resource object with the given key in the resource bundle. If
45      * there isn't any value under the given key, the key is returned.
46      *
47      * @param key
48      * the resource name
49      * @return the string
50      */

51     public static String JavaDoc getString(String JavaDoc key) {
52         try {
53             return bundle.getString(key);
54         } catch (MissingResourceException JavaDoc e) {
55             return key;
56         }
57     }
58
59     /**
60      * Returns the resource object with the given key in the resource bundle. If
61      * there isn't any value under the given key, the default value is returned.
62      *
63      * @param key
64      * the resource name
65      * @param def
66      * the default value
67      * @return the string
68      */

69     public static String JavaDoc getString(String JavaDoc key, String JavaDoc def) {
70         try {
71             return bundle.getString(key);
72         } catch (MissingResourceException JavaDoc e) {
73             return def;
74         }
75     }
76 }
77
Popular Tags