public static HashMap < String , String [ ] > parseQueryString ( String parseString ) throws StorageException { final HashMap < String , String [ ] > retVals = new HashMap < String , String [ ] > ( ) ; if ( Utility . isNullOrEmpty ( parseString ) ) { return retVals ; } // 1. Remove ? if present final int queryDex = parseString . indexOf ( "?" ) ; if ( queryDex >= 0 && parseString . length ( ) > 0 ) { parseString = parseString . substring ( queryDex + 1 ) ; } // 2. split name value pairs by splitting on the 'c&' character final String [ ] valuePairs = parseString . contains ( "&" ) ? parseString . split ( "&" ) : parseString . split ( ";" ) ; // 3. for each field value pair parse into appropriate map entries for ( int m = 0 ; m < valuePairs . length ; m ++ ) { final int equalDex = valuePairs [ m ] . indexOf ( "=" ) ; if ( equalDex < 0 || equalDex == valuePairs [ m ] . length ( ) - 1 ) { continue ; } String key = valuePairs [ m ] . substring ( 0 , equalDex ) ; String value = valuePairs [ m ] . substring ( equalDex + 1 ) ; key = Utility . safeDecode ( key ) ; value = Utility . safeDecode ( value ) ; // 3.1 add to map String [ ] values = retVals . get ( key ) ; if ( values == null ) { values = new String [ ] { value } ; if ( ! value . equals ( Constants . EMPTY_STRING ) ) { retVals . put ( key , values ) ; } } else if ( ! value . equals ( Constants . EMPTY_STRING ) ) { final String [ ] newValues = new String [ values . length + 1 ] ; for ( int j = 0 ; j < values . length ; j ++ ) { newValues [ j ] = values [ j ] ; } newValues [ newValues . length ] = value ; } } return retVals ; }
Parses a query string into a one to many hashmap .