From efac472d42715e583416442554d3c55873f8e85d Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:22:04 +0000 Subject: Move Messages to utils package git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@282 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../main/java/at/asit/pdfover/gui/Messages.java | 119 --------------------- 1 file changed, 119 deletions(-) delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java deleted file mode 100644 index b17e168a..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui; - -// Imports -import java.util.HashMap; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Localizes string messages for PDFOver GUI - */ -public class Messages { - - /** - * SFL4J Logger instance - **/ - static final Logger log = LoggerFactory.getLogger(Messages.class); - - private static final String BUNDLE_NAME = "at.asit.pdfover.gui.messages"; //$NON-NLS-1$ - - private static HashMap bundles = new HashMap(); - - //private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - // .getBundle(BUNDLE_NAME); - - private static Locale currentLocale = getDefaultLocale(); - - private Messages() { - } - - /** - * Get the closest match to the system default Locale out of the supported locales - * @return the default locale - */ - public static Locale getDefaultLocale() { - Locale ld = Locale.getDefault(); - for (Locale l : Constants.SUPPORTED_LOCALES) { - if (l.equals(ld) || l.getLanguage().equals(ld.getLanguage())) - return l; - } - return Constants.SUPPORTED_LOCALES[0]; - } - - /** - * Sets the currently used locals - * @param locale - */ - public static void setLocale(Locale locale) { - currentLocale = locale; - } - - private static ResourceBundle getBundle(Locale locale) { - if(!bundles.containsKey(locale)) { - log.debug("Loading resource bundle for " + locale); //$NON-NLS-1$ - ResourceBundle tmp = null; - try { - tmp = ResourceBundle.getBundle(BUNDLE_NAME, locale); - log.debug("Received bundle for " + tmp.getLocale()); //$NON-NLS-1$ - } catch(Exception e) { - log.error("NO RESOURCE BUNDLE FOR " + locale.toString(), e); //$NON-NLS-1$ - tmp = ResourceBundle.getBundle(BUNDLE_NAME); - } - if(tmp == null) { - log.error("NO RESOURCE BUNDLE FOR " + locale.toString()); //$NON-NLS-1$ - tmp = ResourceBundle.getBundle(BUNDLE_NAME); - } - bundles.put(locale, tmp); - return tmp; - } - return bundles.get(locale); - } - - /** - * Gets the localized message - * @param key - * @return the localized message - */ - public static String getString(String key) { - try { - return getBundle(currentLocale).getString(key); - //return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } - - /** - * Gets the localized message - * @param key the key - * @param locale the locale to use - * @return the localized message - */ - public static String getString(String key, Locale locale) { - try { - return getBundle(locale).getString(key); - //return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } -} -- cgit v1.2.3