annotate src/java/de/intevation/mxd/reader/FeatureLayerReader.java @ 29:77cfa8092611

Write FeatureLayer attributes to XML document.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 08 Apr 2011 17:36:22 +0200
parents 3e24fffdf2bb
children 40c0b4e5f91a
rev   line source
26
3e24fffdf2bb Moved reader components to reader folder.
Raimund Renkert <rrenkert@intevation.de>
parents: 25
diff changeset
1 //package de.intevation.mxd.reader;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import java.io.IOException;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 import com.esri.arcgis.carto.ILayer;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 import com.esri.arcgis.carto.FeatureLayer;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import com.esri.arcgis.geometry.ISpatialReference;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import com.esri.arcgis.geometry.IProjection;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import com.esri.arcgis.geometry.Projection;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import com.esri.arcgis.display.ISymbol;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import com.esri.arcgis.display.SimpleMarkerSymbol;
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
15
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
16 import org.w3c.dom.Attr;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
17 import org.w3c.dom.Document;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
18 import org.w3c.dom.Element;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
19 import org.w3c.dom.Node;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
20 import org.w3c.dom.NodeList;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
21
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 /**
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 * Reads Layer information..
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 *
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 public class FeatureLayerReader implements ILayerReader{
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
31 private FeatureLayer layer;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
32 private Document document;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 //Constructor
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
35 public FeatureLayerReader(ILayer layer) throws Exception{
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
36 if(layer instanceof FeatureLayer)
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
37 this.layer = (FeatureLayer)layer;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
38 else
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
39 throw new Exception("Not an instance of FeatureLayer: " +
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
40 layer.getClass().toString());
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 //Methods
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 /**
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
45 * Setter for XML document.
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
46 */
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
47 public void setDocument(Document doc){
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
48 this.document = doc;
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
49 }
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
50
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
51 /**
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 * Reads the Layer content.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 public boolean read() throws IOException{
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 logger.debug("read()");
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
56 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document,
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
57 "", "");
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
59 Element layerElement = creator.create("layer");
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
60 creator.addAttr(layerElement, "name", layer.getName());
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
61 creator.addAttr(layerElement,
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
62 "min_scale",
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
63 String.valueOf(layer.getMinimumScale()));
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
64 creator.addAttr(layerElement,
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
65 "max_scale",
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
66 String.valueOf(layer.getMaximumScale()));
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
67 if(layer.isVisible())
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
68 creator.addAttr(layerElement, "status", "on");
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
69 else
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
70 creator.addAttr(layerElement, "status", "off");
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
71 creator.addAttr(layerElement,
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
72 "definition_query",
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
73 layer.getDefinitionExpression());
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
74 NodeList list = document.getElementsByTagName("map");
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
75 if(list.getLength() > 1){
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
76 throw new IOException("Error while creating DOM! Found" +
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
77 " more than one map object!");
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 else{
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
80 Node map = list.item(0);
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
81 map.appendChild(layerElement);
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 }
29
77cfa8092611 Write FeatureLayer attributes to XML document.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
83 return true;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 public void getLayer() throws IOException{
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 logger.debug("getLayer() -> not implemented jet.");
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 return;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)