View Javadoc
1   /******************************************************************************
2    * MosaicBatchSetupDom.java - XML for Mosaic Batch Setups
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.Collections;
11  import java.util.Iterator;
12  import java.util.List;
13  
14  import org.dom4j.Document;
15  import org.dom4j.DocumentHelper;
16  import org.dom4j.Element;
17  
18  import com.buckosoft.PicMan.business.PicManFacade;
19  import com.buckosoft.PicMan.domain.MosaicBatch;
20  
21  /** XML for Mosaic Setups
22   * @author Dick Balaska
23   * @since 2008/09/19
24   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/dom/MosaicBatchSetupDom.java">MosaicBatchSetupDom.java</a>
25   */
26  public class MosaicBatchSetupDom {
27  	/** Fetch a dom that is a list of Mosaics in the system
28  	 * @param pmf the PicManFacade
29  	 * @return a Document
30  	 */
31  	static public Document createDocument(PicManFacade pmf) {
32  		Document document = DocumentHelper.createDocument();
33  		Element root = document.addElement("MosaicBatchList");
34  		List<MosaicBatch>	list = pmf.getDB().getMosaicBatches();
35  		Collections.sort(list);
36  		Iterator<MosaicBatch> iter = list.iterator();
37  		while (iter.hasNext()) {
38  			MosaicBatch mb = iter.next();
39  			addMosaic(pmf, mb, root);
40  		}
41  		return document;
42  	}
43  
44  	/** Fetch a dom that is a single MosaicBatch
45  	 * @param pmf the PicManFacade
46  	 * @param mbid the MosiacBatch id to fetch
47  	 * @return a Document
48  	 */
49  	static public Document createDocument(PicManFacade pmf, int mbid) {
50  		Document document = DocumentHelper.createDocument();
51  		Element root = document.addElement("Mosaic");
52  		MosaicBatch mb = pmf.getDB().getMosaicBatch(mbid);
53  		addMosaic(pmf, mb, root);
54  		return document;
55  	}
56  
57  	static private void addMosaic(PicManFacade pmf, MosaicBatch mb, Element root) {
58  		Element ele = DocumentHelper.createElement("MosaicBatch");
59  		ele.addElement("mbid").addText("" + mb.getMbid());
60  		ele.addElement("mid").addText("" + mb.getMid());
61  		ele.addElement("name").addText(mb.getName());
62  		ele.addElement("sizes").addText(mb.getSizes());
63  		ele.addElement("engineName").addText(mb.getEngine());
64  		ele.addElement("outPic").addText(mb.getOutPic());
65  		ele.addElement("masterPic").addText(mb.getMasterPic());
66  		ele.addElement("sid").addText("" + mb.getSid());
67  		if (mb.getStartTime() != null)
68  			ele.addElement("startTime").addText("" + mb.getStartTime().getTime());
69  		root.add(ele);
70  
71  	}
72  
73  }