view src/java/de/intevation/mxd/reader/GroupLayerReader.java @ 266:713ea6f42e55

Added missing files and removed libraries.
author Administrator@vbox-server2003.hq.intevation.de
date Thu, 08 Sep 2011 15:54:34 +0200
parents 2cb2f26d0d54
children
line wrap: on
line source
/*
 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
 *
 * This file is part of MXD2map.
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LICENCE.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 *
 * MXD2map has been developed on behalf of the
 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
 * by Intevation GmbH.
 *
 * Authors:
 * Raimund Renkert <raimund.renkert@intevation.de>
 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
 * Stephan Holl <stephan.holl@intevation.de>
 */

package de.intevation.mxd.reader;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.GdbRasterCatalogLayer;
import com.esri.arcgis.carto.IFeatureRenderer;
import com.esri.arcgis.carto.SimpleRenderer;
import com.esri.arcgis.carto.ClassBreaksRenderer;
import com.esri.arcgis.carto.UniqueValueRenderer;
import com.esri.arcgis.carto.GroupLayer;

import org.w3c.dom.Element;

import de.intevation.mxd.utils.MapToXMLUtils;


/**
 * Reads Layer information.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class GroupLayerReader {

    /**
     * The logger.
     */
    private static final Logger logger =
        Logger.getLogger(FeatureLayerReader.class);

    /**
     * Privte member.
     */
    private GroupLayer  layer;
    private MapToXMLUtils util;
    private int invalidLayerCount;

    /**
     * Constructor with layer.
     *
     * @param layer The ArcGIS layer object.
     */
    public GroupLayerReader(ILayer layer)
    throws Exception {
        if(layer instanceof GroupLayer) {
            this.layer = (GroupLayer)layer;
            invalidLayerCount = 0;
        }
        else {
            throw new Exception("Not an instance of GroupLayer: " +
                layer.getClass().toString());
        }
    }

    /**
     * Setter for XML document helper.
     *
     * @param util The helper for storing map information.
     */
    public void setUtil(MapToXMLUtils util) {
        this.util = util;
    }

    /**
     * Reads the Layer content.
     *
     * @return The layer XML element.
     */
    public Element read(String group)
    throws IOException{
        logger.debug("read()");
        Element layerElement = null;
        for(int i = 0; i < layer.getCount();i++) {
            ILayer lay = layer.getLayer(i);
            try {
                if (lay instanceof FeatureLayer) {
                    FeatureLayerReader lr = new FeatureLayerReader(lay);
                    lr.setUtil(util);
                    layerElement = lr.read();
                    if (layerElement == null) {
                        continue;
                    }
                    layerElement.setAttribute("group", group + "/" + layer.getName());
                    IFeatureRenderer renderer =
                        ((FeatureLayer)lay).getRenderer();
                    IRendererReader rreader;
                    if(renderer instanceof SimpleRenderer) {
                        rreader = new SimpleRendererReader(renderer);
                        rreader.setParent(layerElement);
                        rreader.setUtil(util);
                        rreader.read();
                    }
                    else if(renderer instanceof ClassBreaksRenderer) {
                        rreader = new ClassBreakRendererReader(renderer);
                        rreader.setParent(layerElement);
                        rreader.setUtil(util);
                        rreader.read();
                    }
                    else if(renderer instanceof UniqueValueRenderer) {
                        rreader = new UniqueValueRendererReader(renderer);
                        rreader.setParent(layerElement);
                        rreader.setUtil(util);
                        rreader.read();
                    }
                    else{
                        logger.debug("Not a known renderer type " +
                                     renderer.getClass().toString());
                    }
                }
                else if(lay instanceof GdbRasterCatalogLayer) {
                    GdbRasterCatalogLayerReader gclr =
                        new GdbRasterCatalogLayerReader(lay);
                    gclr.setUtil(util);
                    layerElement = gclr.read();
                    layerElement.setAttribute("group", layer.getName());
                    IFeatureRenderer renderer =
                        ((GdbRasterCatalogLayer)lay).getRenderer();
                    IRendererReader rreader;
                    if(renderer instanceof SimpleRenderer) {
                        rreader = new SimpleRendererReader(renderer);
                        rreader.setParent(layerElement);
                        rreader.setUtil(util);
                        rreader.read();
                    }
                    else if(renderer instanceof ClassBreaksRenderer) {
                        rreader = new ClassBreakRendererReader(renderer);
                        rreader.setParent(layerElement);
                        rreader.setUtil(util);
                        rreader.read();
                    }
                    else if(renderer instanceof UniqueValueRenderer) {
                        rreader = new UniqueValueRendererReader(renderer);
                        rreader.setParent(layerElement);
                        rreader.setUtil(util);
                        rreader.read();
                    }
                    else {
                        logger.debug("Not a known renderer type " +
                                     renderer.getClass().toString());
                    }
                }
                else if(lay instanceof GroupLayer) {
                    GroupLayerReader glr = new GroupLayerReader (lay);
                    glr.setUtil(this.util);
                    layerElement = glr.read("/" + layer.getName());
                }
            }
            catch(Exception e) {
                invalidLayerCount++;
                if(i == 0 && (i + 1) == layer.getCount() ||
                    invalidLayerCount == layer.getCount()) {
                    throw new IOException(
                        "No valid layer in MXD file." +
                        " Aborting.");
                }
            }
        }
        return layerElement;
    }
}
// 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)