comparison src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java @ 0:3e62083dbcbf

First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Thu, 23 Apr 2015 15:46:01 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3e62083dbcbf
1 package de.mpiwg.gazetteer.utils;
2
3 import java.io.FileNotFoundException;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.util.Properties;
7
8 import org.apache.log4j.Logger;
9
10 public class PropertiesUtils {
11
12 private static Logger logger = Logger.getLogger(PropertiesUtils.class);
13 private static PropertiesUtils instance;
14
15
16 private static String PROP_FILENAME = "config.properties";
17 private Properties prop;
18
19 private PropertiesUtils() throws IOException{
20 loadProperties();
21 }
22
23
24 public void loadProperties() throws IOException {
25
26 logger.info("##### Loading Propertis from " + PROP_FILENAME + " #####");
27
28 prop = new Properties();
29 InputStream inputStream = getClass().getClassLoader().getResourceAsStream(PROP_FILENAME);
30
31 if (inputStream != null) {
32 prop.load(inputStream);
33 } else {
34 prop = null;
35 throw new FileNotFoundException("property file '" + PROP_FILENAME + "' not found in the classpath");
36
37 }
38 }
39
40 public static String getPropValue(String key) throws IOException{
41 if(instance == null){
42 instance = new PropertiesUtils();
43 }
44 if(instance.prop == null){
45 instance.loadProperties();
46 }
47 return instance.prop.getProperty(key);
48 }
49
50 }