summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/Globals.java
blob: ae631f141fdf2e513818ca2abbb76f52c1f04fa7 (plain) (tree)




















































































                                                                                                                          
package org.openslx.satellitedaemon;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Globals
{
	private static final Properties properties = new Properties();
	private static boolean loadedProperties = false;

	/**
	 * If there are more ints or Strings which should be added to config/global.properties,
	 * add to suiting enum, add a 'case' to getPropertyInt/String() and add checks to
	 * propertiesValid()
	 */
	public static enum PropInt
	{
		FTPPORT
	}
	
	public static enum PropString
	{
		FTPSERVERIP
	}

	public static boolean loadProperties() throws IOException
	{
		if ( loadedProperties )
			return false;

		// Load properties
		BufferedInputStream stream = new BufferedInputStream( new FileInputStream( "config/global.properties" ) );
		properties.load( stream );
		stream.close();

		return true;
	}

	public static int getPropertyInt( Globals.PropInt props )
	{
		String result = null;

		switch ( props ) {
		case FTPPORT:
			result = properties.getProperty( "ftp_port" );
			break;
		default:
			result = "0";
			break;
		}
		if ( result == null )
			return 0;

		return Integer.valueOf( result );
	}
	
	public static String getPropertyString( Globals.PropString props )
	{
		String result = null;

		switch ( props ) {
		case FTPSERVERIP:
			result = properties.getProperty( "ftp_server_ip" );
			break;
		default:
			result = "";
			break;
		}
		return result;
	}

	public static boolean propertiesValid()
	{
		if (Globals.getPropertyInt( PropInt.FTPPORT ) == 0
				|| Globals.getPropertyString( PropString.FTPSERVERIP ).isEmpty()
				|| Globals.getPropertyString( PropString.FTPSERVERIP ) == null) {
			return false;
		}
		else {
			return true;
		}
	}
}