Skip to content

Commit

Permalink
Merge pull request #95 from chenhengjie123/fix_20210705_fixExportNull…
Browse files Browse the repository at this point in the history
…PointException

fix: 修复导出xmind时,没有 text 属性时会引起空指针问题。以及转码 xml 改为用工具库,避免未考虑周全遗漏转码
  • Loading branch information
gitxiaofeng authored Jul 5, 2021
2 parents e8f9a8a + fd4dfd4 commit 29bc978
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions case-server/src/main/java/com/xiaoju/framework/util/TreeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.xiaoju.framework.constants.enums.ProgressEnum;
import com.xiaoju.framework.entity.xmind.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Element;


Expand Down Expand Up @@ -281,7 +283,11 @@ public static void exportDataToXml(JSONArray children, Element rootTopic) {
.addAttribute("timestamp",dataObj.getString("created"));
Element title = topic.addElement("title");
String text = dataObj.getString("text");
text = repalceSpecialChar(text);
if (StringUtils.isNotEmpty(text)) {
text = StringEscapeUtils.escapeXml11(text);
} else {
text = "";
}
title.setText(text);

String priority = getPriorityByJson(dataObj);
Expand All @@ -296,20 +302,6 @@ public static void exportDataToXml(JSONArray children, Element rootTopic) {
}
}

public static String repalceSpecialChar(String text)
{
Map<String,String> specialChars = new HashMap<>();
specialChars.put("<","&lt;");
specialChars.put(">","&gt;");
specialChars.put("&","&amp;");
for(Map.Entry<String,String> entry:specialChars.entrySet())
{
String key = entry.getKey();
text = text.replace(key,entry.getValue());
}
return text;
}

//根据xmind解压的json文件导入xmind内容
public static void importDataByJson(JSONArray children, JSONObject rootTopic) {
JSONObject rootObj = new JSONObject();
Expand Down

0 comments on commit 29bc978

Please sign in to comment.