aheinecke@301: /* aheinecke@301: * Copyright (c) 2011 by Intevation GmbH, Germany aheinecke@301: * aheinecke@301: * This file is part of MXD2map. aheinecke@301: * aheinecke@301: * This program is free software under the LGPL (>=v2.1) aheinecke@301: * Read the file LICENCE.txt coming with the software for details aheinecke@301: * or visit http://www.gnu.org/licenses/ if it does not exist. aheinecke@301: * aheinecke@301: * MXD2map has been developed on behalf of the aheinecke@301: * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg aheinecke@301: * by Intevation GmbH. aheinecke@301: * aheinecke@301: * Authors: aheinecke@301: * Raimund Renkert aheinecke@301: * Bjoern Schilberg aheinecke@301: * Stephan Holl aheinecke@301: */ aheinecke@301: aheinecke@301: package de.intevation.mxd.reader; aheinecke@301: aheinecke@301: import java.io.IOException; aheinecke@301: aheinecke@301: import org.apache.log4j.Logger; aheinecke@301: aheinecke@301: import com.esri.arcgis.carto.ILayer; aheinecke@301: import com.esri.arcgis.carto.IFeatureRenderer; aheinecke@301: import com.esri.arcgis.carto.WMSMapLayer; aheinecke@301: import com.esri.arcgis.carto.WMSGroupLayer; aheinecke@301: import com.esri.arcgis.carto.WMSLayer; aheinecke@301: import com.esri.arcgis.gisclient.IWMSServiceDescription; aheinecke@301: import com.esri.arcgis.geometry.Envelope; aheinecke@301: aheinecke@301: import org.w3c.dom.Element; aheinecke@301: aheinecke@301: import de.intevation.mxd.utils.MapToXMLUtils; aheinecke@301: aheinecke@301: aheinecke@301: /** aheinecke@301: * Reads Layer information. aheinecke@301: * aheinecke@301: * @author Andre Heinecke aheinecke@301: */ aheinecke@301: public class WMSMapLayerReader { aheinecke@301: aheinecke@301: /** aheinecke@301: * The logger. aheinecke@301: */ aheinecke@301: private static final Logger logger = aheinecke@301: Logger.getLogger(FeatureLayerReader.class); aheinecke@301: aheinecke@301: /** aheinecke@301: * Privte member. aheinecke@301: */ aheinecke@301: private WMSMapLayer layer; aheinecke@301: private MapToXMLUtils util; aheinecke@301: private int invalidLayerCount; aheinecke@301: aheinecke@301: /** aheinecke@301: * Constructor with layer. aheinecke@301: * aheinecke@301: * @param layer The ArcGIS layer object. aheinecke@301: */ aheinecke@301: public WMSMapLayerReader(ILayer layer) aheinecke@301: throws Exception { aheinecke@301: if(layer instanceof WMSMapLayer) { aheinecke@301: this.layer = (WMSMapLayer)layer; aheinecke@301: invalidLayerCount = 0; aheinecke@301: } aheinecke@301: else { aheinecke@301: throw new Exception("Not an instance of WMSMapLayer: " + aheinecke@301: layer.getClass().toString()); aheinecke@301: } aheinecke@301: } aheinecke@301: aheinecke@301: /** aheinecke@301: * Setter for XML document helper. aheinecke@301: * aheinecke@301: * @param util The helper for storing map information. aheinecke@301: */ aheinecke@301: public void setUtil(MapToXMLUtils util) { aheinecke@301: this.util = util; aheinecke@301: } aheinecke@301: aheinecke@301: /** aheinecke@301: * Reads the Layer content. aheinecke@301: * aheinecke@301: * @return The layer XML element. aheinecke@301: */ aheinecke@301: public Element read(String group) aheinecke@301: throws IOException{ aheinecke@301: logger.debug("read()"); aheinecke@301: Element layerElement = null; aheinecke@301: for(int i = 0; i < layer.getCount();i++) { aheinecke@301: try { aheinecke@301: ILayer lay = layer.getLayer(i); aheinecke@301: logger.debug("Stepping down into sublayer " + i + " Name: " + lay.getName()); aheinecke@301: logger.debug("Class is: " + lay.getClass().toString()); aheinecke@301: if(lay instanceof WMSMapLayer) { aheinecke@301: WMSMapLayerReader lr = new WMSMapLayerReader (lay); aheinecke@301: lr.setUtil(this.util); aheinecke@301: layerElement = lr.read("/" + layer.getName()); aheinecke@301: } else if(lay instanceof WMSGroupLayer) { aheinecke@301: WMSGroupLayerReader lr = new WMSGroupLayerReader (lay); aheinecke@301: lr.setUtil(this.util); aheinecke@301: layerElement = lr.read("/" + layer.getName()); aheinecke@301: } else if(lay instanceof WMSLayer) { aheinecke@301: WMSLayerReader lr = new WMSLayerReader (lay); aheinecke@301: lr.setUtil(this.util); aheinecke@301: layerElement = lr.read(); aheinecke@301: } else { aheinecke@301: logger.error("Sublayer not handled: " + lay.getClass().toString()); aheinecke@301: } aheinecke@301: if (layerElement != null) { aheinecke@301: layerElement.setAttribute("group", group + "/" + layer.getName()); aheinecke@301: } aheinecke@301: } aheinecke@301: catch(Exception e) { aheinecke@301: logger.debug(e); aheinecke@301: logger.error("Error reading sublayers. Stop reading: " + layer.getName()); aheinecke@301: } aheinecke@301: } aheinecke@301: return layerElement; aheinecke@301: } aheinecke@301: } aheinecke@301: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :