protected List < String > parseCommand ( ConfigurationHolder configurationHolder , String command ) { //init list List < String > commandList = new LinkedList < String > ( ) ; StringBuilder buffer = new StringBuilder ( command ) ; String part = null ; int quoteIndex = - 1 ; int spaceIndex = - 1 ; int length = - 1 ; do { quoteIndex = buffer . indexOf ( "\"" ) ; spaceIndex = buffer . indexOf ( " " ) ; if ( quoteIndex == - 1 ) { if ( spaceIndex == - 1 ) { buffer = this . addAllBuffer ( commandList , buffer ) ; } else { buffer = this . addPart ( commandList , buffer , spaceIndex , true ) ; } } else if ( spaceIndex == - 1 ) { if ( quoteIndex == - 1 ) { buffer = this . addAllBuffer ( commandList , buffer ) ; } else if ( quoteIndex == 0 ) { quoteIndex = buffer . indexOf ( "\"" , 1 ) ; if ( quoteIndex == - 1 ) { throw new FaxException ( "Unable to parse command: " + command ) ; } buffer = this . addPart ( commandList , buffer , quoteIndex , false ) ; } else { throw new FaxException ( "Unable to parse command: " + command ) ; } } else if ( quoteIndex < spaceIndex ) { if ( quoteIndex == 0 ) { quoteIndex = buffer . indexOf ( "\"" , 1 ) ; if ( quoteIndex == - 1 ) { throw new FaxException ( "Unable to parse command: " + command ) ; } buffer = this . addPart ( commandList , buffer , quoteIndex , false ) ; } else { buffer = this . addPart ( commandList , buffer , spaceIndex , true ) ; } } else //spaceIndex<quoteIndex { buffer = this . addPart ( commandList , buffer , spaceIndex , true ) ; } length = buffer . length ( ) ; if ( length > 0 ) { part = buffer . toString ( ) ; part = part . trim ( ) ; buffer . delete ( 0 , length ) ; buffer . append ( part ) ; length = buffer . length ( ) ; } } while ( length > 0 ) ; return commandList ; }
This function parsers the command and converts to a command array .