changeset 134:acc9e5430177

Handle SDE connection attributes and expressions.
author vc11884admin@VC11884.win.bsh.de
date Wed, 22 Jun 2011 12:01:28 +0200
parents 6b80d2c7536e
children a4ab239509f1
files ChangeLog src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 3 files changed, 155 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jun 21 15:22:06 2011 +0200
+++ b/ChangeLog	Wed Jun 22 12:01:28 2011 +0200
@@ -1,3 +1,12 @@
+2011-06-22  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java:
+	  Split comma separated value list into single values.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Handle join tables and create class expressions correctly for
+	  multiple values and string values.
+
 2011-06-21  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
--- a/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Tue Jun 21 15:22:06 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Wed Jun 22 12:01:28 2011 +0200
@@ -84,10 +84,28 @@
 
             try {
                 String value = renderer.getValue(i);
+                value = value.replaceAll(" ", "");
+                if(value.indexOf(",") > 0) {
+                    int j = 0;
+                    while(value.indexOf(",") > 0) {
+                        String v = value.substring(0, value.indexOf(","));
+                        rendererElement.setAttribute("value_" + j, v);
+                        value = value.substring(
+                            value.indexOf(",") + 1,
+                            value.length());
+                        j++;
+                    }
+                    rendererElement.setAttribute("value_" + j, value);
+                }
+                else {
+                    rendererElement.setAttribute("value", value);
+                }
+
+                value = renderer.getValue(i);
                 rendererElement.setAttribute("name", renderer.esri_getClass(i));
                 rendererElement.setAttribute("description",
-                renderer.getDescription(value));
-                rendererElement.setAttribute("value", value);
+                    renderer.getDescription(value));
+
                 rendererElement.setAttribute("label", renderer.getLabel(value));
                 rendererElement.setAttribute(
                     "field_count",
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Tue Jun 21 15:22:06 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Wed Jun 22 12:01:28 2011 +0200
@@ -41,6 +41,7 @@
     private mapObj map;
     private String mapFilename;
     private String MS_BINDIR = "c:/ms_6.1-dev/bin";
+    private String prefix = "";
 
     public MapScriptWriter() {
         map = new mapObj("");
@@ -184,7 +185,7 @@
 
             //The layer datasource.
 	    String con_type = layerElement.getAttribute("connection_type");
-	    if(con_type.equals("local")) {
+            if(con_type.equals("local")) {
                 String datasource = "";
                 if(layerElement.hasAttribute("workspace")) {
                     datasource = layerElement.getAttribute("workspace");
@@ -210,19 +211,23 @@
 		    ",SHAPE," +
 		    layerElement.getAttribute("version"));
 		layer.setProcessing("CLOSE_CONNECTION=defer");
-		layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE");
-		layer.setProcessing(
-		    "JOINTABLE=" +
-		    layerElement.getAttribute("join_table"));
-                layer.setFilter(
-		    "where " + 
-		    layerElement.getAttribute("definition_query") +
-		    " AND " +
-		    layerElement.getAttribute("join_table_target") + "." +
-		    layerElement.getAttribute("join_field_target") + "=" +
-		    layerElement.getAttribute("join_table") + "." +
-		    layerElement.getAttribute("join_field"));
-
+                layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE");
+		if(layerElement.hasAttribute("join_table")) {
+                    layer.setProcessing(
+		        "JOINTABLE=" +
+		        layerElement.getAttribute("join_table"));
+                    layer.setFilter(
+                        "where " + 
+                        layerElement.getAttribute("definition_query") +
+                        " AND " +
+                        layerElement.getAttribute("join_table_target") + "." +
+                        layerElement.getAttribute("join_field_target") + "=" +
+                        layerElement.getAttribute("join_table") + "." +
+                        layerElement.getAttribute("join_field"));
+		}
+		else {
+		    prefix = layerElement.getAttribute("data_source");
+		}
 	    }
             layer.setTemplate("PleaseInsertAValidTemplateForGFI");
             //Write classes.
@@ -256,23 +261,7 @@
             }
             co.setName (name);
             if(classElement.hasAttribute("field_count")) {
-                int count =
-                    Integer.parseInt(classElement.getAttribute("field_count"));
-                int type = 0;
-                try {
-                    Double.parseDouble(classElement.getAttribute("value"));
-                    type = 1;
-                }
-                catch(Exception e) {
-                    type = 2;
-                }
-                if (type == 1) {
-                    co.setExpression(createDoubleExpression(classElement, count));
-                }
-                else if (type == 2) {
-                    co.setExpression(createStringExpression(classElement, count));
-                }
-
+	        co.setExpression(createExpression(classElement));
             }
             //Write symbols and styles.
             NodeList l = classElement.getChildNodes();
@@ -296,6 +285,112 @@
         }
     }
 
+
+    private String createExpression(Element ce) {
+    	String expression = "(";
+	int count = 0;
+	try {
+	    count = Integer.parseInt(ce.getAttribute("field_count"));
+	}
+	catch(NumberFormatException nfe) {
+		return "";
+	}
+	if(count == 1) {
+            try {
+                Double.parseDouble(ce.getAttribute("value"));
+		String exp = ce.getAttribute("expression_field_0");
+		String pre = "";
+		if (!prefix.equals("") && !exp.startsWith(prefix)) {
+                    pre = prefix + ".";
+		}
+		expression += "[" + pre;
+		expression += ce.getAttribute("expression_field_0") + "]";
+		if(ce.hasAttribute("min_value")) {
+                    expression += " > " + ce.getAttribute("min_value");
+		    expression += " AND [";
+		    expression += ce.getAttribute("expression_field_0")+ "]";
+		}
+		expression += " " + ce.getAttribute("expression_operator");
+		expression += " " + ce.getAttribute("value") + ")";
+	    }
+	    catch(NumberFormatException nfe) {
+ 		String exp = ce.getAttribute("expression_field_0");
+		String pre = "";
+		if (!prefix.equals("") && !exp.startsWith(prefix)) {
+                    pre = prefix + ".";
+		}
+  		expression += "\"[" + pre;
+		expression += ce.getAttribute("expression_field_0") + "]\"";
+		expression += " " + ce.getAttribute("expression_operator");
+		expression += " \"" + ce.getAttribute("value") + "\")";	
+	    }
+	    catch(Exception e) {
+	    	e.printStackTrace();
+	    }
+	}
+	else {
+            for (int i = 0; i < count; i++) {
+                try {
+                    Double.parseDouble(ce.getAttribute("value_" + i));
+                    String exp = ce.getAttribute("expression_field_" + i);
+                    String pre = "";
+                    if (!prefix.equals("") && !exp.startsWith(prefix)) {
+                       pre = prefix + ".";
+                    }
+                    expression += "[" + pre;
+                    expression += ce.getAttribute("expression_field_" + i) + "]";
+                    expression += " " + ce.getAttribute("expression_operator");
+                    expression += " " + ce.getAttribute("value_" + i);
+		    if (i < count - 1) {
+			expression += " AND ";
+		    }
+		    else {
+		    	expression += ")";
+		    }
+		}
+		catch (NumberFormatException nfe) {
+	            String exp = ce.getAttribute("expression_field_" + i);
+                    String pre = "";
+                    if (!prefix.equals("") && !exp.startsWith(prefix)) {
+                       pre = prefix + ".";
+                    }
+                    expression += "\"[" + pre;
+                    expression += ce.getAttribute("expression_field_" + i) + "]\"";
+                    expression += " " + ce.getAttribute("expression_operator");
+                    expression += " " + ce.getAttribute("value_" + i);
+		    if (i < count - 1) {
+			expression += " AND ";
+		    }
+		    else {
+		        expression += ")";
+		    }
+		}
+	    }
+	}
+	return expression;
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private String createDoubleExpression (Element classElement, int count) {
         String exp = "";
         String op = classElement.getAttribute("expression_operator");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)