Java URL Parameter Builder extractParameters(String parameterString)

Here you can find the source of extractParameters(String parameterString)

Description

extract Parameters

License

Apache License

Declaration

private static Map<String, String> extractParameters(String parameterString) 

Method Source Code


//package com.java2s;
/*/*w w  w  .j ava  2s .com*/
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static Map<String, String> extractParameters(String parameterString) {
        Map<String, String> params = new HashMap<String, String>();
        if (parameterString != null) {
            String[] paramPairs = parameterString.split("&");
            for (String pair : paramPairs) {
                String[] keyValue = pair.split("=");
                if (keyValue.length == 2) {
                    // TODO: Determine if this decode step is necessary, since it's just going to be encoded again later
                    params.put(keyValue[0], decode(keyValue[1]));
                }
            }
        }
        return params;
    }

    private static String decode(String encoded) {
        try {
            return URLDecoder.decode(encoded, "UTF-8");
        } catch (UnsupportedEncodingException shouldntHappen) {
            return encoded;
        }
    }
}

Related

  1. canonicalize(final SortedMap sortedParamMap)
  2. constructParameterString(TreeMap pPostParms)
  3. convertHttpParameters(Map parameters)
  4. convertToDataString(Map data)
  5. convertToParameterString(Map parameterMap)
  6. format(final Map> parameters, final String encoding)
  7. format(Map parameters, final String encoding)
  8. getParameter(String source, int index)
  9. getParameterMap(byte[] bytea)