annotate src/java/de/intevation/mxd/utils/MapToXMLUtils.java @ 108:3c58c07cee6b

added hints for connecting to ArcSDE
author Stephan Holl <stephan.holl@intevation.de>
date Tue, 14 Jun 2011 12:35:36 +0200
parents ef7ca23c4233
children 6b80d2c7536e
rev   line source
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 /*
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 *
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 * Read the file LGPL.txt coming with the software for details
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 */
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 package de.intevation.mxd.utils;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import org.apache.log4j.Logger;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import org.w3c.dom.Document;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import org.w3c.dom.Element;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import org.w3c.dom.NodeList;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 /**
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 * Utility class to store map information in a XML structure.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 *
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 */
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 public class MapToXMLUtils
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 {
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
23 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
24 * The logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
25 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
26 private static final Logger logger = Logger.getLogger(MapToXMLUtils.class);
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
27
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
28 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
29 * Private member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
30 */
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 private Document root;
38
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
32 private Element rootElement;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 private XMLUtils.ElementCreator creator;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
35
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 public MapToXMLUtils() {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 this.root = XMLUtils.newDocument();
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 creator = new XMLUtils.ElementCreator(root, "", "");
38
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
39 rootElement = creator.create("mxd");
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
40 root.appendChild(rootElement);
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
41 }
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
42
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
43 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
44 * Add the mxd filename to the dom.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
45 * @param path Path to the mxdfile.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
46 * @return Currently always true.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
47 */
38
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
48 public boolean addFilename(String path) {
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
49 Element file = creator.create("file");
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
50 file.setAttribute("name", path);
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
51 rootElement.appendChild(file);
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
52 return true;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 /**
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 * Create the top level map element.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 * @return The new map element.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 */
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 public Element createMap()
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 throws Exception {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 Element map;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 NodeList list = root.getElementsByTagName("map");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 if(list == null || list.getLength() == 0){
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 map = creator.create("map");
38
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
65 rootElement.appendChild(map);
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 else if(list.getLength() == 1){
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 map = (Element)list.item(0);
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 else{
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 throw new Exception("Error while creating map node.");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 return map;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 /**
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 * Add a layer element to the map.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 * @param name The layer name.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 * @return The layer element.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 */
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 public Element addLayer()
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 throws Exception {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 Element node = creator.create("layer");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 NodeList list = root.getElementsByTagName("map");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 if(list == null || list.getLength() == 0){
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 throw new Exception("No map node found!");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 else if(list.getLength() > 1) {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 throw new Exception("Found more than one map node." +
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 " This should never happen!");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 else {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 list.item(0).appendChild(node);
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 return node;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 /**
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 * Add a renderer element to the map.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 * @param layer The parent layer element.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101 * @return The renderer element.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102 */
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 public Element addRenderer(Element layer) {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 Element node = creator.create("renderer");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 layer.appendChild(node);
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 return node;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 /**
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 * Add a symbol element to the map.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 * @param renderer The parent renderer element.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 * @return The symbol element.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 */
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 public Element addSymbol(Element renderer) {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 Element node = creator.create("symbol");
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 renderer.appendChild(node);
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 return node;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 /**
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 * Print out the XML document.
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 */
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 public void print() {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 XMLUtils.toStream(root, System.out);
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 }
38
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
126
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
127 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
128 * Get the DOM document.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
129 * @return The root document.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 38
diff changeset
130 */
38
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
131 public Document getDocument() {
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
132 return root;
27577294f9ca Added root element to document and save the filename in the XML tree.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
133 }
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)