View Javadoc
1   /******************************************************************************
2    * SyncLogEntryDom.java - XML for Sync Status for PicMan
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2008 - Dick Balaska
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  /** XML for Sync Logs
21   * @author Dick Balaska
22   * @since 2007/12/01
23   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/dom/SyncLogEntryDom.java">SyncLogEntryDom.java</a>
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  //		getNewestContactElement(pmf, root);
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  	/** Return a {@link SyncLogEntry} as a DOM Element
52  	 * @param pmf The PicMan Facade
53  	 * @param sle The {@link SyncLogEntry} to convert
54  	 * @return A DOM Element
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  }