Mercurial > dive4elements > gnv-client
view 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 |
line wrap: on
line source
/** * */ package de.intevation.gnv.artifacts.ressource; import java.util.Locale; import java.util.ResourceBundle; import org.apache.log4j.Logger; /** * @author Tim Englich <tim.englich@intevation.de> * */ public class RessourceFactory { /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(RessourceFactory.class); /** * The singleton Instance of this Factory. */ private static RessourceFactory instance = null; private static String RESSOURCE_BASE_ID = "artifact.ressource.dir"; private static String ressourceName = "artifactMessages"; private String ressourceDir = null; private Locale[] supportedLocales = null; /** * Basic-Constructor of this Class */ private RessourceFactory() { super(); ressourceDir = System.getProperty(RESSOURCE_BASE_ID); if (ressourceDir == null){ ressourceDir = "de/intevation/gnv/artifacts/ressource"; } supportedLocales = new Locale[1]; supportedLocales[0] = Locale.GERMAN; } /** * This Method provides an singleton Instance of this Class. * @return an singleton Instance of this Class */ public static RessourceFactory getInstance(){ if (instance == null){ instance = new RessourceFactory(); } return instance; } /** * Deliveres the translated Value for an Key to an given Language * @param locale The choosen locale * @param key the key * @param defaultValue the Value that should be returned. * @return the translated Value */ public String getRessource(Locale locale, String key, String defaultValue){ ResourceBundle rb = ResourceBundle.getBundle(ressourceDir+"/"+ressourceName, locale); try { return rb.getString(key); } catch (Exception e) { log.warn(e.getMessage()); return defaultValue; } } public Locale[] getSupportedLocales(){ return supportedLocales; } }