package org.jboss.aerogear.unifiedpush.service;

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

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;

import org.jboss.aerogear.unifiedpush.utils.AeroGearLogger;

@Singleton
@Startup
public class Configuration {
	
    private final AeroGearLogger logger = AeroGearLogger.getInstance(Configuration.class);

	private static final String PROPERTIES_FILE_KEY = "aerogear.config";
	
	private Properties properties;
	
	@PostConstruct
	public void loadProperties() {
		final String propertiesFilePath = System.getProperty(PROPERTIES_FILE_KEY);
		properties = new Properties();
		
		if (propertiesFilePath != null) {
			File propertiesFile = new File(propertiesFilePath);
			try {
				loadPropertiesFromStream(new FileInputStream(propertiesFile));
			} catch (FileNotFoundException e) {
				logger.severe("cannot open file " + propertiesFilePath);
			} 
		} else {
			loadDefaultProperties();
		}
	}
	
	public String getProperty(String key) {
		return properties.getProperty(key);
	}
	
	public Properties getProperties() {
		return new PropertiesView(properties);
	}
	
	private void loadDefaultProperties() {
		InputStream inp = getClass().getClassLoader().getResourceAsStream("default.properties");
		if (inp == null) {
			logger.warning("default properties not found");
		}
		loadPropertiesFromStream(inp);
	}
	
	private void loadPropertiesFromStream(InputStream inp) {
		try (InputStream in = inp) {
			properties.load(in);
		} catch (IOException e) {
		    logger.severe("Cannot load configuration", e);
		} 
	}
	
	@SuppressWarnings("serial")
	private class PropertiesView extends Properties {
		private final Properties properties;
		
		public PropertiesView(Properties properties) {
			this.properties = properties;
		}
		
		public String getProperty(String key) {
			return properties.getProperty(key);
		}
	}
}

@@ -1185,24 +1185,219 @@
 (key);%0A%09%7D%0A%09%0A
+%09public boolean getBooleanProperty(String key, boolean defaultValue) %7B%0A%09%09String value = getProperty(key);%0A%09%09if (value == null) %7B%0A%09%09%09return defaultValue;%0A%09%09%7D%0A%09%09return Boolean.valueOf(value);%0A%09%7D%0A%09%0A
 %09public Prop
@@ -1673,17 +1673,25 @@
 d%22);%0A%09%09%7D
-%0A
+ else %7B%0A%09
 %09%09loadPr
@@ -1715,16 +1715,20 @@
 m(inp);%0A
+%09%09%7D%0A
 %09%7D%0A%09%0A%09pr

Fix null check