comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 117:ef157bd2fa92

LanguageSupport integrated gnv-artifacts/trunk@178 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 02 Oct 2009 14:24:47 +0000
parents
children 5ebc059064a6
comparison
equal deleted inserted replaced
116:820238357bab 117:ef157bd2fa92
1 /**
2 *
3 */
4 package de.intevation.gnv.artifacts.ressource;
5
6 import java.util.Locale;
7 import java.util.ResourceBundle;
8
9 import org.apache.log4j.Logger;
10
11 /**
12 * @author Tim Englich <tim.englich@intevation.de>
13 *
14 */
15 public class RessourceFactory {
16
17 /**
18 * the logger, used to log exceptions and additonaly information
19 */
20 private static Logger log = Logger.getLogger(RessourceFactory.class);
21
22 /**
23 * The singleton Instance of this Factory.
24 */
25 private static RessourceFactory instance = null;
26
27 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir";
28
29 private static String ressourceName = "artifactMessages";
30
31 private String ressourceDir = null;
32
33 private Locale[] supportedLocales = null;
34 /**
35 * Basic-Constructor of this Class
36 */
37 private RessourceFactory() {
38 super();
39 ressourceDir = System.getProperty(RESSOURCE_BASE_ID);
40 if (ressourceDir == null){
41 ressourceDir = "de/intevation/gnv/artifacts/ressource";
42 }
43 supportedLocales = new Locale[1];
44 supportedLocales[0] = Locale.GERMAN;
45 }
46
47 /**
48 * This Method provides an singleton Instance of this Class.
49 * @return an singleton Instance of this Class
50 */
51 public static RessourceFactory getInstance(){
52 if (instance == null){
53 instance = new RessourceFactory();
54 }
55 return instance;
56 }
57
58 /**
59 * Deliveres the translated Value for an Key to an given Language
60 * @param locale The choosen locale
61 * @param key the key
62 * @param defaultValue the Value that should be returned.
63 * @return the translated Value
64 */
65 public String getRessource(Locale locale, String key, String defaultValue){
66 ResourceBundle rb = ResourceBundle.getBundle(ressourceDir+"/"+ressourceName, locale);
67 try {
68 return rb.getString(key);
69 } catch (Exception e) {
70 log.warn(e.getMessage());
71 return defaultValue;
72 }
73 }
74
75 public Locale[] getSupportedLocales(){
76 return supportedLocales;
77 }
78 }

http://dive4elements.wald.intevation.org