01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.readmetool;
11:
12: import java.text.MessageFormat;
13: import java.util.MissingResourceException;
14: import java.util.ResourceBundle;
15:
16: /**
17: * Utility class which helps with managing messages.
18: */
19: /* package */class MessageUtil {
20:
21: private static final String RESOURCE_BUNDLE = "org.eclipse.ui.examples.readmetool.messages";//$NON-NLS-1$
22:
23: private static ResourceBundle fgResourceBundle = ResourceBundle
24: .getBundle(RESOURCE_BUNDLE);
25:
26: private MessageUtil() {
27: // prevent instantiation of class
28: }
29:
30: /**
31: * Returns the formatted message for the given key in
32: * the resource bundle.
33: *
34: * @param key the resource name
35: * @param args the message arguments
36: * @return the string
37: */
38: public static String format(String key, Object[] args) {
39: return MessageFormat.format(getString(key), args);
40: }
41:
42: /**
43: * Returns the resource object with the given key in
44: * the resource bundle. If there isn't any value under
45: * the given key, the key is returned, surrounded by '!'s.
46: *
47: * @param key the resource name
48: * @return the string
49: */
50: public static String getString(String key) {
51: try {
52: return fgResourceBundle.getString(key);
53: } catch (MissingResourceException e) {
54: return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
55: }
56: }
57: }
|