01: /*
02: * Created on 26/11/2004
03: *
04: * Swing Components - visit http://sf.net/projects/gfd
05: *
06: * Copyright (C) 2004 Igor Regis da Silva Simőes
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: package br.com.gfpshare.localization;
25:
26: import java.util.Locale;
27: import java.util.MissingResourceException;
28: import java.util.ResourceBundle;
29:
30: import br.com.gfpshare.plugin.core.DynamicClassLoader;
31:
32: /**
33: * @author Igor Regis da Silva Simoes
34: */
35: public abstract class Messages {
36: private ResourceBundle resourceBundle = ResourceBundle.getBundle(
37: getBundleName(), Locale.getDefault(), DynamicClassLoader
38: .getClassLoader());
39:
40: protected abstract String getBundleName();
41:
42: private Locale local = Locale.getDefault();
43:
44: /**
45: * Método que retorna uma string dada uma chave, será procurada a String conforme
46: * a linguagem usada pelo usuário
47: * @param key Chave que indica um texto a ser capturado
48: * @return String
49: */
50: public String getString(String key) {
51:
52: try {
53: return getResourceBundle().getString(key);
54: } catch (MissingResourceException e) {
55: return '!' + key + '!';
56: }
57: }
58:
59: private ResourceBundle getResourceBundle() {
60: if (!local.equals(Locale.getDefault())) {
61: local = Locale.getDefault();
62: resourceBundle = ResourceBundle.getBundle(getBundleName(),
63: local, DynamicClassLoader.getClassLoader());
64: }
65: return resourceBundle;
66: }
67:
68: public ResourceBundle getProperties() {
69: return getResourceBundle();
70: }
71: }
|