rrenkert@243: /* rrenkert@243: * Copyright (c) 2011 by Intevation GmbH, Germany rrenkert@243: * rrenkert@243: * This file is part of MXD2map. rrenkert@243: * rrenkert@243: * This program is free software under the LGPL (>=v2.1) rrenkert@243: * Read the file LICENCE.txt coming with the software for details rrenkert@243: * or visit http://www.gnu.org/licenses/ if it does not exist. rrenkert@243: * rrenkert@243: * MXD2map has been developed on behalf of the rrenkert@243: * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg rrenkert@243: * by Intevation GmbH. rrenkert@243: * rrenkert@243: * Authors: rrenkert@243: * Raimund Renkert rrenkert@243: * Bjoern Schilberg rrenkert@243: * Stephan Holl rrenkert@243: */ rrenkert@243: raimund@179: package de.intevation.mxd.reader; raimund@179: raimund@179: import org.apache.log4j.Logger; raimund@179: raimund@179: import com.esri.arcgis.carto.ILayer; raimund@179: import com.esri.arcgis.carto.FeatureLayer; raimund@179: import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection; raimund@179: import com.esri.arcgis.carto.IAnnotateLayerProperties; raimund@179: import com.esri.arcgis.carto.LabelEngineLayerProperties; raimund@179: import com.esri.arcgis.geodatabase.FeatureClassName; raimund@179: import com.esri.arcgis.system.IName; raimund@179: import com.esri.arcgis.system.IPropertySet; raimund@179: import com.esri.arcgis.display.ITextSymbol; raimund@179: import com.esri.arcgis.display.TextSymbol; raimund@179: raimund@179: import org.w3c.dom.Element; raimund@179: raimund@179: import de.intevation.mxd.utils.MapToXMLUtils; raimund@179: import java.io.IOException; raimund@179: import com.esri.arcgis.interop.AutomationException; raimund@179: /** raimund@179: * Reads Label information. raimund@179: * raimund@179: * @author Raimund Renkert raimund@179: */ raimund@179: public class LabelEngineReader { raimund@179: raimund@179: /** raimund@179: * The logger. raimund@179: */ raimund@179: private static final Logger logger = raimund@179: Logger.getLogger(LabelEngineReader.class); raimund@179: raimund@179: /** raimund@179: * Privte member. raimund@179: */ raimund@179: private LabelEngineLayerProperties properties; raimund@179: private MapToXMLUtils util; raimund@179: private Element parent; raimund@179: rrenkert@181: /** rrenkert@181: * Constructor with annotation properties. rrenkert@181: * rrenkert@181: * @param prop The annotation properties object. rrenkert@181: */ raimund@179: public LabelEngineReader(IAnnotateLayerProperties prop) raimund@179: throws Exception { raimund@179: if(prop instanceof LabelEngineLayerProperties) { raimund@179: this.properties = (LabelEngineLayerProperties)prop; raimund@179: } raimund@179: else { rrenkert@180: throw new Exception("Not an instance of" + rrenkert@180: " LaberEngineLayerProperties: " + rrenkert@180: prop.getClass().toString()); raimund@179: } raimund@179: } raimund@179: raimund@179: /** raimund@179: * Setter for XML document helper. raimund@179: * raimund@179: * @param util The helper for storing map information. raimund@179: */ raimund@179: public void setUtil(MapToXMLUtils util) { raimund@179: this.util = util; raimund@179: } raimund@179: rrenkert@181: /** rrenkert@181: * Setter for the parent DOM element. rrenkert@181: * rrenkert@181: * @param parent The parent DOM element. rrenkert@181: */ raimund@179: public void setParent(Element parent) { rrenkert@180: this.parent = parent; raimund@179: } raimund@179: raimund@179: /** raimund@179: * Reads the Label content. raimund@179: * raimund@179: * @return The label XML element. raimund@179: */ raimund@179: public Element read() raimund@179: throws IOException{ raimund@179: logger.debug("read()"); rrenkert@180: Element labelElement; raimund@179: try { raimund@179: labelElement = util.addLabel(parent); raimund@179: } raimund@179: catch(Exception e) { raimund@179: logger.error("Failed to create DOM-Element for Label."); raimund@179: return null; raimund@179: } raimund@179: rrenkert@180: try { rrenkert@180: labelElement.setAttribute( rrenkert@180: "expression", rrenkert@180: properties.getExpression()); rrenkert@180: } rrenkert@180: catch(IOException ioe) { rrenkert@180: logger.warn("Could not read label expression."); rrenkert@180: return null; rrenkert@180: } raimund@179: raimund@179: try { rrenkert@180: labelElement.setAttribute( raimund@179: "offset", rrenkert@180: String.valueOf(properties.getOffset())); rrenkert@180: } rrenkert@180: catch(IOException ioe) { rrenkert@180: logger.warn("Could not read label offset."); rrenkert@180: } raimund@179: raimund@179: try { rrenkert@180: labelElement.setAttribute( rrenkert@180: "definition_query", rrenkert@180: properties.getWhereClause()); rrenkert@180: } rrenkert@180: catch(IOException ioe) { rrenkert@180: logger.warn("Could not read label where clause."); rrenkert@180: } raimund@179: rrenkert@180: try { rrenkert@180: labelElement.setAttribute( rrenkert@180: "max_scale", rrenkert@180: String.valueOf(properties.getAnnotationMaximumScale())); rrenkert@180: labelElement.setAttribute( rrenkert@180: "min_scale", rrenkert@180: String.valueOf(properties.getAnnotationMinimumScale())); rrenkert@180: } rrenkert@180: catch(IOException ioe) { rrenkert@180: logger.warn("Could not read label scale."); rrenkert@180: } rrenkert@180: rrenkert@180: try { raimund@179: ITextSymbol sym = properties.getSymbol(); rrenkert@180: if(sym instanceof TextSymbol) { rrenkert@180: TextSymbolReader tsr = new TextSymbolReader(sym); rrenkert@180: tsr.setParent(labelElement); rrenkert@180: tsr.setUtil(util); rrenkert@180: tsr.read(); rrenkert@180: } rrenkert@180: } raimund@179: catch(Exception e) { rrenkert@180: logger.warn("Could not read label text symbol."); rrenkert@180: } rrenkert@180: rrenkert@180: return labelElement; raimund@179: } raimund@179: } raimund@179: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :