[3782] | 1 | package org.expressolivre.cte.common; |
---|
[3663] | 2 | |
---|
| 3 | import java.net.URL; |
---|
| 4 | import java.text.MessageFormat; |
---|
| 5 | import java.util.Properties; |
---|
| 6 | |
---|
| 7 | /** |
---|
| 8 | * @author L.F.Estivalet (Serpro) |
---|
| 9 | * |
---|
| 10 | * Created on Jan 4, 2011 at 3:53:14 PM |
---|
| 11 | * |
---|
| 12 | */ |
---|
| 13 | public final class Config { |
---|
| 14 | private static final Config INSTANCE = new Config(); |
---|
| 15 | |
---|
| 16 | private Properties config; |
---|
| 17 | private Properties mensagens; |
---|
| 18 | private Properties valores; |
---|
[3745] | 19 | private Properties emailPreferences; |
---|
[3663] | 20 | |
---|
| 21 | private Config() { |
---|
| 22 | try { |
---|
| 23 | this.config = this |
---|
[3782] | 24 | .load("org/expressolivre/cte/common/config.properties"); |
---|
[3663] | 25 | this.mensagens = this |
---|
[3782] | 26 | .load("org/expressolivre/cte/common/mensagens.properties"); |
---|
[3663] | 27 | this.valores = this |
---|
[3782] | 28 | .load("org/expressolivre/cte/common/valores.properties"); |
---|
[3799] | 29 | this.emailPreferences = this.load("org/expressolivre/cte/common/" |
---|
| 30 | + getConfig("config.email")); |
---|
[3663] | 31 | } catch (Exception e) { |
---|
| 32 | e.printStackTrace(); |
---|
| 33 | System.exit(0); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | public static Config getInstance() { |
---|
| 38 | return INSTANCE; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | public String getConfig(String key) { |
---|
| 42 | return this.config.getProperty(key); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | public String getMensagem(String key) { |
---|
| 46 | return this.mensagens.getProperty(key); |
---|
| 47 | } |
---|
| 48 | |
---|
[3766] | 49 | public String getMensagem(String key, Object... args) { |
---|
| 50 | return MessageFormat.format(getMensagem(key), args); |
---|
[3663] | 51 | } |
---|
| 52 | |
---|
| 53 | public String getCampo(String key, Object... args) { |
---|
| 54 | return MessageFormat.format(getCampo(key), args); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | public String getValor(String key) { |
---|
| 58 | return this.valores.getProperty(key); |
---|
| 59 | } |
---|
| 60 | |
---|
[3745] | 61 | public String getEmailPreference(String key) { |
---|
| 62 | return this.emailPreferences.getProperty(key); |
---|
| 63 | } |
---|
| 64 | |
---|
[3663] | 65 | private Properties load(String propsName) throws Exception { |
---|
| 66 | Properties props = new Properties(); |
---|
| 67 | URL url = ClassLoader.getSystemResource(propsName); |
---|
| 68 | props.load(url.openStream()); |
---|
| 69 | return props; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | } |
---|