public void addParameters ( String url ) { if ( ( url != null ) && ! "" . equals ( url ) ) { url = url . trim ( ) ; if ( url . length ( ) > 1 ) { if ( url . contains ( "?" ) ) { url = url . substring ( url . indexOf ( ' ' ) + 1 ) ; } String pairs [ ] = url . split ( "&(amp;)?" ) ; for ( String pair : pairs ) { String name ; String value ; int pos = pair . indexOf ( ' ' ) ; // for "n=", the value is "", for "n", the value is null if ( pos == - 1 ) { name = pair ; value = null ; } else { try { // FIXME This probably shouldn't be happening here. name = URLDecoder . decode ( pair . substring ( 0 , pos ) , "UTF-8" ) ; value = URLDecoder . decode ( pair . substring ( pos + 1 , pair . length ( ) ) , "UTF-8" ) ; } catch ( IllegalArgumentException e ) { // thrown by URLDecoder if character decoding fails log . warn ( "Ignoring invalid query parameter: " + pair ) ; continue ; } catch ( UnsupportedEncodingException e ) { throw new PrettyException ( "UTF-8 encoding not supported. Something is seriously wrong with your environment." ) ; } } List < String > list = parameters . get ( name ) ; if ( list == null ) { list = new ArrayList < String > ( ) ; parameters . put ( name , list ) ; } list . add ( value ) ; } } } return ; }
Add parameters from the given URL . If a ? character is encountered in the URL the any characters up to and including the first ? will be ignored . If a parameter already exists append new values to the existing list of values for that parameter .