Java URL Query Parse parseQueryParameters( String query)

Here you can find the source of parseQueryParameters( String query)

Description

parse Query Parameters

License

Apache License

Declaration

public final static Map<String, String> parseQueryParameters(
            String query) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public final static Map<String, String> parseQueryParameters(
            String query) {//from w  w  w  .j a  v a  2s  . co m
        HashMap<String, String> values = new HashMap<String, String>();
        parseQueryParameters(query, false, values);

        return values;
    }

    public final static Map<String, String> parseQueryParameters(URL url) {
        return parseQueryParameters(url.getQuery());
    }

    public final static Map<String, String> parseQueryParameters(URI url) {
        return parseQueryParameters(url.getQuery());
    }

    public final static void parseQueryParameters(String query,
            boolean lowercaseKeys, Map<String, String> params) {
        if (query == null) {
            return;
        }

        if (query.startsWith("?")) {
            query = query.substring(1);
        }

        String[] parts = query.split("&");
        for (String part : parts) {
            String[] tokens = part.split("=");

            if (lowercaseKeys) {
                tokens[0] = tokens[0].toLowerCase();
            }

            params.put(tokens[0], tokens[1]);
        }
    }
}

Related

  1. parseQuery(String query)
  2. parseQuery(String query)
  3. parseQuery(String query)
  4. parseQuery(String query)
  5. parseQuery(String queryString)
  6. parseQueryParameters( String queryString, String encoding)
  7. parseQueryString(final String newQueryString, final String encoding)
  8. parseQueryString(String input)
  9. parseQueryString(String path)