package cn.cerc.ui.core;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class UrlRecord {
    private String site;
    private String name;
    private String title;
    private String target;
    private Map<String, String> params = new HashMap<>();
    private String hintMsg;
    private String id;
    private String imgage;
    private String arrow;

    public UrlRecord() {
    }

    public UrlRecord(String site, String name) {
        super();
        this.site = site;
        this.name = name;
    }

    @Deprecated // 请改为 putParam
    public UrlRecord addParam(String key, String value) {
        return putParam(key, value);
    }

    public UrlRecord putParam(String key, String value) {
        params.put(key, value);
        return this;
    }

    public String getSite() {
        return site;
    }

    public UrlRecord setSite(String site) {
        this.site = site;
        return this;
    }

    public UrlRecord setSite(String format, Object... args) {
        this.site = String.format(format, args);
        return this;
    }

    public String getName() {
        return name;
    }

    public UrlRecord setName(String name) {
        this.name = name;
        return this;
    }

    /**
     * @return 请改为getName
     */
    @Deprecated
    public String getCaption() {
        return name;
    }

    public String getUrl() {
        StringBuilder sl = new StringBuilder();
        if (site != null)
            sl.append(site);

        int i = 0;
        for (String key : params.keySet()) {
            i++;
            sl.append(i == 1 ? "?" : "&");
            sl.append(key);
            sl.append("=");
            String value = params.get(key);
            if (value != null)
                sl.append(encodeUTF8(value));
        }
        return sl.toString();
    }

    private String encodeUTF8(String value) {
        try {
            return URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return value;
        }
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTarget() {
        return target;
    }

    public UrlRecord setTarget(String target) {
        this.target = target;
        return this;
    }

    public String getHintMsg() {
        return hintMsg;
    }

    public void setHintMsg(String hintMsg) {
        this.hintMsg = hintMsg;
    }

    public String getId() {
        return id;
    }

    public UrlRecord setId(String id) {
        this.id = id;
        return this;
    }

    public String getImgage() {
        return imgage;
    }

    public UrlRecord setImgage(String imgage) {
        this.imgage = imgage;
        return this;
    }

    public String getArrow() {
        return arrow;
    }

    public UrlRecord setArrow(String arrow) {
        this.arrow = arrow;
        return this;
    }
}

@@ -593,142 +593,8 @@
  %7D%0A%0A
-    @Deprecated // %E8%AF%B7%E6%94%B9%E4%B8%BA putParam%0A    public UrlRecord addParam(String key, String value) %7B%0A        return putParam(key, value);%0A    %7D%0A%0A
     

Update UrlRecord.java