package org.opentosca.csarrepo.util;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@WebListener
public class RepositoryProperties implements ServletContextListener {
	
	private static final Logger LOGGER = LogManager.getLogger(RepositoryProperties.class);
	
	public void contextInitialized(ServletContextEvent event) {
		try {
			InputStream propertiesStream = event.getServletContext().getResourceAsStream("WEB-INF/repository.properties");
			System.getProperties().load(propertiesStream);
		} catch (IOException e) {
			LOGGER.error("error while reading properties file " + e.getMessage());
		}
    }
    public void contextDestroyed(ServletContextEvent event) {
        return;
    }
}

@@ -88,16 +88,53 @@
 tream;%0A%0A
+import javax.servlet.ServletContext;%0A
 import j
@@ -167,16 +167,16 @@
 tEvent;%0A
-
 import j
@@ -587,16 +587,78 @@
 %09%09try %7B%0A
+%09%09%09ServletContext servletContext = event.getServletContext();%0A
 %09%09%09Input
@@ -683,26 +683,17 @@
 tream = 
-event.getS
+s
 ervletCo
@@ -697,18 +697,16 @@
 tContext
-()
 .getReso
@@ -752,16 +752,286 @@
 ties%22);%0A
+%09%09%09%0A%09%09%09if(propertiesStream == null) %7B%0A%09%09%09%09LOGGER.error(%22Properties file does not exist. Create %22 + servletContext.getRealPath(%22WEB-INF/repository.properties%22));%0A%09%09%09%09%0A%09%09%09%09throw new RuntimeException(%22Property file does not exist. See log for more information.%22);%0A%09%09%09%7D%0A%09%09%09%0A
 %09%09%09Syste

add error handling for not existing config file, refs #168