1 | package org.expressolivre.cte.common; |
---|
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; |
---|
19 | private Properties emailPreferences; |
---|
20 | private Properties emailAdminPreferences; |
---|
21 | |
---|
22 | private Config() { |
---|
23 | try { |
---|
24 | this.config = this.load("config.properties"); |
---|
25 | this.mensagens = this.load("mensagens.properties"); |
---|
26 | this.valores = this.load("valores.properties"); |
---|
27 | this.emailPreferences = this.load(getConfig("config.email")); |
---|
28 | this.emailAdminPreferences = this |
---|
29 | .load(getConfig("config.email.admin")); |
---|
30 | } catch (Exception e) { |
---|
31 | e.printStackTrace(); |
---|
32 | System.exit(0); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | public static Config getInstance() { |
---|
37 | return INSTANCE; |
---|
38 | } |
---|
39 | |
---|
40 | public String getConfig(String key) { |
---|
41 | return this.config.getProperty(key); |
---|
42 | } |
---|
43 | |
---|
44 | public String getMensagem(String key) { |
---|
45 | return this.mensagens.getProperty(key); |
---|
46 | } |
---|
47 | |
---|
48 | public String getMensagem(String key, Object... args) { |
---|
49 | return MessageFormat.format(getMensagem(key), args); |
---|
50 | } |
---|
51 | |
---|
52 | public String getCampo(String key, Object... args) { |
---|
53 | return MessageFormat.format(getCampo(key), args); |
---|
54 | } |
---|
55 | |
---|
56 | public String getValor(String key) { |
---|
57 | return this.valores.getProperty(key); |
---|
58 | } |
---|
59 | |
---|
60 | public String getEmailPreference(String key) { |
---|
61 | return this.emailPreferences.getProperty(key); |
---|
62 | } |
---|
63 | |
---|
64 | public String getEmailAdminPreference(String key) { |
---|
65 | return this.emailAdminPreferences.getProperty(key); |
---|
66 | } |
---|
67 | |
---|
68 | private Properties load(String propsName) throws Exception { |
---|
69 | Properties props = new Properties(); |
---|
70 | URL url = ClassLoader.getSystemResource(propsName); |
---|
71 | props.load(url.openStream()); |
---|
72 | return props; |
---|
73 | } |
---|
74 | |
---|
75 | } |
---|