diff src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 134:acc9e5430177

Handle SDE connection attributes and expressions.
author vc11884admin@VC11884.win.bsh.de
date Wed, 22 Jun 2011 12:01:28 +0200
parents 02df1dbc2166
children cd55975ba0c4
line wrap: on
line diff
--- 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)