View Javadoc
1   /******************************************************************************
2    * PicsInContactDom.java - XML Chains 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.ArrayList;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
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.Contact;
20  
21  public class PicsInContactDom {
22  	protected final static Log log = LogFactory.getLog(PicsInContactDom.class);
23  	/** Create a DOM of the Pics in this Contact
24  	 * @param pmf The PicMan Facade
25  	 * @param cid chainId
26  	 * @param contactName Name of this Contact i.e. "mlbM_100_01"
27  	 * @return The DOM
28  	 */
29  	static public Document createDocument(PicManFacade pmf, int cid, String contactName) {
30  		Document document = DocumentHelper.createDocument();
31  		Element root = document.addElement("PicsInContact");
32  		log.debug("cid=" + cid + " name='" + contactName + "'");
33  		Contact c = pmf.getDB().getContact(cid, contactName);
34  		int rowcount = c.getRowCount();
35  		root.addElement("rowCount").addText("" + rowcount);
36  		Element pics = DocumentHelper.createElement("Pics");
37  		ArrayList<ArrayList<String>> aapics = c.getPics();
38  		for (int row=0; row<aapics.size(); row++) {
39  			ArrayList<String> arow = aapics.get(row);
40  			for (int col=0; col<arow.size(); col++) {
41  				Element ele = DocumentHelper.createElement("Pic");
42  				ele.addElement("row").addText(((Integer)row).toString());
43  				ele.addElement("col").addText(((Integer)col).toString());
44  				ele.addElement("name").addText(arow.get(col));
45  				pics.add(ele);
46  			}
47  		}
48  		root.add(pics);
49  		return document;
50  	}
51  
52  
53  }