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.propertysheet;
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.propertysheet.messages";//$NON-NLS-1$
22:
23: private static ResourceBundle fgResourceBundle = ResourceBundle
24: .getBundle(RESOURCE_BUNDLE);
25:
26: private MessageUtil() {
27: }
28:
29: /**
30: * Returns the formatted message for the given key in
31: * the resource bundle.
32: *
33: * @param key the resource name
34: * @param args the message arguments
35: * @return the string
36: */
37: public static String format(String key, Object[] args) {
38: return MessageFormat.format(getString(key), args);
39: }
40:
41: /**
42: * Returns the resource object with the given key in
43: * the resource bundle. If there isn't any value under
44: * the given key, the key is returned, surrounded by '!'s.
45: *
46: * @param key the resource name
47: * @return the string
48: */
49: public static String getString(String key) {
50: try {
51: return fgResourceBundle.getString(key);
52: } catch (MissingResourceException e) {
53: return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
54: }
55: }
56: }
|