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: 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 { raimund@179: throw new Exception("Not an instance of LaberEngineLayerProperties: " + raimund@179: 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: raimund@179: public void setParent(Element parent) { raimund@179: this.parent = parent; raimund@179: } raimund@179: 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()"); raimund@179: 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: raimund@179: try { raimund@179: labelElement.setAttribute("expression", properties.getExpression()); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read label expression."); raimund@179: return null; raimund@179: } raimund@179: raimund@179: try { raimund@179: labelElement.setAttribute( raimund@179: "offset", raimund@179: String.valueOf(properties.getOffset())); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read label offset."); raimund@179: } raimund@179: raimund@179: try { raimund@179: labelElement.setAttribute( raimund@179: "definition_query", raimund@179: properties.getWhereClause()); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read label where clause."); raimund@179: } raimund@179: raimund@179: try { raimund@179: labelElement.setAttribute( raimund@179: "max_scale", raimund@179: String.valueOf(properties.getAnnotationMaximumScale())); raimund@179: labelElement.setAttribute( raimund@179: "min_scale", raimund@179: String.valueOf(properties.getAnnotationMinimumScale())); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read label scale."); raimund@179: } raimund@179: raimund@179: try { raimund@179: ITextSymbol sym = properties.getSymbol(); raimund@179: if(sym instanceof TextSymbol) { raimund@179: TextSymbolReader tsr = new TextSymbolReader(sym); raimund@179: tsr.setParent(labelElement); raimund@179: tsr.setUtil(util); raimund@179: tsr.read(); raimund@179: } raimund@179: } raimund@179: catch(Exception e) { raimund@179: logger.warn("Could not read label text symbol."); raimund@179: } raimund@179: raimund@179: return labelElement; raimund@179: } raimund@179: } raimund@179: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :