KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > antadapter > AntAdapterMessages


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 package org.eclipse.jdt.internal.antadapter;
12
13 import java.text.MessageFormat JavaDoc;
14 import java.util.Locale JavaDoc;
15 import java.util.MissingResourceException JavaDoc;
16 import java.util.ResourceBundle JavaDoc;
17
18 public class AntAdapterMessages {
19
20     private static final String JavaDoc BUNDLE_NAME = "org.eclipse.jdt.internal.antadapter.messages"; //$NON-NLS-1$
21

22     private static ResourceBundle JavaDoc RESOURCE_BUNDLE;
23     
24     static {
25         try {
26         RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault());
27         } catch(MissingResourceException JavaDoc e) {
28             System.out.println("Missing resource : " + BUNDLE_NAME.replace('.', '/') + ".properties for locale " + Locale.getDefault()); //$NON-NLS-1$//$NON-NLS-2$
29
throw e;
30         }
31     }
32
33     private AntAdapterMessages() {
34         // cannot be instantiated
35
}
36
37     public static String JavaDoc getString(String JavaDoc key) {
38         try {
39             return RESOURCE_BUNDLE.getString(key);
40         } catch (MissingResourceException JavaDoc e) {
41             return '!' + key + '!';
42         }
43     }
44
45     public static String JavaDoc getString(String JavaDoc key, String JavaDoc argument) {
46         try {
47             String JavaDoc message = RESOURCE_BUNDLE.getString(key);
48             MessageFormat JavaDoc messageFormat = new MessageFormat JavaDoc(message);
49             return messageFormat.format(new String JavaDoc[] { argument } );
50         } catch (MissingResourceException JavaDoc e) {
51             return '!' + key + '!';
52         }
53     }
54 }
55
Popular Tags