| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PicBrowserDom |
|
| 8.0;8 |
| 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 | 0 | 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 | 0 | int count = 10; |
| 32 | 0 | if (user != null) |
| 33 | 0 | count = user.getPicBrowserPicsPerPage(); |
| 34 | 0 | Document document = DocumentHelper.createDocument(); |
| 35 | 0 | Element root = document.addElement("PicBrowser"); |
| 36 | 0 | root.addElement("thumbHeight").addText("" + pmf.getDB().getThumbHeight()); |
| 37 | 0 | if (picList == null) |
| 38 | 0 | root.addElement("Count").addText("" + pmf.getDB().getFilterCount()); |
| 39 | else { | |
| 40 | 0 | root.addElement("Count").addText("" + (picList != null ? picList.length : 0)); |
| 41 | 0 | Element pics = DocumentHelper.createElement("Pics"); |
| 42 | try { | |
| 43 | // iter = picList.listIterator(offset); | |
| 44 | 0 | int i = offset; |
| 45 | 0 | while (i < picList.length && --count >= 0) { |
| 46 | //String v = ; | |
| 47 | 0 | Element ele = DocumentHelper.createElement("Pic"); |
| 48 | 0 | ele.addElement("index").addText("" + i); |
| 49 | 0 | ele.addElement("name").addText(picList[i].name); |
| 50 | 0 | if (picList[i].label != null) |
| 51 | 0 | ele.addElement("label").addText(picList[i].label); |
| 52 | 0 | pics.add(ele); |
| 53 | 0 | i++; |
| 54 | 0 | } |
| 55 | 0 | } catch (Exception e) {} |
| 56 | 0 | root.add(pics); |
| 57 | } | |
| 58 | 0 | return document; |
| 59 | } | |
| 60 | ||
| 61 | } | |
| 62 |