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