View Javadoc
1   /******************************************************************************
2    * RootsDom.java - XML Sets for PicMan's Roots
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.Iterator;
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.Root;
19  
20  /** Fetch the Roots as a DOM
21   * @author Dick Balaska
22   */
23  public class RootsDom {
24  	static public Document createDocument(PicManFacade pmf) {
25  		Document document = DocumentHelper.createDocument();
26  		Element root = document.addElement("PicManRoots");
27  		List<Root> roots = pmf.getDB().getRoots();
28  		Iterator<Root> iter = roots.iterator();
29  		while (iter.hasNext()) {
30  			Root r = iter.next();
31  			root.add(getRootElement(r));
32  		}
33  		return document;
34  	}
35  
36  	static public Element getRootElement(Root r) {
37  		Element ele = DocumentHelper.createElement("Root");
38  		ele.addElement("name").addText(r.getName());
39  		ele.addElement("rid").addText("" + r.getRid());
40  		ele.addElement("path").addText(r.getPath());
41  		ele.addElement("prefix").addText(r.getFilePrefix());
42  		ele.addElement("active").addText(((Boolean)r.isActive()).toString());
43  		return(ele);
44  	}
45  
46  }