view 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
line wrap: on
line source

package de.mpiwg.gazetteer.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertiesUtils {
	
	private static Logger logger = Logger.getLogger(PropertiesUtils.class);
	private static PropertiesUtils instance;
	
	
	private static String PROP_FILENAME = "config.properties";
	private Properties prop;
	
	private PropertiesUtils() throws IOException{
		loadProperties();
	}
	
	
	public void loadProperties() throws IOException {
		
		logger.info("##### Loading Propertis from " + PROP_FILENAME + " #####");
		
		prop = new Properties();
		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(PROP_FILENAME);
 
		if (inputStream != null) {
			prop.load(inputStream);
		} else {
			prop = null;
			throw new FileNotFoundException("property file '" + PROP_FILENAME + "' not found in the classpath");
			
		}
	}

	public static String getPropValue(String key) throws IOException{
		if(instance == null){
			instance = new PropertiesUtils();
		}
		if(instance.prop == null){
			instance.loadProperties();
		}
		return instance.prop.getProperty(key);
	}
	
}