帆软报表设计器源代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

83 lines
2.2 KiB

package com.fr.design.mainframe.simple;
import com.fr.json.JSONObject;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
import java.util.HashMap;
import java.util.Map;
/**
* @author Wei
* 一个简单属性(字符串)存储类,用于自定义简单属性的存储
* 如:getInstance("FVSDesignerConfig")可在FineReportEnv.xml中定义一个<FVSDesignerConfig></>存储FVS相关配置
*/
public class SimpleDesignerConfig implements XMLable {
private static final Map<String, SimpleDesignerConfig> configs = new HashMap<>();
private SimpleDesignerConfig(String name) {
this.name = name;
}
public static SimpleDesignerConfig getInstance(String name) {
SimpleDesignerConfig config = configs.get(name);
if (config == null) {
config = new SimpleDesignerConfig(name);
configs.put(name, config);
}
return config;
}
private String name = "";
private JSONObject content = new JSONObject();
public void addAttr(String key, String value) {
content.put(key, value);
}
public JSONObject getContent() {
return content;
}
public void setContent(JSONObject content) {
this.content = content;
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
String rawContent = reader.getAttrAsString("content", null);
if (StringUtils.isNotBlank(rawContent)) {
this.content = new JSONObject(rawContent);
}
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(name);
if (this.content != null) {
writer.attr("content", this.content.toString());
}
writer.end();
}
@Override
public Object clone() throws CloneNotSupportedException {
SimpleDesignerConfig cloned = (SimpleDesignerConfig) super.clone();
if (this.content != null) {
cloned.content = new JSONObject(this.content.toString());
}
cloned.name = this.name;
return cloned;
}
public String getName() {
return name;
}
}