3m9 compatible;
[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.getBundle(BUNDLE_NAME);
25
26         private ActionMessages() {
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          * Returns the resource bundle managed by the receiver.
46          * 
47          * @return the resource bundle
48          * @since 3.0
49          */
50         public static ResourceBundle getResourceBundle() {
51                 return RESOURCE_BUNDLE;
52         }
53         /**
54          * Returns the formatted resource string associated with the given key in the resource bundle. 
55          * <code>MessageFormat</code> is used to format the message. If there isn't  any value 
56          * under the given key, the key is returned.
57          *
58          * @param key the resource key
59          * @param arg the message argument
60          * @return the string
61          */     
62         public static String getFormattedString(String key, Object arg) {
63                 return getFormattedString(key, new Object[] { arg });
64         }
65         
66         /**
67          * Returns the formatted resource string associated with the given key in the resource bundle. 
68          * <code>MessageFormat</code> is used to format the message. If there isn't  any value 
69          * under the given key, the key is returned.
70          *
71          * @param key the resource key
72          * @param args the message arguments
73          * @return the string
74          */     
75         public static String getFormattedString(String key, Object[] args) {
76                 return MessageFormat.format(getString(key), args);      
77         }       
78 }