KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > source > JFaceTextMessages


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.text.source;
13
14 import com.ibm.icu.text.MessageFormat;
15 import java.util.MissingResourceException JavaDoc;
16 import java.util.ResourceBundle JavaDoc;
17
18 /**
19  * Accessor for the <code>JFaceTextMessages.properties</code> file in
20  * package <code>org.eclipse.jface.text</code>.
21  * @since 2.0
22  */

23 class JFaceTextMessages {
24
25     /** The resource bundle name. */
26     private static final String JavaDoc RESOURCE_BUNDLE= "org.eclipse.jface.text.JFaceTextMessages";//$NON-NLS-1$
27

28     /** The resource bundle. */
29     private static ResourceBundle JavaDoc fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
30
31     /**
32      * Prohibits the creation of accessor objects.
33      */

34     private JFaceTextMessages() {
35     }
36
37     /**
38      * Returns the string found in the resource bundle under the given key or a place holder string.
39      *
40      * @param key the look up key
41      * @return the value found under the given key
42      */

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

59     public static String JavaDoc getFormattedString(String JavaDoc key, Object JavaDoc[] args) {
60         String JavaDoc format= null;
61         try {
62             format= fgResourceBundle.getString(key);
63         } catch (MissingResourceException JavaDoc e) {
64             return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
65
}
66         return MessageFormat.format(format, args);
67     }
68 }
69
Popular Tags