1
2
3
4
5
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
20
21
22
23
24 public class PicBrowserDom {
25
26
27
28
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
44 int i = offset;
45 while (i < picList.length && --count >= 0) {
46
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