Parse the query string into an unordered map of name/value pairs. If keepDuplicates parameter is true, then the resulting map will contain values of String object when only one occurrence of a key is found in the query, and an ordered List object if more than one occurrence is found, where the list
(String query, boolean keepDuplicates)
| 511 | * @return the parsed parameters. |
| 512 | */ |
| 513 | public static Hashtable<String, Object> parseQuery(String query, boolean keepDuplicates) throws URISyntaxException { |
| 514 | if (query == null) { |
| 515 | return null; |
| 516 | } |
| 517 | Hashtable<String, Object> parameters = new Hashtable<String, Object>(); |
| 518 | List<NameValuePair> nvps = parseQueryOrdered(query); |
| 519 | Iterator<NameValuePair> i = nvps.iterator(); |
| 520 | while(i.hasNext()) { |
| 521 | NameValuePair nvp = i.next(); |
| 522 | if (parameters.containsKey(nvp.getName())) { |
| 523 | if (keepDuplicates == true) { |
| 524 | Object v = parameters.get(nvp.getName()); |
| 525 | if (v instanceof String) { |
| 526 | parameters.put(nvp.getName(), new String[]{(String) v, nvp.getValue()}); |
| 527 | } else { |
| 528 | int size = ((String[]) v).length; |
| 529 | String array[] = new String[size + 1]; |
| 530 | System.arraycopy(v, 0, array, 0, size); |
| 531 | array[size] = nvp.getValue(); |
| 532 | parameters.put(nvp.getName(), nvp.getValue()); |
| 533 | } |
| 534 | } |
| 535 | } else { |
| 536 | parameters.put(nvp.getName(), (nvp.getValue() == null) ? String.valueOf(true) : nvp.getValue()); |
| 537 | } |
| 538 | } |
| 539 | return parameters; |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * Get the default port that would be used for this connection if the port |
no test coverage detected