KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > text > html > HTMLMessages


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

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

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

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

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