91d813272dc88ed05951cb0da30ec80786642840
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / actions / ActionMessages.java
1 /*******************************************************************************
2  * Copyright (c) 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
12
13 import java.text.MessageFormat;
14 import java.util.MissingResourceException;
15 import java.util.ResourceBundle;
16
17 /**
18  * Class that gives access to the action messages resource bundle.
19  */
20 public class ActionMessages {
21
22         private static final String BUNDLE_NAME = "net.sourceforge.phpdt.internal.ui.actions.ActionMessages"; //$NON-NLS-1$
23
24         private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
25                         .getBundle(BUNDLE_NAME);
26
27         private ActionMessages() {
28                 // no instance
29         }
30
31         /**
32          * Returns the resource string associated with the given key in the resource
33          * bundle. If there isn't any value under the given key, the key is
34          * returned.
35          * 
36          * @param key
37          *            the resource key
38          * @return the string
39          */
40         public static String getString(String key) {
41                 try {
42                         return RESOURCE_BUNDLE.getString(key);
43                 } catch (MissingResourceException e) {
44                         return '!' + key + '!';
45                 }
46         }
47
48         /**
49          * Returns the resource bundle managed by the receiver.
50          * 
51          * @return the resource bundle
52          * @since 3.0
53          */
54         public static ResourceBundle getResourceBundle() {
55                 return RESOURCE_BUNDLE;
56         }
57
58         /**
59          * Returns the formatted resource string associated with the given key in
60          * the resource bundle. <code>MessageFormat</code> is used to format the
61          * message. If there isn't any value under the given key, the key is
62          * returned.
63          * 
64          * @param key
65          *            the resource key
66          * @param arg
67          *            the message argument
68          * @return the string
69          */
70         public static String getFormattedString(String key, Object arg) {
71                 return getFormattedString(key, new Object[] { arg });
72         }
73
74         /**
75          * Returns the formatted resource string associated with the given key in
76          * the resource bundle. <code>MessageFormat</code> is used to format the
77          * message. If there isn't any value under the given key, the key is
78          * returned.
79          * 
80          * @param key
81          *            the resource key
82          * @param args
83          *            the message arguments
84          * @return the string
85          */
86         public static String getFormattedString(String key, Object[] args) {
87                 return MessageFormat.format(getString(key), args);
88         }
89 }