Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/FeatureLayerReader.java @ 31:40c0b4e5f91a
Added utility class to store map attributes.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 11 Apr 2011 16:04:03 +0200 |
parents | 77cfa8092611 |
children | c51376f8e24c |
comparison
equal
deleted
inserted
replaced
30:c34c450edb06 | 31:40c0b4e5f91a |
---|---|
24 * | 24 * |
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
26 */ | 26 */ |
27 public class FeatureLayerReader implements ILayerReader{ | 27 public class FeatureLayerReader implements ILayerReader{ |
28 | 28 |
29 private static final Logger logger = Logger.getLogger(FeatureLayerReader.class); | 29 /** |
30 * The logger. | |
31 */ | |
32 private static final Logger logger = | |
33 Logger.getLogger(FeatureLayerReader.class); | |
30 | 34 |
35 /** | |
36 * Privte member. | |
37 */ | |
31 private FeatureLayer layer; | 38 private FeatureLayer layer; |
32 private Document document; | 39 private MapToXMLUtils util; |
33 | 40 |
34 //Constructor | 41 |
35 public FeatureLayerReader(ILayer layer) throws Exception{ | 42 public FeatureLayerReader(ILayer layer) |
43 throws Exception { | |
36 if(layer instanceof FeatureLayer) | 44 if(layer instanceof FeatureLayer) |
37 this.layer = (FeatureLayer)layer; | 45 this.layer = (FeatureLayer)layer; |
38 else | 46 else |
39 throw new Exception("Not an instance of FeatureLayer: " + | 47 throw new Exception("Not an instance of FeatureLayer: " + |
40 layer.getClass().toString()); | 48 layer.getClass().toString()); |
41 } | 49 } |
42 | 50 |
43 //Methods | |
44 /** | 51 /** |
45 * Setter for XML document. | 52 * Setter for XML document helper. |
53 * | |
54 * @param util The helper for storing map information. | |
46 */ | 55 */ |
47 public void setDocument(Document doc){ | 56 public void setUtil(MapToXMLUtils util){ |
48 this.document = doc; | 57 this.util = util; |
49 } | 58 } |
50 | 59 |
51 /** | 60 /** |
52 * Reads the Layer content. | 61 * Reads the Layer content. |
62 * | |
63 * @return The layer XML element. | |
53 */ | 64 */ |
54 public boolean read() throws IOException{ | 65 public Element read() |
66 throws IOException { | |
55 logger.debug("read()"); | 67 logger.debug("read()"); |
56 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document, | 68 Element layerElement; |
57 "", ""); | 69 try { |
70 layerElement = util.addLayer(); | |
71 } | |
72 catch(Exception e) { | |
73 e.printStackTrace(); | |
74 return null; | |
75 } | |
58 | 76 |
59 Element layerElement = creator.create("layer"); | 77 layerElement.setAttribute("name", layer.getName()); |
60 creator.addAttr(layerElement, "name", layer.getName()); | 78 layerElement.setAttribute("min_scale", |
61 creator.addAttr(layerElement, | 79 String.valueOf(layer.getMinimumScale())); |
62 "min_scale", | 80 layerElement.setAttribute("max_scale", |
63 String.valueOf(layer.getMinimumScale())); | 81 String.valueOf(layer.getMaximumScale())); |
64 creator.addAttr(layerElement, | 82 if(layer.isVisible()) { |
65 "max_scale", | 83 layerElement.setAttribute("status", "on"); |
66 String.valueOf(layer.getMaximumScale())); | |
67 if(layer.isVisible()) | |
68 creator.addAttr(layerElement, "status", "on"); | |
69 else | |
70 creator.addAttr(layerElement, "status", "off"); | |
71 creator.addAttr(layerElement, | |
72 "definition_query", | |
73 layer.getDefinitionExpression()); | |
74 NodeList list = document.getElementsByTagName("map"); | |
75 if(list.getLength() > 1){ | |
76 throw new IOException("Error while creating DOM! Found" + | |
77 " more than one map object!"); | |
78 } | 84 } |
79 else{ | 85 else { |
80 Node map = list.item(0); | 86 layerElement.setAttribute("status", "off"); |
81 map.appendChild(layerElement); | |
82 } | 87 } |
83 return true; | |
84 } | |
85 | 88 |
86 public void getLayer() throws IOException{ | 89 layerElement.setAttribute("definition_query", |
87 logger.debug("getLayer() -> not implemented jet."); | 90 layer.getDefinitionExpression()); |
88 return; | 91 |
92 return layerElement; | |
89 } | 93 } |
90 } | 94 } |
91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |