Java URL Parameter Builder constructParameterString(TreeMap pPostParms)

Here you can find the source of constructParameterString(TreeMap pPostParms)

Description

construct Parameter String

License

Open Source License

Declaration

private static String constructParameterString(TreeMap<String, String> pPostParms)
            throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

import java.util.TreeMap;

public class Main {
    public static final String ENCODING = "UTF-8";
    private static final String URL_EQUALS = "=";
    private static final String URL_AMPERSAND = "&";

    private static String constructParameterString(TreeMap<String, String> pPostParms)
            throws UnsupportedEncodingException {
        StringBuilder sb = new StringBuilder();

        if (pPostParms != null) {
            String cp = ENCODING;

            for (String thisKey : pPostParms.keySet()) {
                String thisVal = pPostParms.get(thisKey);

                if (!thisVal.isEmpty()) {
                    if (!(sb.length() == 0)) {
                        sb.append(URL_AMPERSAND);
                    }//from  ww w  . j a v  a  2 s.  com
                    sb.append(URLEncoder.encode(thisKey, cp));
                    sb.append(URL_EQUALS);
                    sb.append(URLEncoder.encode(thisVal, cp));
                }
            }
        }

        return sb.toString();
    }
}

Related

  1. addParameter(Map> map, String pair)
  2. canonicalize(final SortedMap sortedParamMap)
  3. canonicalize(final SortedMap sortedParamMap)
  4. convertHttpParameters(Map parameters)
  5. convertToDataString(Map data)
  6. convertToParameterString(Map parameterMap)
  7. extractParameters(String parameterString)