/* 
 * Licensed to the soi-toolkit project under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The soi-toolkit project licenses this file to You 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 org.soitoolkit.tools.generator.util;

import java.util.MissingResourceException;
import java.util.ResourceBundle;


public class PreferencesUtil {

	/**
     * Hidden constructor.
     */
    private PreferencesUtil() {
        throw new UnsupportedOperationException("Not allowed to create an instance of this class");
    }

    static public String getDefaultRootFolder() {
    	return get("root_folder", getUserHome());
    }
    
    static public String getMavenHome() {
    	return get("maven_home", "");
    }
    
	static public String getCustomGroovyModelImpl() {
    	return get("custom_groovy_model_impl", "");
	}

    static public String getDefaultFileRootFolder() {
    	return get("file_root_folder", getUserHome() + "/soitoolkit/file-transport");
    }
    
    static public String getDefaultFtpRootFolder() {
    	return get("ftp_root_folder", "${SOITOOLKIT_FTP_USERNAME}:${SOITOOLKIT_FTP_PASSWORD}@localhost:8021/ftp");
    }
    
	static public String getDefaultFtpUsername() {
    	return get("ftp_default_usr", "muletest1");
    }
	
	static public String getDefaultFtpPassword() {
    	return get("ftp_default_pwd", "muletest1");
    }

	static public String getDefaultSftpUsername() {
    	return get("sftp_default_usr", "muletest1");
    }
    
    static public String getDefaultSftpRootFolder() {
    	return get("sftp_root_folder", "${SOITOOLKIT_SFTP_USERNAME}@localhost:2222/~/sftp");
    }
    
    static public String getDefaultSftpIdentityFile() {
    	//return get("sftp_identity_file", getUserHome() + "/.ssh/id_dsa");
    	// id file that is generated when the embedded sftp-server is started
    	return get("sftp_identity_file", "target/ssh/id_dsa");
    }
    
    static public String getDefaultSftpIdentityPassphrase() {
    	// passphrase for the private key that is generated when
    	// the embedded sftp-server is started
    	return get("sftp_identity_passphrase", "testonly");
    }

    static public String getDefaultArchiveFolder() {
    	//return get("archive_folder", getUserHome() + "/soitoolkit/archive");
    	return get("archive_folder", "target/soitoolkit/archive");
    }

    // -----------------
	
    static private ResourceBundle defaultPreferences = null;
    
    static private ResourceBundle getDefaultPreferences() {
    	if (defaultPreferences == null) {
    		defaultPreferences = ResourceBundle.getBundle("soi_toolkit_generator_plugin_default_preferences");
    	}
    	return defaultPreferences;
    }

    static private String get(String key, String defaultValue) {
    	try {
			String value = getDefaultPreferences().getString(key);
			return (value.trim().length() > 0) ? value : defaultValue;
		} catch (MissingResourceException mre) {
			return defaultValue;
		}
    }
    
    static private String getUserHome() {
		return System.getProperty("user.home").replace('\\', '/');
    }
}
@@ -1181,32 +1181,34 @@
 Folder() %7B%0A    %09
+//
 return get(%22root
@@ -1233,16 +1233,58 @@
 ome());%0A
+    %09return get(%22root_folder%22, %22target%22);%0A
     %7D%0A  
@@ -1529,32 +1529,34 @@
 Folder() %7B%0A    %09
+//
 return get(%22file
@@ -1613,24 +1613,97 @@
 ransport%22);%0A
+    %09return get(%22file_root_folder%22, %22target/soitoolkit/file-transport%22);%0A
     %7D%0A    %0A 

Update issue 215