1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.dom;
9
10 import java.util.Iterator;
11 import java.util.List;
12
13 import org.dom4j.Document;
14 import org.dom4j.DocumentHelper;
15 import org.dom4j.Element;
16
17 import com.buckosoft.PicMan.business.PicManFacade;
18 import com.buckosoft.PicMan.domain.SyncLogEntry;
19
20
21
22
23
24
25 public class SyncStatusDom {
26
27 static private int maxSyncCount = 10;
28 static public Document createDocument(PicManFacade pmf) {
29 Document document = DocumentHelper.createDocument();
30 Element root = document.addElement("PicManStatus");
31 root.addElement("syncLogCount").addText("" + (pmf.getSyncLog().size() < maxSyncCount ? pmf.getSyncLog().size() : maxSyncCount));
32 Element ele = root.addElement("JobLog");
33 getSyncLog(pmf, ele);
34
35
36 return document;
37 }
38
39 private static void getSyncLog(PicManFacade pmf, Element ele) {
40 List<SyncLogEntry> sl = pmf.getSyncLog();
41 int i = 0;
42 Iterator<SyncLogEntry> iter = sl.iterator();
43 while (iter.hasNext()) {
44 if (i >= pmf.getSyncLogMaxCount())
45 break;
46 SyncLogEntry sle = iter.next();
47 ele.add(getDomElement(pmf, sle));
48 i++;
49 }
50 }
51
52
53
54
55
56 static private Element getDomElement(PicManFacade pmf, SyncLogEntry sle) {
57 Element ele = DocumentHelper.createElement("SyncLogEntry");
58 ele.addElement("type").addText(sle.getTypeAsString());
59 ele.addElement("name").addText(sle.getName());
60 ele.addElement("color").addText("" + sle.getColor());
61 ele.addElement("startTime").addText(sle.getStartTimeAsString());
62 if (sle.getMessage() != null)
63 ele.addElement("message").addText(sle.getMessage());
64 return(ele);
65 }
66
67 }