diff src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 181:0bde090506f9

Added comments.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 11 Jul 2011 14:28:38 +0200
parents f4eb506499f5
children 1391f911ee39
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Jul 11 12:11:08 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Jul 11 14:28:38 2011 +0200
@@ -52,11 +52,23 @@
     private String prefix = "";
     private MS_UNITS units = MS_UNITS.MS_METERS;
 
+    /**
+     * Default constructor.
+     * Creates a mapscript writer object with an empty map.
+     */
     public MapScriptWriter() {
         map = new mapObj("");
         mapFilename = "";
     }
 
+    /**
+     * Contructor with template and output filename.
+     * Creates a mapscript writer object with the given template that saves the
+     * map to the filename.
+     *
+     * @param templ    Mapfile template.
+     * @param filename Output file name.
+     */
     public MapScriptWriter(String templ, String filename) {
         String path = System.getProperty("user.dir");
         map = new mapObj(templ);
@@ -231,6 +243,7 @@
             //The layer datasource.
             String con_type = layerElement.getAttribute("connection_type");
             if(con_type.equals("local")) {
+                // The data source is a local file. (.shp)
                 String datasource = "";
                 if(layerElement.hasAttribute("workspace")) {
                     datasource = layerElement.getAttribute("workspace");
@@ -241,6 +254,7 @@
                 layer.setData(datasource);
             }
             else if(con_type.equals("SDE")) {
+                // The data source is a sde database.
                 logger.info(
                     "SDE datasource found." +
                     " Please edit password in mapfile.");
@@ -283,6 +297,7 @@
             }
             layer.setTemplate("PleaseInsertAValidTemplateForGFI");
 
+            // Create labelitem
             NodeList labels = layerElement.getElementsByTagName("label");
             if(labels.getLength() > 0) {
                 Element label = (Element)labels.item(0);
@@ -298,7 +313,6 @@
             //Write classes.
             writeClass(layer, layerElement);
         }
-
     }
 
     /**
@@ -326,15 +340,19 @@
             }
             co.setName (name);
 
+            //Create label object.
             NodeList labels = layerElement.getElementsByTagName("label");
             if(labels.getLength() > 0) {
                 Element labelElement = (Element)labels.item(0);
                 String  layerType = layerElement.getAttribute("type");
                 writeLabel(co, labelElement, layerType);
             }
+
+            //Create definition expression.
             if(classElement.hasAttribute("field_count")) {
                 co.setExpression(createExpression(classElement, i));
             }
+
             //Write symbols and styles.
             NodeList l = classElement.getChildNodes();
             for (int j = l.getLength() - 1; j >= 0; j--) {
@@ -363,13 +381,22 @@
         }
     }
 
-
+    /**
+     * Create a label object in a class object.
+     *
+     * @param co Class object.
+     * @param labelElement DOM element containing label attributes.
+     * @param layertype The layer type. Used to define the label position.
+     */
     private void writeLabel(
         classObj co,
         Element labelElement,
         String layerType) {
 
+        //Get the label object. Each class has a predefined labelobject.
         labelObj label = co.getLabel();
+
+        //Get the label text symbol attributes from DOM.
         Element symbol = (Element)labelElement.getFirstChild();
         if(symbol != null && symbol.getTagName().equals("symbol")) {
             String type = symbol.getAttribute("type");
@@ -419,13 +446,19 @@
                 }
             }
 
+            //Set the label position.
             if(layerType.equals("point")) {
                 label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue());
             }
         }
     }
 
-
+    /**
+     * Create definition expression.
+     *
+     * @param ce DOM elementcontaining the class expression information.
+     * @param index Index to determine the correct expression operator.
+     */
     private String createExpression(Element ce, int index) {
         String expression = "(";
         int count = 0;
@@ -435,8 +468,11 @@
         catch(NumberFormatException nfe) {
             return "";
         }
+
         if(count == 1) {
-            try {
+           //Create single field expression.
+           try {
+                //If no exception is thrown, the expression value is a number.
                 Double.parseDouble(ce.getAttribute("value"));
                 String exp = ce.getAttribute("expression_field_0");
                 String pre = "";
@@ -452,14 +488,15 @@
                     else {
                         expression += " > " + ce.getAttribute("min_value");
                     }
-                        expression += " AND [" + pre;
-                        expression += ce.getAttribute("expression_field_0");
-                        expression += "]";
+                    expression += " AND [" + pre;
+                    expression += ce.getAttribute("expression_field_0");
+                    expression += "]";
                 }
                 expression += " " + ce.getAttribute("expression_operator");
                 expression += " " + ce.getAttribute("value") + ")";
             }
             catch(NumberFormatException nfe) {
+                //The expression value is a strings.
                 String exp = ce.getAttribute("expression_field_0");
                 String pre = "";
                 if (!prefix.equals("") && !exp.startsWith(prefix)) {
@@ -475,8 +512,11 @@
             }
         }
         else {
+            //Create a multi field expression.
             for (int i = 0; i < count; i++) {
                 try {
+                    //If no exception is thrown, the expression values are
+                    //numbers.
                     Double.parseDouble(ce.getAttribute("value_" + i));
                     String exp = ce.getAttribute("expression_field_" + i);
                     String pre = "";
@@ -496,6 +536,7 @@
                     }
                 }
                 catch (NumberFormatException nfe) {
+                    //The expression values are strings.
                     String exp = ce.getAttribute("expression_field_" + i);
                     String pre = "";
                     if (!prefix.equals("") && !exp.startsWith(prefix)) {
@@ -518,4 +559,3 @@
         return expression;
     }
 }
-
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)