package de.uni_potsdam.hpi.bpt.bp2014.settings;

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

/**
 * Class for accessing Properties from resources/config.properties.
 */
public final class PropertyLoader {

	private PropertyLoader() { }

	/**
	 * Name of properties file.
	 */
	public static final String PROPERTIES_FILE = "config.properties";
	/**
	 * Folder for properties file.
	 */
	public static final String PROPERTIES_FOLDER = "resources";
	private static Properties props = new Properties();

	//TODO should an exception be thrown if the property file could not be read?
	static {
		String path = PROPERTIES_FOLDER + File.separator + PROPERTIES_FILE;

		InputStream is = null;
		try {
			ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
			is = classLoader.getResourceAsStream(PROPERTIES_FILE);
			props.load(is);
		} catch (IOException e) {
			System.err.println("Could not read configuration file " + path);
			e.printStackTrace();
		} finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
/*	
//    static Logger log = Logger.getLogger(PropertyReader.class);

	
	public PropertyLoader() {
		loadProperties();
	}
	
	private Properties loadProperties() {
		
		String path = PROPERTIES_FOLDER + File.separator + PROPERTIES_FILE;
		
		InputStream is = null;
		try {
			ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
			is = classLoader.getResourceAsStream(PROPERTIES_FILE);
			props.load(is);
		} catch (IOException e) {
			System.err.println("Could not read configuration file " + path);
			e.printStackTrace();
		} finally {
			if(is != null) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
		return props;
	}
*/

	/**
	 *
	 * @param key Key for the Property to be returned
	 * @return the property
	 */
	public static String getProperty(String key) {
		return props.getProperty(key);
	}

}

@@ -1162,13 +1162,11 @@
 %0A%09%7D%0A
-%09
 %0A/*
-%09
 %0A// 
@@ -1229,18 +1229,17 @@
 lass);%0A%0A
-%09
 %0A
+
 %09public 
@@ -1280,18 +1280,17 @@
 s();%0A%09%7D%0A
-%09
 %0A
+
 %09private
@@ -1320,19 +1320,17 @@
 ies() %7B%0A
-%09%09
 %0A
+
 %09%09String
@@ -1391,19 +1391,17 @@
 S_FILE;%0A
-%09%09
 %0A
+
 %09%09InputS
@@ -1835,11 +1835,9 @@
 %09%09%7D%0A
-%09%09
 %0A
+
 %09%09re
@@ -1993,18 +1993,223 @@
  key) %7B%0A
-
 %09%09
+if (!props.containsKey(key)) %7B%0A            String errorMsg = String.format(%22Property %25s was not present in property file%22, key);%0A            throw new IllegalArgumentException(errorMsg);%0A        %7D%0A        
 return p

Throw exception if property could not be loaded from config file