XmlCreator.java
上传用户:damzkj
上传日期:2022-01-07
资源大小:24k
文件大小:2k
- package jxtamessenger.xml;
- import java.util.logging.Logger;
- import jxtamessenger.bean.ChatMessage;
- import jxtamessenger.bean.OfflineMessage;
- import jxtamessenger.bean.OnlineMessage;
- import jxtamessenger.util.MiscUtil;
- import org.dom4j.Document;
- import org.dom4j.DocumentHelper;
- import org.dom4j.Element;
- /**
- * class取bean的全名称
- * Element的名称取bean的属性名称
- * Element的值为String类型
- */
- public class XmlCreator {
- @SuppressWarnings("unused")
- private static final Logger LOG = Logger.getLogger(XmlCreator.class.getName());
-
- public static String createOnlineMessage() {
- Document document = DocumentHelper.createDocument();
- Element root = document.addElement("root").addAttribute("class", OnlineMessage.class.getCanonicalName());
- // TODO: Read user's configuration from property file, For simplicity, here use user's host name instead.
- root.addElement("hostName").addText(MiscUtil.getHostName());
- root.addElement("userName").addText(MiscUtil.getUserName());
- return document.asXML();
- }
-
- public static String createOfflineMessage() {
- Document document = DocumentHelper.createDocument();
- Element root = document.addElement("root").addAttribute("class", OfflineMessage.class.getCanonicalName());
- root.addElement("hostName").addText(MiscUtil.getHostName());
- root.addElement("userName").addText(MiscUtil.getUserName());
-
- return document.asXML();
- }
-
- public static String createChatMessage(String message) {
- Document document = DocumentHelper.createDocument();
- Element root = document.addElement("root").addAttribute("class", ChatMessage.class.getCanonicalName());
- root.addElement("hostName").addText(MiscUtil.getUserName());
- root.addElement("userName").addText(MiscUtil.getHostName());
- // root.addElement("sendUserName").addText(sendUserName);
- // root.addElement("sendHostName").addText(sendHostName);
- root.addElement("message").addText(message);
-
- return document.asXML();
- }
- }