1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.dom;
9
10 import java.util.Collections;
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.Mosaic;
19 import com.buckosoft.PicMan.domain.Pic;
20 import com.buckosoft.PicMan.domain.Poster;
21
22
23
24
25
26
27 public class PosterSetupDom {
28
29
30
31
32 static public Document createDocument(PicManFacade pmf) {
33 Document document = DocumentHelper.createDocument();
34 Element root = document.addElement("PosterList");
35 List<Poster> list = pmf.getDB().getPosters();
36 Collections.sort(list);
37 for (Poster p : list)
38 addPoster(pmf, p, root);
39 return document;
40 }
41
42
43
44
45
46
47 static public Document createDocument(PicManFacade pmf, int pid) {
48 Document document = DocumentHelper.createDocument();
49 Element root = document.addElement("Poster");
50 Poster p = pmf.getDB().getPoster(pid);
51 addPoster(pmf, p, root);
52 return document;
53 }
54
55 static private void addPoster(PicManFacade pmf, Poster p, Element root) {
56 Element ele = DocumentHelper.createElement("Poster");
57 ele.addElement("pid").addText("" + p.getPid());
58 ele.addElement("name").addText(p.getName());
59 ele.addElement("outPath").addText(p.getOutputPath());
60 ele.addElement("masterMid").addText("" + p.getMasterMid());
61 Mosaic m = pmf.getDB().getMosaic(p.getMasterMid());
62 if (m != null) {
63 Pic pic = pmf.getDB().getPic(m.getMasterPic());
64 if (pic != null) {
65 ele.addElement("picWidth").addText("" + pic.getWidth());
66 ele.addElement("picHeight").addText("" + pic.getHeight());
67 }
68 }
69 Element config = ele.addElement("Config");
70 for (String k : p.getConfig().keySet())
71 config.addElement(k).addText(p.getConfig().get(k));
72 root.add(ele);
73
74 }
75 }