📄 topicxml.java
字号:
package com.italk.ui;
import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import com.italk.util.StringUtil;
import com.italk.vo.AdvanceInfo;
import com.italk.vo.Topic;
public class TopicXML {
public static Logger log = Logger.getLogger("italk");
public Document getReplyList(List list, int total) {
log.debug("begin generate reply xml");
Iterator it = list.iterator();
Document document = DocumentHelper.createDocument();
Element dataSet = document.addElement("dataSet");
Element totalRecord = dataSet.addElement("totalRecord");
totalRecord.addText(total + "");
while (it.hasNext()) {
Topic t = (Topic) it.next();
Element row = dataSet.addElement("row");
Element id = row.addElement("id");
Element title = row.addElement("title");
Element publishTime = row.addElement("publishTime");
Element anthor = row.addElement("anthor");
Element content = row.addElement("content");
Element lock = row.addElement("lock");
Element prime = row.addElement("prime");
Element top = row.addElement("top");
Element photo = row.addElement("photo");
Element nickName = row.addElement("nickName");
Element realName = row.addElement("realName");
Element registerTime = row.addElement("registerTime");
Element description = row.addElement("description");
id.addText(t.getId() + "");
title.addCDATA(t.getTitle());
publishTime.addText(StringUtil.dateToFullLocalString(new Timestamp(
t.getPublishTime().longValue())));
anthor.addText(t.getUser().getBaseInfo().getUserName());
content.addCDATA(t.getContent());
lock.setText(t.isLock() + "");
prime.setText(t.isPrime() + "");
top.setText(t.isTop() + "");
AdvanceInfo ai = t.getUser().getAdvanceInfo();
if (ai != null && ai.getNickName() != null) {
nickName.addText(t.getUser().getAdvanceInfo().getNickName());
} else {
nickName.addText("-");
}
if (ai != null && ai.getRealName() != null) {
realName.addText(t.getUser().getAdvanceInfo().getRealName());
} else {
realName.addText("-");
}
registerTime.addText(StringUtil
.dateToSimpleLocalString(new Timestamp(t.getUser()
.getBaseInfo().getRegisterTime().longValue())));
if (ai != null && ai.getDescription() != null) {
description.addText(t.getUser().getAdvanceInfo()
.getDescription());
} else {
description.addText("-");
}
if (ai != null && ai.getPhoto() != null && ai.getPhoto().length>1) {
photo.addText(t.getUser().getBaseInfo().getUserName());
} else {
photo.addText("default");
}
}
return document;
}
public Document getSimpleTopic(List list, int total) {
log.debug("begin generate topic xml");
Iterator it = list.iterator();
Document document = DocumentHelper.createDocument();
Element dataSet = document.addElement("dataSet");
Element totalRecord = dataSet.addElement("totalRecord");
totalRecord.addText(total + "");
log.debug("add totalRecord element");
while (it.hasNext()) {
Topic t = (Topic) it.next();
Element row = dataSet.addElement("row");
Element id = row.addElement("id");
Element top = row.addElement("top");
Element prime = row.addElement("prime");
Element lock = row.addElement("lock");
Element title = row.addElement("title");
Element anthor = row.addElement("anthor");
Element publishTime = row.addElement("publishTime");
Element reply = row.addElement("reply");
Element lastUpdateTime = row.addElement("lastUpdateTime");
Element clickCount = row.addElement("clickCount");
id.addText(t.getId() + "");
top.addText(t.isTop() + "");
prime.addText(t.isPrime() + "");
lock.addText(t.isLock() + "");
title.addCDATA(t.getTitle());
anthor.addText(t.getUser().getBaseInfo().getUserName());
publishTime.addText(StringUtil.dateToFullLocalString(new Timestamp(
t.getPublishTime().longValue())));
reply.addText(t.getReplys().size() + "");
if (t.getLastUpdateTime() != null && t.getLastUpdateTime().longValue() != 0) {
lastUpdateTime.addText(StringUtil
.dateToFullLocalString(new Timestamp(t
.getLastUpdateTime().longValue())));
} else {
lastUpdateTime.addText("");
}
clickCount.addText(t.getClickCount() + "");
}
log.debug("end generate topic xml");
return document;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -