View Javadoc
1   /******************************************************************************
2    * PicsInSetDom.java - XML Sets for PicMan's Editors
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.Pic;
19  import com.buckosoft.PicMan.domain.Set;
20  
21  /** XML for Pics in a Set
22   * @author Dick Balaska
23   * @since 2008/06/01
24   */
25  public class PicsInSetDom {
26  	/** Fetch the {@link com.buckosoft.PicMan.domain.Pic}s in a set.
27  	 * For now, all that we need is the pid and the name of the Pic
28  	 * @param pmf The reference to the PicManFacade
29  	 * @param sid The Set ID to query
30  	 * @param size The size that we want to query.
31  	 * @return A DOM of a List of stripped down Pic.
32  	 */
33  	static public Document createDocument(PicManFacade pmf, int sid, int size) {
34  		Document document = DocumentHelper.createDocument();
35  		Element root = document.addElement("PicsInSet");
36  		Set set = pmf.getDB().getSet(sid);
37  		List<Pic> list = pmf.getDB().getPics(set, size);
38  		Iterator<Pic> iter = list.iterator();
39  		while (iter.hasNext()) {
40  			Pic pic = iter.next();
41  			Element ele = DocumentHelper.createElement("Pic");
42  			ele.addElement("pid").addText(((Integer)pic.getPid()).toString());
43  			ele.addElement("name").addText(pic.getName());
44  			root.add(ele);
45  		}
46  		return document;
47  	}
48  
49  	/** Fetch the number of {@link com.buckosoft.PicMan.domain.Pic}s in a set.
50  	 * @param pmf The reference to the PicManFacade
51  	 * @param setName The name of the Set to query
52  	 * @param size The size that we want to query.
53  	 * @return A DOM with the element "count" which is the number of pics in the set/size specified.
54  	 */
55  	static public Document createDocument(PicManFacade pmf, String setName, int size) {
56  		Document document = DocumentHelper.createDocument();
57  		Element root = document.addElement("PicsInSetCount");
58  		Set set = pmf.getDB().getSet(setName);
59  		List<Pic> list = pmf.getDB().getPics(set, size);
60  		root.addElement("name").addText(set.getName());
61  		root.addElement("sid").addText("" + set.getSid());
62  		root.addElement("size").addText("" + size);
63  		root.addElement("count").addText("" + list.size());
64  		return document;
65  	}
66  }