KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > text > link > contentassist > ContentAssistMessages


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.jface.internal.text.link.contentassist;
13
14 import com.ibm.icu.text.MessageFormat;
15 import java.util.MissingResourceException JavaDoc;
16 import java.util.ResourceBundle JavaDoc;
17
18
19 /**
20  * Helper class to get NLSed messages.
21  *
22  * @since 3.0
23  */

24 class ContentAssistMessages {
25
26     private static final String JavaDoc RESOURCE_BUNDLE= ContentAssistMessages.class.getName();
27
28     private static ResourceBundle JavaDoc fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
29
30     private ContentAssistMessages() {
31     }
32
33     /**
34      * Gets a string from the resource bundle.
35      *
36      * @param key the string used to get the bundle value, must not be null
37      * @return the string from the resource bundle
38      */

39     public static String JavaDoc getString(String JavaDoc key) {
40         try {
41             return fgResourceBundle.getString(key);
42         } catch (MissingResourceException JavaDoc e) {
43             return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
44
}
45     }
46
47     /**
48      * Gets a string from the resource bundle and formats it with the given arguments.
49      *
50      * @param key the string used to get the bundle value, must not be null
51      * @param args the arguments used to format the string
52      * @return the formatted string
53      */

54     public static String JavaDoc getFormattedString(String JavaDoc key, Object JavaDoc[] args) {
55         String JavaDoc format= null;
56         try {
57             format= fgResourceBundle.getString(key);
58         } catch (MissingResourceException JavaDoc e) {
59             return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
60
}
61         return MessageFormat.format(format, args);
62     }
63
64     /**
65      * Gets a string from the resource bundle and formats it with the given argument.
66      *
67      * @param key the string used to get the bundle value, must not be null
68      * @param arg the argument used to format the string
69      * @return the formatted string
70      */

71     public static String JavaDoc getFormattedString(String JavaDoc key, Object JavaDoc arg) {
72         String JavaDoc format= null;
73         try {
74             format= fgResourceBundle.getString(key);
75         } catch (MissingResourceException JavaDoc e) {
76             return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
77
}
78         if (arg == null)
79             arg= ""; //$NON-NLS-1$
80
return MessageFormat.format(format, new Object JavaDoc[] { arg });
81     }
82 }
83
Popular Tags