/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.httpclient.NameValuePair
 *  org.apache.commons.httpclient.methods.PostMethod
 *  org.apache.commons.lang3.StringUtils
 */
package com.hst.httpclient;

import com.hst.framework.util.HstToolsUtil;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.lang3.StringUtils;

public class HttpClientCommon {
    public static PostMethod szrsLoginPostMethod(String czryDm, String passWord, String url) throws Exception {
        PostMethod loginPost = new PostMethod(url);
        NameValuePair userid = new NameValuePair("userName", czryDm);
        NameValuePair password = new NameValuePair("password", passWord);
        NameValuePair state = new NameValuePair("state", "login");
        loginPost.setRequestBody(new NameValuePair[]{userid, password, state});
        loginPost.setRequestHeader("Connection", "close");
        return loginPost;
    }

    public static PostMethod postMethodInstance(String url, Map<String, String> map) throws Exception {
        PostMethod post = new PostMethod(url);
        NameValuePair[] arr = null;
        if (map != null && !map.isEmpty()) {
            arr = new NameValuePair[map.size()];
            NameValuePair obj = null;
            int i = 0;
            for (String key : map.keySet()) {
                obj = new NameValuePair();
                obj.setName(key);
                obj.setValue(map.get(key));
                arr[i++] = obj;
            }
            obj = null;
        }
        post.setRequestBody(arr);
        post.setRequestHeader("Connection", "close");
        return post;
    }

    public static Map<String, String> parseSzrsGzjsHtml(String context) throws Exception {
        HashMap<String, String> map = new HashMap<String, String>();
        if (HstToolsUtil.isNullOrEmpty(context)) {
            return map;
        }
        String start = "onmousedown=\"myFunction(";
        String end = "')\"><div style";
        String[] arr = StringUtils.substringsBetween((String)context, (String)start, (String)end);
        if (arr == null || arr.length == 0) {
            return map;
        }
        int i = 0;
        while (i < arr.length) {
            int num;
            String url = arr[i];
            System.out.println(url);
            if (!HstToolsUtil.isNullOrEmpty(url) && (num = url.indexOf("&date=")) >= 0) {
                String key = url.substring(num + 6);
                map.put(key, url);
            }
            ++i;
        }
        return map;
    }

    public static PostMethod getSavePostMethod(String url, String nd, String yf, String skey, String gzjsVO_c_zs_zt, String gzjsVO_c_oid, String gzjsVO_c_gzjs, String _previous_url_, String dateString2, String dateString) {
        PostMethod savePost = new PostMethod(url);
        NameValuePair nv_nd = new NameValuePair("nd", nd);
        NameValuePair nv_yf = new NameValuePair("yf", yf);
        NameValuePair state = new NameValuePair("state", "saveGzjs");
        NameValuePair nv_skey = new NameValuePair("skey", "abc");
        NameValuePair nv_gzjsVO_c_zs_zt = new NameValuePair("gzjsVO.c_zs_zt", gzjsVO_c_zs_zt);
        NameValuePair nv_gzjsVO_c_oid = new NameValuePair("gzjsVO.c_oid", gzjsVO_c_oid);
        NameValuePair nv_gzjsVO_c_gzjs = new NameValuePair("gzjsVO.c_gzjs", gzjsVO_c_gzjs);
        NameValuePair nv_previous_url_ = new NameValuePair("_previous_url_", _previous_url_);
        NameValuePair nv_dateString2 = new NameValuePair("dateString2", dateString2);
        NameValuePair nv_dateString = new NameValuePair("dateString", dateString);
        savePost.setRequestBody(new NameValuePair[]{nv_nd, nv_yf, state, nv_skey, nv_gzjsVO_c_zs_zt, nv_gzjsVO_c_oid, nv_gzjsVO_c_gzjs, nv_previous_url_, nv_dateString2, nv_dateString});
        savePost.setRequestHeader("Connection", "close");
        return savePost;
    }
}
