implemented 1416503, automatic closing of braces
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / preferences / Messages.java
1 /*******************************************************************************
2  * Copyright (c) 2003 Berthold Daum.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Berthold Daum
10  *******************************************************************************/
11
12 package net.sourceforge.phpeclipse.wiki.preferences;
13
14 import java.text.MessageFormat;
15 import java.util.MissingResourceException;
16 import java.util.ResourceBundle;
17
18
19 public class Messages {
20
21         private final static String RESOURCE_BUNDLE= "net.sourceforge.phpeclipse.wiki.preferences.Messages";//$NON-NLS-1$
22         
23         private static ResourceBundle fgResourceBundle = null;
24         
25         private static boolean notRead = true;
26
27         public Messages() {
28         }
29         public static ResourceBundle getResourceBundle() {
30                 if (notRead) {
31                         notRead = false;
32                         try {
33                                 fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
34                         }
35                         catch (Exception e) {
36                         }
37                 }
38                 
39                 return fgResourceBundle;
40         }
41         public static String getString(String key) {
42                 try {
43                         return getResourceBundle().getString(key);
44                 } catch (Exception e) {
45                         return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
46                 }
47         }
48         
49         /**
50          * Lookup the message with the given ID in this catalog and bind its
51          * substitution locations with the given string.
52          */
53         public static String bind(String id, String binding) {
54                 return bind(id, new String[] { binding });
55         }
56         
57         /**
58          * Lookup the message with the given ID in this catalog and bind its
59          * substitution locations with the given strings.
60          */
61         public static String bind(String id, String binding1, String binding2) {
62                 return bind(id, new String[] { binding1, binding2 });
63         }
64         
65         /**
66          * Gets a string from the resource bundle. We don't want to crash because of a missing String.
67          * Returns the key if not found.
68          */
69         public static String bind(String key) {
70                 try {
71                         return getString(key);
72                 } catch (MissingResourceException e) {
73                         return key;
74                 } catch (NullPointerException e) {
75                         return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
76                 }
77         }
78         
79         /**
80          * Gets a string from the resource bundle and binds it with the given arguments. If the key is 
81          * not found, return the key.
82          */
83         public static String bind(String key, Object[] args) {
84                 try {
85                         return MessageFormat.format(bind(key), args);
86                 } catch (MissingResourceException e) {
87                         return key;
88                 } catch (NullPointerException e) {
89                         return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
90                 }
91         }
92 }
93