Java URI to Parameter getQueryParameters(URI uri)

Here you can find the source of getQueryParameters(URI uri)

Description

get Query Parameters

License

BSD License

Declaration

public static Map<String, String> getQueryParameters(URI uri) 

Method Source Code


//package com.java2s;
/*/*from ww w .ja v a 2 s.  c  om*/
 * Copyright (c) 2013. betterFORM Project - http://www.betterform.de
 * Licensed under the terms of BSD License
 */

import java.net.URI;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

public class Main {
    private static final String AMPF = "&";
    private static final String EQ = "=";

    public static Map<String, String> getQueryParameters(URI uri) {

        if (null == uri || null == uri.getQuery()) {
            return Collections.emptyMap();
        }

        Map<String, String> result = new LinkedHashMap<String, String>();
        for (String pair : uri.getQuery().split(AMPF)) {
            if (1 > pair.indexOf(EQ)) {
                result.put(pair, null);
            } else {
                String[] kv = pair.split(EQ);
                result.put(kv[0], kv[1]);
            }
        }

        return result;
    }
}

Related

  1. getQueryKeyValuePairs(URI uri)
  2. getQueryKeyValuePairs(URI uri)
  3. getQueryParameter(final String param, URI data)
  4. getQueryParameters(URI uri)
  5. getQueryParameterValues(String uri, String name)
  6. getParameters(URI uri)
  7. getParameters(URI uri)