diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/Globals.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/Globals.java | 172 |
1 files changed, 106 insertions, 66 deletions
diff --git a/src/main/java/org/openslx/imagemaster/Globals.java b/src/main/java/org/openslx/imagemaster/Globals.java index 1f0b876..6f3524b 100644 --- a/src/main/java/org/openslx/imagemaster/Globals.java +++ b/src/main/java/org/openslx/imagemaster/Globals.java @@ -8,43 +8,51 @@ import java.util.Properties; import org.apache.commons.lang3.StringUtils; import org.openslx.imagemaster.server.MasterFtpServer; -public class Globals { +public class Globals +{ + private static final Properties properties = new Properties(); private static boolean loadedProperties = false; - + public static final MasterFtpServer ftpServer = new MasterFtpServer(); - - public static enum PropInt { + + public static enum PropInt + { LDAPPORT, SESSIONTIMEOUTUSER, SESSIONTIMEOUTSERVER, FTPPORT, FTPTIMEOUT } - - public static enum PropString { + + public static enum PropString + { IMAGEDIR, LDAPHOST, LDAPBINDQUERY, LDAPSEARCHBASEDN, LDAPSEARCHFILTER, FTPBASEDIR } - - public static enum PropBool { + + public static enum PropBool + { LDAPSSL } - + /** * Loads the properties from config/global.properties + * * @return if the properties were loaded or not * @throws IOException */ - public static boolean loadProperties() throws IOException { - if (loadedProperties) return false; - + 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(); - + BufferedInputStream stream = new BufferedInputStream( new FileInputStream( "config/global.properties" ) ); + properties.load( stream ); + stream.close(); + return true; } - - public static boolean propertiesValid() { - - if ( Globals.getPropertyString( PropString.IMAGEDIR ) == null + + public static boolean propertiesValid() + { + if ( Globals.getPropertyString( PropString.IMAGEDIR ) == null || Globals.getPropertyString( PropString.IMAGEDIR ).isEmpty() || Globals.getPropertyString( PropString.LDAPHOST ) == null || Globals.getPropertyString( PropString.LDAPHOST ).isEmpty() @@ -56,79 +64,111 @@ public class Globals { || Globals.getPropertyString( PropString.LDAPSEARCHFILTER ).isEmpty() || Globals.getPropertyString( PropString.FTPBASEDIR ) == null || Globals.getPropertyString( PropString.FTPBASEDIR ).isEmpty() - + || Globals.getPropertyInt( PropInt.LDAPPORT ) == 0 || Globals.getPropertyInt( PropInt.SESSIONTIMEOUTUSER ) == 0 || Globals.getPropertyInt( PropInt.SESSIONTIMEOUTSERVER ) == 0 || Globals.getPropertyInt( PropInt.FTPPORT ) == 0 - || Globals.getPropertyInt( PropInt.FTPTIMEOUT ) == 0 - ) { + || Globals.getPropertyInt( PropInt.FTPTIMEOUT ) == 0 ) { return false; } - - if (StringUtils.countMatches(Globals.getPropertyString( PropString.LDAPBINDQUERY ), "%") != 1) { + + if ( StringUtils.countMatches( Globals.getPropertyString( PropString.LDAPBINDQUERY ), "%" ) != 1 ) { return false; } - - if (StringUtils.countMatches(Globals.getPropertyString( PropString.LDAPSEARCHFILTER ), "%") != 1) { + + if ( StringUtils.countMatches( Globals.getPropertyString( PropString.LDAPSEARCHFILTER ), "%" ) != 1 ) { return false; } - + // remove "/" at the end of the path String ftp = Globals.getPropertyString( PropString.FTPBASEDIR ); - if (ftp.endsWith("/")) { - Globals.properties.put("ftp_base_dir", ftp.substring(0, ftp.length() - 1)); + if ( ftp.endsWith( "/" ) ) { + Globals.properties.put( "ftp_base_dir", ftp.substring( 0, ftp.length() - 1 ) ); } - + String image = Globals.getPropertyString( PropString.IMAGEDIR ); - if (image.endsWith("/")) { - Globals.properties.put("image_dir", image.substring(0, image.length() -1 )); + if ( image.endsWith( "/" ) ) { + Globals.properties.put( "image_dir", image.substring( 0, image.length() - 1 ) ); } - + return true; } - - public static int getPropertyInt(Globals.PropInt props) { + + public static int getPropertyInt( Globals.PropInt props ) + { String result = null; - - switch (props) { - case LDAPPORT: result = properties.getProperty( "ldap_port" ); break; - case SESSIONTIMEOUTUSER: result = properties.getProperty( "session_timeout_user" ); break; - case SESSIONTIMEOUTSERVER: result = properties.getProperty( "session_timeout_server" ); break; - case FTPPORT: result = properties.getProperty( "ftp_port" ); break; - case FTPTIMEOUT: result = properties.getProperty( "ftp_timeout" ); break; - default: result = "0"; break; + + switch ( props ) { + case LDAPPORT: + result = properties.getProperty( "ldap_port" ); + break; + case SESSIONTIMEOUTUSER: + result = properties.getProperty( "session_timeout_user" ); + break; + case SESSIONTIMEOUTSERVER: + result = properties.getProperty( "session_timeout_server" ); + break; + case FTPPORT: + result = properties.getProperty( "ftp_port" ); + break; + case FTPTIMEOUT: + result = properties.getProperty( "ftp_timeout" ); + break; + default: + result = "0"; + break; } - - if (result == null) return 0; - + + if ( result == null ) + return 0; + return Integer.valueOf( result ); } - - public static String getPropertyString(Globals.PropString props) { + + public static String getPropertyString( Globals.PropString props ) + { String result = null; - - switch (props) { - case IMAGEDIR: result = properties.getProperty( "image_dir" ); break; - case LDAPHOST: result = properties.getProperty( "ldap_host" ); break; - case LDAPBINDQUERY: result = properties.getProperty( "ldap_bind_query" ); break; - case LDAPSEARCHBASEDN: result = properties.getProperty( "ldap_search_base_dn" ); break; - case LDAPSEARCHFILTER: result = properties.getProperty( "ldap_search_filter" ); break; - case FTPBASEDIR: result = properties.getProperty( "ftp_base_dir" ); break; - default: result = ""; break; + + switch ( props ) { + case IMAGEDIR: + result = properties.getProperty( "image_dir" ); + break; + case LDAPHOST: + result = properties.getProperty( "ldap_host" ); + break; + case LDAPBINDQUERY: + result = properties.getProperty( "ldap_bind_query" ); + break; + case LDAPSEARCHBASEDN: + result = properties.getProperty( "ldap_search_base_dn" ); + break; + case LDAPSEARCHFILTER: + result = properties.getProperty( "ldap_search_filter" ); + break; + case FTPBASEDIR: + result = properties.getProperty( "ftp_base_dir" ); + break; + default: + result = ""; + break; } - + return result; } - - public static boolean getPropertyBool(Globals.PropBool props) { + + public static boolean getPropertyBool( Globals.PropBool props ) + { String result = null; - - switch (props) { - case LDAPSSL: result = properties.getProperty( "ldap_ssl" ); - default: result = ""; break; + + switch ( props ) { + case LDAPSSL: + result = properties.getProperty( "ldap_ssl" ); + default: + result = ""; + break; } - + return Boolean.valueOf( result ); } } |