comparison src/java/de/intevation/mxd/utils/MapToXMLUtils.java @ 38:27577294f9ca

Added root element to document and save the filename in the XML tree.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 14 Apr 2011 11:04:59 +0200
parents 7a927921eb6c
children ef7ca23c4233
comparison
equal deleted inserted replaced
37:c14a92c7628d 38:27577294f9ca
19 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 19 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
20 */ 20 */
21 public class MapToXMLUtils 21 public class MapToXMLUtils
22 { 22 {
23 private Document root; 23 private Document root;
24 private Element rootElement;
24 private XMLUtils.ElementCreator creator; 25 private XMLUtils.ElementCreator creator;
25 26
26 public MapToXMLUtils() { 27 public MapToXMLUtils() {
27 this.root = XMLUtils.newDocument(); 28 this.root = XMLUtils.newDocument();
28 creator = new XMLUtils.ElementCreator(root, "", ""); 29 creator = new XMLUtils.ElementCreator(root, "", "");
30 rootElement = creator.create("mxd");
31 root.appendChild(rootElement);
32 }
33
34 public boolean addFilename(String path) {
35 Element file = creator.create("file");
36 file.setAttribute("name", path);
37 rootElement.appendChild(file);
38 return true;
29 } 39 }
30 40
31 /** 41 /**
32 * Create the top level map element. 42 * Create the top level map element.
33 * 43 *
37 throws Exception { 47 throws Exception {
38 Element map; 48 Element map;
39 NodeList list = root.getElementsByTagName("map"); 49 NodeList list = root.getElementsByTagName("map");
40 if(list == null || list.getLength() == 0){ 50 if(list == null || list.getLength() == 0){
41 map = creator.create("map"); 51 map = creator.create("map");
42 root.appendChild(map); 52 rootElement.appendChild(map);
43 } 53 }
44 else if(list.getLength() == 1){ 54 else if(list.getLength() == 1){
45 map = (Element)list.item(0); 55 map = (Element)list.item(0);
46 } 56 }
47 else{ 57 else{
98 * Print out the XML document. 108 * Print out the XML document.
99 */ 109 */
100 public void print() { 110 public void print() {
101 XMLUtils.toStream(root, System.out); 111 XMLUtils.toStream(root, System.out);
102 } 112 }
113
114 public Document getDocument() {
115 return root;
116 }
103 } 117 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)