blob: ae631f141fdf2e513818ca2abbb76f52c1f04fa7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;
}
}
}
|