KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > r21 > R21PresentationMessages


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.presentations.r21;
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 abstract class R21PresentationMessages {
21
22     private static final String JavaDoc RESOURCE_BUNDLE = "org.eclipse.ui.internal.presentations.r21.messages"; //$NON-NLS-1$
23

24     private static ResourceBundle JavaDoc bundle = ResourceBundle
25             .getBundle(RESOURCE_BUNDLE);
26
27     /**
28      * Returns the formatted message for the given key in the resource bundle.
29      *
30      * @param key
31      * the resource name
32      * @param args
33      * the message arguments
34      * @return the string
35      */

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

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

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