public static Map < String , String > parseQueryParameters ( String rawQuery ) { Map < String , String > ret = new LinkedHashMap < String , String > ( ) ; if ( rawQuery == null || rawQuery . length ( ) == 0 ) { return ret ; } try { String [ ] pairs = rawQuery . split ( "&" ) ; for ( String pair : pairs ) { int idx = pair . indexOf ( "=" ) ; String name ; String value ; if ( idx > 0 ) { // name=value name = pair . substring ( 0 , idx ) ; value = URLDecoder . decode ( pair . substring ( idx + 1 ) , PcsUtils . UTF8 . name ( ) ) ; } else if ( idx < 0 ) { // name (no value) name = pair ; value = null ; } else { // =value ?? we ignore this name = null ; value = null ; } if ( name != null ) { ret . put ( name , value ) ; } } return ret ; } catch ( UnsupportedEncodingException ex ) { throw new RuntimeException ( ex ) ; } }
Parse a query param string into a map of parameters .