summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/Globals.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/Globals.java')
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Globals.java85
1 files changed, 85 insertions, 0 deletions
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;
+ }
+ }
+}