From a00f154064936fb3ec8d2ed37a7cf9cc681e0421 Mon Sep 17 00:00:00 2001 From: Michael Petretti Date: Mon, 26 May 2014 15:22:13 +0200 Subject: Added a Globals.java class for properties handling. --- .../java/org/openslx/satellitedaemon/Globals.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/main/java/org/openslx/satellitedaemon/Globals.java (limited to 'src/main/java/org/openslx/satellitedaemon/Globals.java') diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java new file mode 100644 index 0000000..ae631f1 --- /dev/null +++ b/src/main/java/org/openslx/satellitedaemon/Globals.java @@ -0,0 +1,85 @@ +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; + } + } +} -- cgit v1.2.3-55-g7522