package org.expressolivre.cte.common; import java.net.URL; import java.text.MessageFormat; import java.util.Properties; /** * @author L.F.Estivalet (Serpro) * * Created on Jan 4, 2011 at 3:53:14 PM * */ public final class Config { private static final Config INSTANCE = new Config(); private Properties config; private Properties mensagens; private Properties valores; private Properties emailPreferences; private Config() { try { this.config = this .load("org/expressolivre/cte/common/config.properties"); this.mensagens = this .load("org/expressolivre/cte/common/mensagens.properties"); this.valores = this .load("org/expressolivre/cte/common/valores.properties"); this.emailPreferences = this.load("org/expressolivre/cte/common/" + getConfig("config.email")); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } public static Config getInstance() { return INSTANCE; } public String getConfig(String key) { return this.config.getProperty(key); } public String getMensagem(String key) { return this.mensagens.getProperty(key); } public String getMensagem(String key, Object... args) { return MessageFormat.format(getMensagem(key), args); } public String getCampo(String key, Object... args) { return MessageFormat.format(getCampo(key), args); } public String getValor(String key) { return this.valores.getProperty(key); } public String getEmailPreference(String key) { return this.emailPreferences.getProperty(key); } private Properties load(String propsName) throws Exception { Properties props = new Properties(); URL url = ClassLoader.getSystemResource(propsName); props.load(url.openStream()); return props; } }