private void inputOption ( String optionId ) throws InstallationCancelledException { OptionDefinition opt = OptionDefinition . get ( optionId , this ) ; if ( opt . getLabel ( ) == null || opt . getLabel ( ) . length ( ) == 0 ) { throw new InstallationCancelledException ( optionId + " is missing label (check OptionDefinition.properties?)" ) ; } System . out . println ( opt . getLabel ( ) ) ; System . out . println ( dashes ( opt . getLabel ( ) . length ( ) ) ) ; System . out . println ( opt . getDescription ( ) ) ; System . out . println ( ) ; String [ ] valids = opt . getValidValues ( ) ; if ( valids != null ) { System . out . print ( "Options : " ) ; for ( int i = 0 ; i < valids . length ; i ++ ) { if ( i > 0 ) { System . out . print ( ", " ) ; } System . out . print ( valids [ i ] ) ; } System . out . println ( ) ; } String defaultVal = opt . getDefaultValue ( ) ; if ( valids != null || defaultVal != null ) { System . out . println ( ) ; } boolean gotValidValue = false ; while ( ! gotValidValue ) { System . out . print ( "Enter a value " ) ; if ( defaultVal != null ) { System . out . print ( "[default is " + defaultVal + "] " ) ; } System . out . print ( "==> " ) ; String value = readLine ( ) . trim ( ) ; if ( value . length ( ) == 0 && defaultVal != null ) { value = defaultVal ; } System . out . println ( ) ; if ( value . equalsIgnoreCase ( "cancel" ) ) { throw new InstallationCancelledException ( "Cancelled by user." ) ; } try { opt . validateValue ( value ) ; gotValidValue = true ; _map . put ( optionId , value ) ; System . out . println ( ) ; } catch ( OptionValidationException e ) { System . out . println ( "Error: " + e . getMessage ( ) ) ; } } }
Get the indicated option from the console . Continue prompting until the value is valid or the user has indicated they want to cancel the installation .