package plugin;

import java.io.IOException;
import java.util.Map.Entry;
import java.util.Properties;

import play.Logger;
import play.Play;
import play.PlayPlugin;
import play.libs.IO;

public class PropertiesFileConfigurationPlugin extends PlayPlugin {
	
	@Override
	public void onConfigurationRead() {
		String[] propertiesFilenames = Play.configuration.getProperty("externalConfig.fileName", "/" + Play.id + ".properties").split(",");
		
		for (String propertiesFilename : propertiesFilenames) {
			Logger.info("Loading configuration from " + propertiesFilename);
			Properties properties = IO.readUtf8Properties(this.getClass().getResourceAsStream(propertiesFilename));
			
			for (Entry<Object, Object> entry : properties.entrySet()) {
				Play.configuration.setProperty((String) entry.getKey(),(String) entry.getValue());
			}
		}
	}

}

@@ -10,16 +10,114 @@
 lugin;%0A%0A
+import java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.InputStream;%0A
 import j
@@ -536,90 +536,546 @@
 ;%0A%09%09
-%0A%09%09for (String propertiesFilename : propertiesFilenames) %7B%0A%09%09%09Logger.info(%22Loading
+String propertiesFileAbsolutePath = Play.configuration.getProperty(%22externalConfig.fileAbsolutePath%22);%0A%09%09%0A%09%09for (String propertiesFilename : propertiesFilenames) %7B%0A%09%09%09String propertiesFilenameAndPath = null;%0A%09%09%09InputStream is = null;%0A%09%09%09if (propertiesFileAbsolutePath != null) %7B%0A%09%09%09%09propertiesFilenameAndPath = propertiesFileAbsolutePath + System.getProperty(%22file.separator%22) + propertiesFilename;%0A%09%09%09%09try %7B%0A%09%09%09%09%09is = new FileInputStream(propertiesFilenameAndPath);%0A%09%09%09%09%7D catch (FileNotFoundException fnfe) %7B%0A%09%09%09%09%09Logger.error(%22Not found
  con
@@ -1090,11 +1090,11 @@
 on f
-rom
+ile
  %22 +
@@ -1116,122 +1116,349 @@
 name
-);%0A%09%09%09Properties properties = IO.readUtf8Properties(this.getClass().getResourceAsStream(propertiesFilename));%0A%09%09%09%0A
+AndPath);%0A%09%09%09%09%7D%0A%09%09%09%7D else %7B%0A%09%09%09%09// get from classpath%0A%09%09%09%09propertiesFilenameAndPath = propertiesFilename;%0A        is = this.getClass().getResourceAsStream(propertiesFilenameAndPath);%0A      %7D%0A%09%09%09Logger.info(%22Loading configuration from %22 + propertiesFilenameAndPath);%0A%09%09%09%0A%09%09%09try  %7B%0A%09%09%09%09Properties properties = IO.readUtf8Properties(is);%0A%09%09%09%09%0A%09
 %09%09%09f
@@ -1512,24 +1512,25 @@
 trySet()) %7B%0A
+%09
 %09%09%09%09Play.con
@@ -1604,16 +1604,123 @@
 lue());%0A
+%09%09%09%09%7D%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09Logger.error(%22Error when loading file %22 + propertiesFilenameAndPath);%0A
 %09%09%09%7D%0A%09%09%7D

add absolute path feature and catch error for readUtf8Properties method