package org.pig.oink.common.config;

import java.io.InputStream;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.PropertyConfigurator;

public class ConfigurationLoader implements ServletContextListener {
	@Override
	public void contextInitialized(ServletContextEvent se) {
		String logFileName = se.getServletContext().getInitParameter("log4jFileName");
		String env= System.getenv("env");
		
		String confFileName;
		if (env == null){
			confFileName = se.getServletContext().getInitParameter("configFileName");
		}else{
			confFileName= "/" + env + ".properties";
		}
		
		if(logFileName != null) {
			InputStream in = getClass().getResourceAsStream(logFileName);
			if(in == null) {
				in = ClassLoader.getSystemResourceAsStream(logFileName);
			}
			try {
				PropertyConfigurator.configure(in);
			} catch(Exception e) {
				e.printStackTrace();
			}
		}
		if (confFileName != null){
			PropertyLoader.getInstance().init(confFileName);
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {		
	}
}

@@ -1,8 +1,604 @@
+/*%0D%0ACopyright 2013-2014 eBay Software Foundation%0D%0A %0D%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0D%0Ayou may not use this file except in compliance with the License.%0D%0AYou may obtain a copy of the License at%0D%0A %0D%0A    http://www.apache.org/licenses/LICENSE-2.0%0D%0A %0D%0AUnless required by applicable law or agreed to in writing, software%0D%0Adistributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0AWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0ASee the License for the specific language governing permissions and%0D%0Alimitations under the License.%0D%0A*/%0D%0A%0D%0A
 package 

Update ConfigurationLoader.java