blob: 3bfd5cb6c474bb47503d0d063d28afb37d65e931 (
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().
*
* As an Example, if you want the value of the FTPSERVERIP you have to call
* Globals.getPropertyString( PropString.FTPSERVERIP ) which returns a string.
*/
public static enum PropInt
{
FTPPORT, THRIFTPORT // More int's? Add them separated with ","
}
public static enum PropString
{ // More strings's? Add them separated with ","
FTPSERVERIP, KEYSTORETYPE, FTPSKEYSTOREPATH, FTPSKEYSTOREPWD, THRIFTORGANIZATIONNAME,
RNDSTRINGENCRYPTALIAS, RNDSTRINGENCRYPTPASSWORD, RNDSTRINGENCRYPTPATH
}
public static boolean loadProperties() throws IOException
{
if ( loadedProperties )
return false;
// Load all entries of the config file into properties
BufferedInputStream stream = new BufferedInputStream( new FileInputStream( "config/global.properties" ) );
properties.load( stream );
stream.close();
return true;
}
// Calling
public static int getPropertyInt( Globals.PropInt props )
{
String result = null;
switch ( props ) {
case FTPPORT:
result = properties.getProperty( "ftp_port" );
break;
case THRIFTPORT:
result = properties.getProperty( "ThriftPort" );
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;
case KEYSTORETYPE:
result = properties.getProperty( "keyStore_type" );
break;
case FTPSKEYSTOREPATH:
result = properties.getProperty( "path_to_ftps_keyStore" );
break;
case FTPSKEYSTOREPWD:
result = properties.getProperty( "ftps_keyStore_password" );
break;
case THRIFTORGANIZATIONNAME:
result = properties.getProperty( "organization_name" );
break;
case RNDSTRINGENCRYPTALIAS:
result = properties.getProperty( "RndStringEncrypt_alias" );
break;
case RNDSTRINGENCRYPTPASSWORD:
result = properties.getProperty( "RndStringEncrypt_password" );
break;
case RNDSTRINGENCRYPTPATH:
result = properties.getProperty( "RndStringEncrypt_path" );
break;
default:
result = "";
break;
}
return result;
}
public static boolean propertiesValid()
{
if ( Globals.getPropertyInt( PropInt.FTPPORT ) == 0
|| Globals.getPropertyInt( PropInt.THRIFTPORT ) == 0
|| Globals.getPropertyString( PropString.FTPSERVERIP ).isEmpty()
|| Globals.getPropertyString( PropString.FTPSERVERIP ) == null
|| Globals.getPropertyString( PropString.KEYSTORETYPE ).isEmpty()
|| Globals.getPropertyString( PropString.KEYSTORETYPE ) == null
|| Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ).isEmpty()
|| Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) == null
|| Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).isEmpty()
|| Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ) == null
|| Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME ).isEmpty()
|| Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME ) == null
|| Globals.getPropertyString( PropString.RNDSTRINGENCRYPTALIAS ).isEmpty()
|| Globals.getPropertyString( PropString.RNDSTRINGENCRYPTALIAS ) == null
|| Globals.getPropertyString( PropString.RNDSTRINGENCRYPTPASSWORD ).isEmpty()
|| Globals.getPropertyString( PropString.RNDSTRINGENCRYPTPASSWORD ) == null
|| Globals.getPropertyString( PropString.RNDSTRINGENCRYPTPATH ).isEmpty()
|| Globals.getPropertyString( PropString.RNDSTRINGENCRYPTPATH ) == null ) {
return false;
}
else {
return true;
}
}
}
|