1 package es.inteco.eni.commons;
2
3 import java.io.FileInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.util.ArrayList;
7 import java.util.List;
8 import java.util.Properties;
9
10 import org.apache.log4j.Logger;
11
12
13
14
15
16 public final class ApplicationPropertiesManager {
17
18
19
20 private static Logger log = Logger.getLogger(ApplicationPropertiesManager.class);
21
22
23
24
25 private static final String PROPERTIESFILENAME = "/eni.properties";
26
27
28
29 private static Properties properties;
30
31
32 static {
33 properties = new Properties();
34 try {
35 InputStream inputStream = null;
36 inputStream = new FileInputStream("conf"+PROPERTIESFILENAME);
37 if(inputStream==null){
38 inputStream = ApplicationPropertiesManager.class.getResourceAsStream(PROPERTIESFILENAME);
39 }
40 properties.load(inputStream);
41 } catch (IOException e) {
42 log.debug("No se ha podido cargar el fichero de propiedades");
43 }
44 }
45
46
47
48
49 private ApplicationPropertiesManager(){
50
51 }
52
53
54
55
56
57
58 public static String getProperty(String key) {
59 if(key==null){
60 return null;
61 }
62 return properties.getProperty(key);
63 }
64
65
66
67
68
69
70 public static List<String> getListProperty(String key){
71 List<String> result = new ArrayList<String>();
72 String propertyStr = getProperty(key);
73 if(propertyStr!=null && !"".equals(propertyStr)){
74 String[] propertyAr = propertyStr.split(",");
75 for(int i=0; propertyAr!=null && i<propertyAr.length; i++){
76 result.add(propertyAr[i].trim());
77 }
78 }
79 return result;
80 }
81 }