View Javadoc

1   /*
2    * Created on Mar 8, 2005. Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the "License"); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.editor.lang;
13  
14  import java.util.MissingResourceException;
15  import java.util.ResourceBundle;
16  import sk.uniba.euromath.tools.LangTools;
17  import sk.uniba.euromath.tools.StringTools;
18  
19  /***
20   * I18n strings for sk.uniba.euromath.editor package.
21   * 
22   * @author Martin Vysny
23   */
24  public class Messages {
25      /***
26       * Name of bundle with messages.
27       */
28      private static final String BUNDLE_NAME = "sk.uniba.euromath.editor.lang.messages";//$NON-NLS-1$
29  
30      /***
31       * Resource bundle.
32       */
33      private static final ResourceBundle RESOURCE_BUNDLE = LangTools.newBundle(
34              BUNDLE_NAME, Messages.class);
35  
36      /***
37       * Hides contructor.
38       */
39      private Messages() {
40          // hide constructor
41      }
42  
43      /***
44       * Gets message for given key.
45       * 
46       * @param key
47       *            key in the properties file.
48       * @return message associated with the key.
49       */
50      public static String getString(String key) {
51          try {
52              return RESOURCE_BUNDLE.getString(key);
53          } catch (MissingResourceException e) {
54              return '!' + key + '!';
55          }
56      }
57  
58      /***
59       * Gets message for given key.
60       * 
61       * @param key
62       *            key in the properties file.
63       * @param params
64       *            message variable part replacements
65       * @return message associated with the key.
66       */
67      public static String getString(String key, Object... params) {
68          try {
69              String msg = RESOURCE_BUNDLE.getString(key);
70              return StringTools.format(msg, params);
71          } catch (MissingResourceException e) {
72              return '!' + key + '!';
73          }
74      }
75  }