View Javadoc
1   /******************************************************************************
2    * PicManSetManDom.java - XML Sets for PicMan's SetMan
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2007 - 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.Set;
19  import com.buckosoft.PicMan.domain.User;
20  
21  /** Fetch the Sets as a DOM
22   * @author Dick Balaska
23   * @since 2007/12/21
24   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/dom/SetManDom.java">SetManDom.java</a>
25   */
26  public class SetManDom {
27  	static public Document createDocument(PicManFacade pmf, User user) {
28  		Document document = DocumentHelper.createDocument();
29  		Element root = document.addElement("PicManSetMan");
30  		if (user != null) {
31  			root.addElement("showInactiveSets").addText(((Boolean)user.isSetManShowInactiveSets()).toString());
32  			// convienence because picBrowser doesn't have his own dom.
33  			root.addElement("picBrowserPicsPerPage").addText("" + user.getPicBrowserPicsPerPage());
34  		}
35  		List<Set> sets = pmf.getDB().getSets();
36  		Iterator<Set> iter = sets.iterator();
37  		while (iter.hasNext()) {
38  			Set set = iter.next();
39  			root.add(getSetElement(set));
40  		}
41  		return document;
42  	}
43  
44  	static public Element getSetElement(Set set) {
45  		Element ele = DocumentHelper.createElement("Set");
46  		ele.addElement("sid").addText(((Integer)set.getSid()).toString());
47  		ele.addElement("name").addText("" + set.getName());
48  		ele.addElement("description").addText(set.getDescription() != null ? set.getDescription() : "");
49  		ele.addElement("active").addText(((Boolean)set.isActive()).toString());
50  		ele.addElement("metaSet").addText(((Boolean)set.isMetaSet()).toString());
51  		ele.addElement("microSet").addText(((Boolean)set.isMicroSet()).toString());
52  		ele.addElement("nanoSet").addText(((Boolean)set.isNanoSet()).toString());
53  		return(ele);
54  	}
55  }
56