comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 171:7fb9441dd8af

Format Code to max 80 Chars per Row and Cleanup gnv-artifacts/trunk@208 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 09 Oct 2009 07:54:48 +0000
parents 8cc96c9cc962
children 7b4e2f80cba2
comparison
equal deleted inserted replaced
170:7be22e76c270 171:7fb9441dd8af
10 10
11 import de.intevation.artifacts.PreferredLocale; 11 import de.intevation.artifacts.PreferredLocale;
12 12
13 /** 13 /**
14 * @author Tim Englich <tim.englich@intevation.de> 14 * @author Tim Englich <tim.englich@intevation.de>
15 * 15 *
16 */ 16 */
17 public class RessourceFactory { 17 public class RessourceFactory {
18 18
19 /** 19 /**
20 * the logger, used to log exceptions and additonaly information 20 * the logger, used to log exceptions and additonaly information
21 */ 21 */
22 private static Logger log = Logger.getLogger(RessourceFactory.class); 22 private static Logger log = Logger.getLogger(RessourceFactory.class);
23 23
24 /** 24 /**
25 * The singleton Instance of this Factory. 25 * The singleton Instance of this Factory.
26 */ 26 */
27 private static RessourceFactory instance = null; 27 private static RessourceFactory instance = null;
28 28
29 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir"; 29 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir";
30 30
31 private static String ressourceName = "artifactMessages"; 31 private static String ressourceName = "artifactMessages";
32 private static String DEFAULT_DIR = "lang"; 32 private static String DEFAULT_DIR = "lang";
33 33
34 private String ressourceDir = null; 34 private String ressourceDir = null;
35 35
36 /** 36 /**
37 * Basic-Constructor of this Class 37 * Basic-Constructor of this Class
38 */ 38 */
41 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR); 41 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR);
42 } 42 }
43 43
44 /** 44 /**
45 * This Method provides an singleton Instance of this Class. 45 * This Method provides an singleton Instance of this Class.
46 *
46 * @return an singleton Instance of this Class 47 * @return an singleton Instance of this Class
47 */ 48 */
48 public static synchronized RessourceFactory getInstance(){ 49 public static synchronized RessourceFactory getInstance() {
49 if (instance == null){ 50 if (instance == null) {
50 instance = new RessourceFactory(); 51 instance = new RessourceFactory();
51 } 52 }
52 return instance; 53 return instance;
53 } 54 }
54 55
55 /** 56 /**
56 * Deliveres the translated Value for an Key to an given Language 57 * Deliveres the translated Value for an Key to an given Language
57 * @param locale The choosen locale 58 *
58 * @param key the key 59 * @param locale
59 * @param defaultValue the Value that should be returned. 60 * The choosen locale
61 * @param key
62 * the key
63 * @param defaultValue
64 * the Value that should be returned.
60 * @return the translated Value 65 * @return the translated Value
61 */ 66 */
62 public String getRessource( 67 public String getRessource(PreferredLocale[] preferredLocales, String key,
63 PreferredLocale [] preferredLocales, 68 String defaultValue) {
64 String key,
65 String defaultValue
66 ) {
67 if (key == null || preferredLocales.length == 0) { 69 if (key == null || preferredLocales.length == 0) {
68 return defaultValue; 70 return defaultValue;
69 } 71 }
70 72
71 try { 73 try {
72 ResourceBundle rb = ResourceBundle.getBundle( 74 ResourceBundle rb = ResourceBundle.getBundle(ressourceDir + "/"
73 ressourceDir + "/" + ressourceName, 75 + ressourceName,
74 preferredLocales[0].getLocale()); 76 preferredLocales[0].getLocale());
75 77
76 return rb.getString(key); 78 return rb.getString(key);
77 } 79 } catch (MissingResourceException mre) {
78 catch (MissingResourceException mre) {
79 log.warn(mre.getLocalizedMessage()); 80 log.warn(mre.getLocalizedMessage());
80 return defaultValue; 81 return defaultValue;
81 } 82 }
82 } 83 }
83 } 84 }

http://dive4elements.wald.intevation.org