Example usage for org.apache.commons.httpclient.params HttpMethodParams setLongParameter

List of usage examples for org.apache.commons.httpclient.params HttpMethodParams setLongParameter

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpMethodParams setLongParameter.

Prototype

public void setLongParameter(String paramString, long paramLong) 

Source Link

Usage

From source file:org.apache.maven.wagon.providers.webdav.HttpMethodConfiguration.java

private void fillParams(HttpMethodParams p) {
    if (!hasParams()) {
        return;/*from  www  .j a v a  2  s  .c  o  m*/
    }

    if (connectionTimeout > 0) {
        p.setSoTimeout(connectionTimeout);
    }

    if (params != null) {
        Pattern coercePattern = Pattern.compile(COERCE_PATTERN);

        for (Map.Entry<Object, Object> entry : params.entrySet()) {
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();

            Matcher matcher = coercePattern.matcher(value);
            if (matcher.matches()) {
                char type = matcher.group(1).charAt(0);
                value = matcher.group(2);

                switch (type) {
                case 'i': {
                    p.setIntParameter(key, Integer.parseInt(value));
                    break;
                }
                case 'd': {
                    p.setDoubleParameter(key, Double.parseDouble(value));
                    break;
                }
                case 'l': {
                    p.setLongParameter(key, Long.parseLong(value));
                    break;
                }
                case 'b': {
                    p.setBooleanParameter(key, Boolean.valueOf(value).booleanValue());
                    break;
                }
                case 'c': {
                    String[] entries = value.split(",");
                    List<String> collection = new ArrayList<String>();
                    for (String e : entries) {
                        collection.add(e.trim());
                    }

                    p.setParameter(key, collection);
                    break;
                }
                case 'm': {
                    String[] entries = value.split(",");

                    Map<String, String> map = new LinkedHashMap<String, String>();
                    for (String e : entries) {
                        int idx = e.indexOf("=>");
                        if (idx < 1) {
                            break;
                        }

                        String mapKey = e.substring(0, idx);
                        String mapVal = e.substring(idx + 1, e.length());
                        map.put(mapKey.trim(), mapVal.trim());
                    }

                    p.setParameter(key, map);
                    break;
                }
                }
            } else {
                p.setParameter(key, value);
            }
        }
    }
}