Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 121:6b9a07f758cf
Move resources to a place where maven puts them into final package.
Cleaned up changelog.
gnv-artifacts/trunk@191 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 06 Oct 2009 11:04:52 +0000 |
parents | 5ebc059064a6 |
children | 8cc96c9cc962 |
comparison
equal
deleted
inserted
replaced
120:5134266f00e7 | 121:6b9a07f758cf |
---|---|
26 private static RessourceFactory instance = null; | 26 private static RessourceFactory instance = null; |
27 | 27 |
28 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir"; | 28 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir"; |
29 | 29 |
30 private static String ressourceName = "artifactMessages"; | 30 private static String ressourceName = "artifactMessages"; |
31 private static String DEFAULT_DIR = "lang"; | |
31 | 32 |
32 private String ressourceDir = null; | 33 private String ressourceDir = null; |
33 | 34 |
34 /** | 35 /** |
35 * Basic-Constructor of this Class | 36 * Basic-Constructor of this Class |
36 */ | 37 */ |
37 private RessourceFactory() { | 38 private RessourceFactory() { |
38 super(); | 39 super(); |
39 ressourceDir = System.getProperty(RESSOURCE_BASE_ID); | 40 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR); |
40 if (ressourceDir == null){ | |
41 ressourceDir = "de/intevation/gnv/artifacts/ressource"; | |
42 } | |
43 } | 41 } |
44 | 42 |
45 /** | 43 /** |
46 * This Method provides an singleton Instance of this Class. | 44 * This Method provides an singleton Instance of this Class. |
47 * @return an singleton Instance of this Class | 45 * @return an singleton Instance of this Class |
48 */ | 46 */ |
49 public static RessourceFactory getInstance(){ | 47 public static synchronized RessourceFactory getInstance(){ |
50 if (instance == null){ | 48 if (instance == null){ |
51 instance = new RessourceFactory(); | 49 instance = new RessourceFactory(); |
52 } | 50 } |
53 return instance; | 51 return instance; |
54 } | 52 } |
58 * @param locale The choosen locale | 56 * @param locale The choosen locale |
59 * @param key the key | 57 * @param key the key |
60 * @param defaultValue the Value that should be returned. | 58 * @param defaultValue the Value that should be returned. |
61 * @return the translated Value | 59 * @return the translated Value |
62 */ | 60 */ |
63 public String getRessource(PreferredLocale[] preferredLocales, String key, String defaultValue){ | 61 public String getRessource( |
64 ResourceBundle rb = ResourceBundle.getBundle(ressourceDir+"/"+ressourceName, preferredLocales[0].getLocale()); | 62 PreferredLocale [] preferredLocales, |
63 String key, | |
64 String defaultValue | |
65 ) { | |
66 if (key == null || preferredLocales.length == 0) { | |
67 return defaultValue; | |
68 } | |
69 | |
65 try { | 70 try { |
71 ResourceBundle rb = ResourceBundle.getBundle( | |
72 ressourceDir + "/" + ressourceName, | |
73 preferredLocales[0].getLocale()); | |
74 | |
66 return rb.getString(key); | 75 return rb.getString(key); |
67 } catch (Exception e) { | 76 } |
68 log.warn(e.getMessage()); | 77 catch (MissingResourceException mre) { |
78 log.warn(mre.getLocalizedMessage()); | |
69 return defaultValue; | 79 return defaultValue; |
70 } | 80 } |
71 } | 81 } |
72 } | 82 } |