/*
 * Copyright 2015 University of Oxford
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.ox.it.ords.security.configuration;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.DefaultConfigurationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Local configuration manager
 */
public class MetaConfiguration {

	public static Logger log = LoggerFactory.getLogger(MetaConfiguration.class);

	private static Configuration config;
	
	/**
	 * Load meta-configuration
	 */
    private static void load(){
		try {
			DefaultConfigurationBuilder factory = new DefaultConfigurationBuilder("config.xml");
			factory.load();
			config = factory.getConfiguration();
		} catch (Exception e) {
			config = null;
			e.printStackTrace();
			log.warn("No server configuration location set; using defaults");
		}
	}
    
    public static Configuration getConfiguration(){
    	if (config == null) load();
    	return config;
    }
}

@@ -649,16 +649,38 @@
 ation;%0A%0A
+import java.io.File;%0A%0A
 import o
@@ -726,16 +726,16 @@
 ration;%0A
-
 import o
@@ -1045,16 +1045,84 @@
 nfig;%0A%09%0A
+%09private static final String ORDS_CONFIG_FILENAME = %22config.xml%22;%0A%09%0A
 %09/**%0A%09 *
@@ -1191,16 +1191,319 @@
 %09%09try %7B%0A
+%09%09%09%0A%09%09%09String ordsConfigurationLocation = %22%22;%0A%09%09%09final String ORDS_CONF_DIR = System.getenv(%22ORDS_CONF_DIR%22);%0A%09%09%09if (ORDS_CONF_DIR != null)%7B%0A%09%09%09%09ordsConfigurationLocation = ORDS_CONF_DIR + File.separator + ORDS_CONFIG_FILENAME;%0A%09%09%09%7D else %7B%0A%09%09%09%09ordsConfigurationLocation = ORDS_CONFIG_FILENAME;%0A%09%09%09%7D%0A%09%09%09%0A
 %09%09%09Defau
@@ -1567,28 +1567,41 @@
 Builder(
-%22config.xml%22
+ordsConfigurationLocation
 );%0A%09%09%09fa
@@ -1680,16 +1680,16 @@
 on e) %7B%0A
+
 %09%09%09confi
@@ -1702,32 +1702,8 @@
 ll;%0A
-%09%09%09e.printStackTrace();%0A
 %09%09%09l

Load master configuration using an environment variable - this allows easier reconfiguration of the service when deployed remotely.