diff 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
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java	Tue Oct 06 10:58:47 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java	Tue Oct 06 11:04:52 2009 +0000
@@ -28,6 +28,7 @@
     private static String RESSOURCE_BASE_ID = "artifact.ressource.dir";
     
     private static String ressourceName = "artifactMessages";
+    private static String DEFAULT_DIR   = "lang";
     
     private String ressourceDir = null;
 
@@ -36,17 +37,14 @@
      */
     private RessourceFactory() {
         super();
-        ressourceDir = System.getProperty(RESSOURCE_BASE_ID);
-        if (ressourceDir == null){
-            ressourceDir = "de/intevation/gnv/artifacts/ressource";
-        }
+        ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR);
     }
 
     /**
      * This Method provides an singleton Instance of this Class.
      * @return an singleton Instance of this Class
      */
-    public static RessourceFactory getInstance(){
+    public static synchronized RessourceFactory getInstance(){
         if (instance == null){
             instance = new RessourceFactory();
         }
@@ -60,12 +58,24 @@
      * @param defaultValue the Value that should be returned.
      * @return the translated Value
      */
-    public String getRessource(PreferredLocale[] preferredLocales, String key, String defaultValue){
-        ResourceBundle rb = ResourceBundle.getBundle(ressourceDir+"/"+ressourceName, preferredLocales[0].getLocale());
+    public String getRessource(
+        PreferredLocale [] preferredLocales, 
+        String             key, 
+        String             defaultValue
+    ) {
+        if (key == null || preferredLocales.length == 0) {
+            return defaultValue;
+        }
+
         try {
+            ResourceBundle rb = ResourceBundle.getBundle(
+                ressourceDir + "/" + ressourceName,
+                preferredLocales[0].getLocale());
+
             return rb.getString(key);
-        } catch (Exception e) {
-            log.warn(e.getMessage());
+        }
+        catch (MissingResourceException mre) {
+            log.warn(mre.getLocalizedMessage());
             return defaultValue;
         }
     }

http://dive4elements.wald.intevation.org