Created a separated 'externaltools' plugin: initial check-in
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / internal / model / ToolMessages.java
1 package net.sourceforge.phpdt.externaltools.internal.model;
2
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8  
9 Contributors:
10 **********************************************************************/
11
12 import java.text.MessageFormat;
13 import java.util.MissingResourceException;
14 import java.util.ResourceBundle;
15
16 /**
17  * Utility class which helps managing messages
18  */
19 public final class ToolMessages {
20         private static final String RESOURCE_BUNDLE= "net.sourceforge.phpdt.externaltools.internal.model.messages"; //$NON-NLS-1$
21         private static ResourceBundle bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
22         
23         private ToolMessages(){
24                 // prevent instantiation of class
25         }
26         
27         /**
28          * Returns the formatted message for the given key in
29          * the resource bundle. 
30          *
31          * @param key the message name
32          * @param args the message arguments
33          * @return the formatted message
34          */     
35         public static String format(String key, Object[] args) {
36                 return MessageFormat.format(getString(key), args);
37         }
38         
39         /**
40          * Returns the message with the given key in
41          * the resource bundle. If there isn't any value under
42          * the given key, the key is returned.
43          *
44          * @param key the message name
45          * @return the message
46          */     
47         public static String getString(String key) {
48                 try {
49                         return bundle.getString(key);
50                 } catch (MissingResourceException e) {
51                         return key;
52                 }
53         }
54         
55         /**
56          * Returns the resource bundle for the plug-in
57          */
58         public static ResourceBundle getResourceBundle() {
59                 return bundle;
60         }
61 }