package org.kurento.commons;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConfigFileManager {

	private static final Logger log = LoggerFactory
			.getLogger(ConfigFileManager.class);

	private static final String CONFIG_FILE_PATH_PROPERTY = "configFilePath";

	public static void loadConfigFile() {
		loadConfigFile("kurento.conf.json");
	}

	public static void loadConfigFile(String configFileName) {

		try {

			String configFilePath = System
					.getProperty(CONFIG_FILE_PATH_PROPERTY);

			Path configFile = null;

			if (configFilePath != null) {
				configFile = Paths.get(configFilePath);

				if (!Files.exists(configFile)) {
					log.warn(
							"Property '{}' points to an invalid location '{}'. Searching default config file '{}' in classpath and workdir",
							CONFIG_FILE_PATH_PROPERTY, configFilePath,
							configFileName);
					configFile = ConfigFileFinder
							.searchConfigFileInDefaultPlaces(configFileName);
				} else {
					log.info("Property {} points to a valid location. Will use the config from {}", CONFIG_FILE_PATH_PROPERTY, configFilePath);
				}
				
			} else {
				configFile = ConfigFileFinder
						.searchConfigFileInDefaultPlaces(configFileName);
			}

			if (configFile != null && Files.exists(configFile)) {
				ConfigFilePropertyHolder
				.configurePropertiesFromConfigFile(configFile);
			} else {
				log.warn("Config file {} not found. Using all default values", configFileName);
			}

		} catch (IOException e) {
			log.warn("Exception loading config file", e);
		}
	}

}

@@ -391,16 +391,89 @@
 lePath%22;
+%0A%09private static final String CONFIG_FILE_PATH_PROPERTY2 = %22config.file%22;
 %0A%0A%09publi
@@ -699,16 +699,124 @@
 ERTY);%0A%0A
+%09%09%09if (configFilePath == null) %7B%0A%09%09%09%09configFilePath = System.getProperty(CONFIG_FILE_PATH_PROPERTY2);%0A%09%09%09%7D%0A%0A
 %09%09%09Path 
@@ -1278,16 +1278,24 @@
 og.info(
+%0A%09%09%09%09%09%09%09
 %22Propert
@@ -1356,17 +1356,24 @@
 rom %7B%7D%22,
- 
+%0A%09%09%09%09%09%09%09
 CONFIG_F
@@ -1414,20 +1414,16 @@
 ;%0A%09%09%09%09%7D%0A
-%09%09%09%09
 %0A%09%09%09%7D el
@@ -1613,16 +1613,18 @@
 der%0A%09%09%09%09
+%09%09
 .configu
@@ -1741,17 +1741,23 @@
 values%22,
- 
+%0A%09%09%09%09%09%09
 configFi

Add "config.file" as alias for "configFilePath" system property