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.jdt.internal.ui.actions;
11:
12: import com.ibm.icu.text.MessageFormat;
13: import java.util.MissingResourceException;
14: import java.util.ResourceBundle;
15:
16: /**
17: * Class that gives access to the folding messages resource bundle.
18: */
19: public class FoldingMessages {
20:
21: private static final String BUNDLE_NAME = "org.eclipse.jdt.internal.ui.actions.FoldingMessages"; //$NON-NLS-1$
22:
23: private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
24: .getBundle(BUNDLE_NAME);
25:
26: private FoldingMessages() {
27: // no instance
28: }
29:
30: /**
31: * Returns the resource string associated with the given key in the resource bundle. If there isn't
32: * any value under the given key, the key is returned.
33: *
34: * @param key the resource key
35: * @return the string
36: */
37: public static String getString(String key) {
38: try {
39: return RESOURCE_BUNDLE.getString(key);
40: } catch (MissingResourceException e) {
41: return '!' + key + '!';
42: }
43: }
44:
45: /**
46: * Returns the resource bundle managed by the receiver.
47: *
48: * @return the resource bundle
49: * @since 3.0
50: */
51: public static ResourceBundle getResourceBundle() {
52: return RESOURCE_BUNDLE;
53: }
54:
55: /**
56: * Returns the formatted resource string associated with the given key in the resource bundle.
57: * <code>MessageFormat</code> is used to format the message. If there isn't any value
58: * under the given key, the key is returned.
59: *
60: * @param key the resource key
61: * @param arg the message argument
62: * @return the string
63: */
64: public static String getFormattedString(String key, Object arg) {
65: return getFormattedString(key, new Object[] { arg });
66: }
67:
68: /**
69: * Returns the formatted resource string associated with the given key in the resource bundle.
70: * <code>MessageFormat</code> is used to format the message. If there isn't any value
71: * under the given key, the key is returned.
72: *
73: * @param key the resource key
74: * @param args the message arguments
75: * @return the string
76: */
77: public static String getFormattedString(String key, Object[] args) {
78: return MessageFormat.format(getString(key), args);
79: }
80: }
|