package com.zving.dynamic.tag;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import com.zving.dynamic.DynamicPlugin;
import com.zving.framework.collection.Mapx;
import com.zving.framework.template.AbstractTag;
import com.zving.framework.template.TagAttr;
import com.zving.framework.template.exception.TemplateRuntimeException;
import com.zving.framework.utility.StringUtil;
import com.zving.platform.util.CodeCache;
import com.zving.schema.ZDCode;
public class CodeDataTag extends AbstractTag {
protected String code;
protected String varCode;
protected String varList;
@Override
public String getDescription() {
return "代码项数据";
}
@Override
public String getExtendItemName() {
return "代码项数据";
}
@Override
public String getPluginID() {
return DynamicPlugin.ID;
}
@Override
public String getPrefix() {
return "z";
}
@Override
public List<TagAttr> getTagAttrs() {
List<TagAttr> list = new ArrayList<TagAttr>();
list.add(new TagAttr("code", true));
list.add(new TagAttr("varCode"));
list.add(new TagAttr("varList"));
return list;
}
@Override
public String getTagName() {
return "code";
}
@Override
public int doStartTag() throws TemplateRuntimeException {
if (StringUtil.isEmpty(varCode)) {
varCode = "CodeBean";
}
if (StringUtil.isEmpty(varList)) {
varList = "CodeList";
}
Mapx<String, ZDCode> map = CodeCache.getMapx(code);
ZDCode bean = map.remove("System");
List<ZDCode> list = new ArrayList<ZDCode>(map.size());
for (Entry<String, ZDCode> entry : map.entrySet()) {
list.add(entry.getValue());
}
Collections.sort(list, new Comparator<ZDCode>() {
@Override
public int compare(ZDCode o1, ZDCode o2) {
return new Long(o1.getCodeOrder()).compareTo(o2.getCodeOrder());
}
});
context.addDataVariable(varCode, bean);
context.addDataVariable(varList, list);
return EVAL_BODY_INCLUDE;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getVarCode() {
return varCode;
}
public void setVarCode(String varCode) {
this.varCode = varCode;
}
public String getVarList() {
return varList;
}
public void setVarList(String varList) {
this.varList = varList;
}
}
所有评论仅代表网友意见