comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 118:5ebc059064a6

Adding Languagetransfer to the ArtifactDatabase to the GNV-Client gnv-artifacts/trunk@181 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 05 Oct 2009 07:52:13 +0000
parents ef157bd2fa92
children 6b9a07f758cf
comparison
equal deleted inserted replaced
117:ef157bd2fa92 118:5ebc059064a6
1 /** 1 /**
2 * 2 *
3 */ 3 */
4 package de.intevation.gnv.artifacts.ressource; 4 package de.intevation.gnv.artifacts.ressource;
5 5
6 import java.util.Locale;
7 import java.util.ResourceBundle; 6 import java.util.ResourceBundle;
8 7
9 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
9
10 import de.intevation.artifacts.PreferredLocale;
10 11
11 /** 12 /**
12 * @author Tim Englich <tim.englich@intevation.de> 13 * @author Tim Englich <tim.englich@intevation.de>
13 * 14 *
14 */ 15 */
27 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir"; 28 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir";
28 29
29 private static String ressourceName = "artifactMessages"; 30 private static String ressourceName = "artifactMessages";
30 31
31 private String ressourceDir = null; 32 private String ressourceDir = null;
32 33
33 private Locale[] supportedLocales = null;
34 /** 34 /**
35 * Basic-Constructor of this Class 35 * Basic-Constructor of this Class
36 */ 36 */
37 private RessourceFactory() { 37 private RessourceFactory() {
38 super(); 38 super();
39 ressourceDir = System.getProperty(RESSOURCE_BASE_ID); 39 ressourceDir = System.getProperty(RESSOURCE_BASE_ID);
40 if (ressourceDir == null){ 40 if (ressourceDir == null){
41 ressourceDir = "de/intevation/gnv/artifacts/ressource"; 41 ressourceDir = "de/intevation/gnv/artifacts/ressource";
42 } 42 }
43 supportedLocales = new Locale[1];
44 supportedLocales[0] = Locale.GERMAN;
45 } 43 }
46 44
47 /** 45 /**
48 * This Method provides an singleton Instance of this Class. 46 * This Method provides an singleton Instance of this Class.
49 * @return an singleton Instance of this Class 47 * @return an singleton Instance of this Class
60 * @param locale The choosen locale 58 * @param locale The choosen locale
61 * @param key the key 59 * @param key the key
62 * @param defaultValue the Value that should be returned. 60 * @param defaultValue the Value that should be returned.
63 * @return the translated Value 61 * @return the translated Value
64 */ 62 */
65 public String getRessource(Locale locale, String key, String defaultValue){ 63 public String getRessource(PreferredLocale[] preferredLocales, String key, String defaultValue){
66 ResourceBundle rb = ResourceBundle.getBundle(ressourceDir+"/"+ressourceName, locale); 64 ResourceBundle rb = ResourceBundle.getBundle(ressourceDir+"/"+ressourceName, preferredLocales[0].getLocale());
67 try { 65 try {
68 return rb.getString(key); 66 return rb.getString(key);
69 } catch (Exception e) { 67 } catch (Exception e) {
70 log.warn(e.getMessage()); 68 log.warn(e.getMessage());
71 return defaultValue; 69 return defaultValue;
72 } 70 }
73 } 71 }
74
75 public Locale[] getSupportedLocales(){
76 return supportedLocales;
77 }
78 } 72 }

http://dive4elements.wald.intevation.org