View Javadoc
1   /******************************************************************************
2    * PicBrowserDom.java - XML for PicMan's Pic Browser
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2009 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.dom;
9   
10  import org.dom4j.Document;
11  import org.dom4j.DocumentHelper;
12  import org.dom4j.Element;
13  
14  import com.buckosoft.PicMan.business.PicManFacade;
15  import com.buckosoft.PicMan.domain.User;
16  import com.buckosoft.PicMan.web.PicBrowserAjaxController;
17  
18  
19  /** XML for PicMan's Pic Browser
20   * @author Dick Balaska
21   * @since 2009/06/03
22   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/dom/VirginsDom.java">VirginsDom.java</a>
23   */
24  public class PicBrowserDom {
25  
26  	/** Create a DOM of a limited number of Pics in our database
27  	 * @param pmf The PicMan Facade
28  	 * @return The DOM
29  	 */
30  	static public Document createDocument(PicManFacade pmf, User user, PicBrowserAjaxController.PicNameWithLabel[] picList, int offset) {
31  		int		count = 10;
32  		if (user != null)
33  			count = user.getPicBrowserPicsPerPage();
34  		Document document = DocumentHelper.createDocument();
35  		Element root = document.addElement("PicBrowser");
36  		root.addElement("thumbHeight").addText("" + pmf.getDB().getThumbHeight());
37  		if (picList == null)
38  			root.addElement("Count").addText("" + pmf.getDB().getFilterCount());
39  		else {
40  			root.addElement("Count").addText("" + (picList != null ? picList.length : 0));
41  			Element pics = DocumentHelper.createElement("Pics");
42  			try {
43  //				iter = picList.listIterator(offset);
44  				int i = offset;
45  				while (i < picList.length && --count >= 0) {
46  					//String v = ;
47  					Element ele = DocumentHelper.createElement("Pic");
48  					ele.addElement("index").addText("" + i);
49  					ele.addElement("name").addText(picList[i].name);
50  					if (picList[i].label != null)
51  						ele.addElement("label").addText(picList[i].label);
52  					pics.add(ele);
53  					i++;
54  				}
55  			} catch (Exception e) {}
56  			root.add(pics);
57  		}
58  		return document;
59  	}
60  
61  }
62