View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: Messages.java,v 38ef83fddf0c 2009/02/17 12:21:58 maxberger $ */
18  
19  package net.sourceforge.jeuclid.app.mathviewer;
20  
21  import java.util.MissingResourceException;
22  import java.util.ResourceBundle;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  /**
28   * Class to load i18n messages.
29   * 
30   * @version $Revision: 38ef83fddf0c $
31   */
32  public final class Messages {
33      /**
34       * Logger for this class
35       */
36      private static final Log LOGGER = LogFactory.getLog(Messages.class);
37  
38      private static final String BUNDLE_NAME = "intl.mathviewer"; //$NON-NLS-1$
39  
40      private static ResourceBundle resourceBundle;
41  
42      private Messages() {
43      }
44  
45      /**
46       * retrieve a translation string.
47       * 
48       * @param key
49       *            key to look for
50       * @return the expanded string
51       */
52      public static String getString(final String key) {
53          String retVal = '!' + key + '!';
54          try {
55              if (Messages.resourceBundle != null) {
56                  retVal = Messages.resourceBundle.getString(key);
57              }
58          } catch (final MissingResourceException e) {
59              Messages.LOGGER.warn(e.getMessage());
60          }
61          return retVal;
62      }
63  
64      static {
65          try {
66              Messages.resourceBundle = ResourceBundle
67                      .getBundle(Messages.BUNDLE_NAME);
68          } catch (final MissingResourceException e) {
69              Messages.LOGGER.warn(e.getMessage());
70          }
71      }
72  }