KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > wizards > newresource > ResourceMessages


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

11 package org.eclipse.ui.wizards.newresource;
12
13 import java.text.MessageFormat JavaDoc;
14 import java.util.MissingResourceException JavaDoc;
15 import java.util.ResourceBundle JavaDoc;
16
17 /**
18  * Utility class which helps managing messages
19  */

20 class ResourceMessages {
21     private static final String JavaDoc RESOURCE_BUNDLE= "org.eclipse.ui.wizards.newresource.messages";//$NON-NLS-1$
22
private static ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
23
24 private ResourceMessages(){
25     // prevent instantiation of class
26
}
27 /**
28  * Returns the formatted message for the given key in
29  * the resource bundle.
30  *
31  * @param key the resource name
32  * @param args the message arguments
33  * @return the string
34  */

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

46 public static String JavaDoc getString(String JavaDoc key) {
47     try {
48         return bundle.getString(key);
49     } catch (MissingResourceException JavaDoc e) {
50         return key;
51     }
52 }
53 }
54
Popular Tags