source: devel/testlink/automation2.0/src/test/java/org/expressolivre/cte/common/Config.java @ 4057

Revision 4057, 1.6 KB checked in by felipe.kuhn, 13 years ago (diff)

Ticket #1771 - Removendo o caminho hardcoded dos resources

Line 
1package org.expressolivre.cte.common;
2
3import java.net.URL;
4import java.text.MessageFormat;
5import 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 */
13public 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
21        private Config() {
22                try {
23                        this.config = this.load("config.properties");
24                        this.mensagens = this.load("mensagens.properties");
25                        this.valores = this.load("valores.properties");
26                        this.emailPreferences = this.load(getConfig("config.email"));
27                } catch (Exception e) {
28                        e.printStackTrace();
29                        System.exit(0);
30                }
31        }
32
33        public static Config getInstance() {
34                return INSTANCE;
35        }
36
37        public String getConfig(String key) {
38                return this.config.getProperty(key);
39        }
40
41        public String getMensagem(String key) {
42                return this.mensagens.getProperty(key);
43        }
44
45        public String getMensagem(String key, Object... args) {
46                return MessageFormat.format(getMensagem(key), args);
47        }
48
49        public String getCampo(String key, Object... args) {
50                return MessageFormat.format(getCampo(key), args);
51        }
52
53        public String getValor(String key) {
54                return this.valores.getProperty(key);
55        }
56
57        public String getEmailPreference(String key) {
58                return this.emailPreferences.getProperty(key);
59        }
60
61        private Properties load(String propsName) throws Exception {
62                Properties props = new Properties();
63                URL url = ClassLoader.getSystemResource(propsName);
64                props.load(url.openStream());
65                return props;
66        }
67
68}
Note: See TracBrowser for help on using the repository browser.