EWA DEMO emp-script emp-script-utils emp-script-static ffmpeg-utils weixin

更新 com.gdxsoft.easyweb.script.display.items.ItemBase

2016-05-19

package com.gdxsoft.easyweb.script.display.items.ItemBase

将createItemAddHtml 从返回字符串改为返回map对象,原因是要处理AttributeSet中的class参数,原来在html元素上追加一个 class="xxx",这是无效的
现在将class追加到模板 class中,例如 class="xxx IX_SPAN"。

代码段

/**
 * 生成附加的属性 attributeSet, eventSet 在此替换
 * 
 * @param _UserXItem
 * @return
 * @throws Exception
 */
HashMap createItemAddHtml() throws Exception {
    HashMap<String, HashMap<String, String>> sb 
        = new HashMap<String, HashMap<String, String>>();
    ...
    
    for (int i = 0; i < _UserXItem.count(); i++) {
        ...
        MListStr a = Utils.getParameters(html, "@");
        for (int i0 = 0; i0 < _UserXItemValues.count(); i0++) {
            ...
            HashMap<String, String> paras = new HashMap<String, String>();
            boolean ok = false;
            for (int i1 = 0; i1 < a.size(); i1++) {
                ...
                h1 = h1.replace("@" + key, v);
                ok = true;
                paras.put(key, v);
            }
            if (ok) {
                inc++;
                paras.put("---GDX-RST---", h1);
                sb.put(html+inc, paras);
            }
        }
    }

    return sb;
}


/**
 * 获取对象的模板文件
 * 
 * @return
 * @throws Exception
 */
String getXItemFrameHtml() throws Exception {
    ...
    HashMap<String, HashMap<String, String>> addParas = this.createItemAddHtml();
    for (String key : addParas.keySet()) {
        HashMap<String, String> paras = addParas.get(key);
        boolean is_find_class = false;
        if (paras.containsKey("AttName")) {
            String val = paras.get("AttName");
            if (val.trim().equalsIgnoreCase("class")) {
                is_find_class = true;
            }
        }

        if (is_find_class) { // attributeSet 指定了class属性
            String val = paras.get("AttValue").trim();
            if (s1.indexOf(" class=\"") > 0) {
                s1 = s1.replace(" class=\"", " class=\"" + val + " ");
            } else if (s1.indexOf(" class='") > 0) {
                s1 = s1.replace(" class='", " class='" + val + " ");
            }
        } else {
            String val = paras.get("---GDX-RST---").trim();
            sb.append(" " + val);
        }
    }

    ...
}