public static String addParams ( String href , HttpParameters params , String encoding ) throws UnsupportedEncodingException { if ( params != null ) { StringBuilder sb = new StringBuilder ( href ) ; // First find any anchor and if has parameters int anchorStart = href . lastIndexOf ( ' ' ) ; String anchor ; boolean hasQuestion ; if ( anchorStart == - 1 ) { anchor = null ; hasQuestion = href . lastIndexOf ( ' ' ) != - 1 ; } else { anchor = href . substring ( anchorStart ) ; sb . setLength ( anchorStart ) ; hasQuestion = href . lastIndexOf ( ' ' , anchorStart - 1 ) != - 1 ; } for ( Map . Entry < String , List < String > > entry : params . getParameterMap ( ) . entrySet ( ) ) { String encodedName = URLEncoder . encode ( entry . getKey ( ) , encoding ) ; for ( String value : entry . getValue ( ) ) { if ( hasQuestion ) sb . append ( ' ' ) ; else { sb . append ( ' ' ) ; hasQuestion = true ; } sb . append ( encodedName ) ; assert value != null : "null values no longer supported to be consistent with servlet environment" ; sb . append ( ' ' ) . append ( URLEncoder . encode ( value , encoding ) ) ; } } if ( anchor != null ) sb . append ( anchor ) ; href = sb . toString ( ) ; } return href ; }
Adds all of the parameters to a URL .