summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/Globals.java
diff options
context:
space:
mode:
authorMichael Petretti2014-05-26 15:22:13 +0200
committerMichael Petretti2014-05-26 15:22:13 +0200
commita00f154064936fb3ec8d2ed37a7cf9cc681e0421 (patch)
tree2e0970077f4a740547e2dbe89b1f120f7e513c80 /src/main/java/org/openslx/satellitedaemon/Globals.java
parentAdded some notes (diff)
downloadsatellite-daemon-a00f154064936fb3ec8d2ed37a7cf9cc681e0421.tar.gz
satellite-daemon-a00f154064936fb3ec8d2ed37a7cf9cc681e0421.tar.xz
satellite-daemon-a00f154064936fb3ec8d2ed37a7cf9cc681e0421.zip
Added a Globals.java class for properties handling.
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;
+ }
+ }
+}