001    /*
002     * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    /* $Id: Messages.java,v 38ef83fddf0c 2009/02/17 12:21:58 maxberger $ */
018    
019    package net.sourceforge.jeuclid.app.mathviewer;
020    
021    import java.util.MissingResourceException;
022    import java.util.ResourceBundle;
023    
024    import org.apache.commons.logging.Log;
025    import org.apache.commons.logging.LogFactory;
026    
027    /**
028     * Class to load i18n messages.
029     * 
030     * @version $Revision: 38ef83fddf0c $
031     */
032    public final class Messages {
033        /**
034         * Logger for this class
035         */
036        private static final Log LOGGER = LogFactory.getLog(Messages.class);
037    
038        private static final String BUNDLE_NAME = "intl.mathviewer"; //$NON-NLS-1$
039    
040        private static ResourceBundle resourceBundle;
041    
042        private Messages() {
043        }
044    
045        /**
046         * retrieve a translation string.
047         * 
048         * @param key
049         *            key to look for
050         * @return the expanded string
051         */
052        public static String getString(final String key) {
053            String retVal = '!' + key + '!';
054            try {
055                if (Messages.resourceBundle != null) {
056                    retVal = Messages.resourceBundle.getString(key);
057                }
058            } catch (final MissingResourceException e) {
059                Messages.LOGGER.warn(e.getMessage());
060            }
061            return retVal;
062        }
063    
064        static {
065            try {
066                Messages.resourceBundle = ResourceBundle
067                        .getBundle(Messages.BUNDLE_NAME);
068            } catch (final MissingResourceException e) {
069                Messages.LOGGER.warn(e.getMessage());
070            }
071        }
072    }