private String parseLink ( final String link ) { String [ ] tokens = link . substring ( 7 , link . length ( ) - 1 ) . split ( "\\s" ) ; if ( tokens . length == 1 ) { return tokens [ 0 ] ; } StringBuilder result = new StringBuilder ( ) ; boolean parametersSeen = false ; boolean inParameters = false ; for ( int index = 0 ; index < tokens . length ; index ++ ) { result . append ( " " ) . append ( tokens [ index ] ) ; if ( tokens [ index ] . indexOf ( ' ' ) != - 1 && ! parametersSeen ) { inParameters = true ; } if ( index == 1 && ! inParameters ) { result = new StringBuilder ( tokens [ index ] ) ; } if ( tokens [ index ] . indexOf ( ' ' ) != - 1 && ! parametersSeen ) { parametersSeen = true ; if ( index != tokens . length - 1 ) { result = new StringBuilder ( ) ; } } } return result . toString ( ) . trim ( ) ; }
a helper method to process the links as they are found .