1 | |
package booking.model.util; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.io.FileInputStream; |
5 | |
import java.io.InputStream; |
6 | |
import java.util.Properties; |
7 | |
|
8 | |
import org.apache.log4j.Logger; |
9 | |
|
10 | 0 | public class LoadPropertiesUtil { |
11 | |
|
12 | |
|
13 | 0 | private static Logger log = Logger.getLogger(LoadPropertiesUtil.class); |
14 | |
|
15 | |
public static Properties loadProperties(String filePath) { |
16 | |
|
17 | 0 | Properties properties = new Properties(); |
18 | |
try { |
19 | |
|
20 | 0 | if (log.isDebugEnabled()) { |
21 | 0 | log.debug("loadProperties() - Inicio"); |
22 | |
} |
23 | |
|
24 | |
|
25 | 0 | properties.load(new FileInputStream(filePath)); |
26 | |
|
27 | 0 | } catch (Exception e) { |
28 | |
|
29 | 0 | ClassLoader cl = LoadPropertiesUtil.class. |
30 | |
getClassLoader(); |
31 | 0 | InputStream inputFile = cl.getResourceAsStream(filePath); |
32 | 0 | properties.load(inputFile); |
33 | |
|
34 | |
} finally { |
35 | |
|
36 | 0 | if (properties.isEmpty()) { |
37 | 0 | log.error("Error cargando properties: " |
38 | |
+ new File(filePath).getAbsolutePath()); |
39 | |
} |
40 | |
|
41 | 0 | if (log.isDebugEnabled()) { |
42 | 0 | log.debug("loadProperties() - Fin"); |
43 | |
} |
44 | 0 | return properties; |
45 | |
} |
46 | |
|
47 | |
} |
48 | |
} |