diff src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 180:f4eb506499f5

Done some code styling and removed TODOs.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 11 Jul 2011 12:11:08 +0200
parents f3a91cd7440b
children 0bde090506f9
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Fri Jul 08 16:32:05 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Jul 11 12:11:08 2011 +0200
@@ -58,27 +58,27 @@
     }
 
     public MapScriptWriter(String templ, String filename) {
-	String path = System.getProperty("user.dir");
+        String path = System.getProperty("user.dir");
         map = new mapObj(templ);
-	File f = new File(filename);
-	mapFilename = filename;
-	if(f.isAbsolute()) {
+        File f = new File(filename);
+        mapFilename = filename;
+        if(f.isAbsolute()) {
             map.setMappath(mapFilename);
-	}
-	else {
-	    map.setMappath(
-	        System.getProperty("user.dir") +
-	       	File.separator +
-		mapFilename);
-	    mapFilename = System.getProperty("user.dir") +
-	       	File.separator +
-		mapFilename;
-	}
-	String fontSetPath = map.getFontset().getFilename();
-	File fonts = new File(fontSetPath);
-	String fontSet = fonts.getAbsolutePath();
-	fontSet = fontSet.replaceAll("\\\\", "/");
-	map.setFontSet(fontSet);
+        }
+        else {
+            map.setMappath(
+                System.getProperty("user.dir") +
+                File.separator +
+                mapFilename);
+            mapFilename = System.getProperty("user.dir") +
+                File.separator +
+                mapFilename;
+        }
+        String fontSetPath = map.getFontset().getFilename();
+        File fonts = new File(fontSetPath);
+        String fontSet = fonts.getAbsolutePath();
+        fontSet = fontSet.replaceAll("\\\\", "/");
+        map.setFontSet(fontSet);
     }
 
     /**
@@ -103,7 +103,7 @@
         //Save the map.
         mapObj cloneMap = map.cloneMap();
 
-	cloneMap.save(mapFilename);
+        cloneMap.save(mapFilename);
         logger.info("Mapfile created: " + mapFilename);
         return true;
     }
@@ -130,10 +130,10 @@
             Double.parseDouble(mapNode.getAttribute("extent_max_y")));
 
         //Set the units and projection.
-	int proj = Integer.parseInt(mapNode.getAttribute("projection"));
-	if(proj != 0) {
-	    map.setProjection("epsg:" + mapNode.getAttribute("projection"));
-	}
+        int proj = Integer.parseInt(mapNode.getAttribute("projection"));
+        if(proj != 0) {
+            map.setProjection("epsg:" + mapNode.getAttribute("projection"));
+        }
         String u = mapNode.getAttribute("units");
         if(u.equals("feet")) {
             units = MS_UNITS.MS_FEET;
@@ -156,16 +156,13 @@
         else if(u.equals("points")) {
             units = MS_UNITS.MS_PIXELS;
         }
-	else if(u.equals("degree")) {
-	    units = MS_UNITS.MS_DD;
-	}
+        else if(u.equals("degree")) {
+            units = MS_UNITS.MS_DD;
+        }
         else {
             units = MS_UNITS.MS_METERS;
         }
         map.setUnits(units);
-
-        //TODO: Find out whats the correct scale value.
-        //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale")));
     }
 
     /**
@@ -186,11 +183,12 @@
             String lname = layerElement.getAttribute("name");
             lname = lname.replaceAll(" ", "");
             layer.setName(lname);
-	    layer.setUnits(units.swigValue());
+            layer.setUnits(units.swigValue());
             layer.setMetaData("wms_title", layerElement.getAttribute("name"));
             if(layerElement.hasAttribute("group")) {
-	    	layer.setGroup(layerElement.getAttribute("group"));
-	    }
+                layer.setGroup(layerElement.getAttribute("group"));
+            }
+
             //The layer status.
             String stat = layerElement.getAttribute("status");
             if (stat.equals("on")) {
@@ -239,7 +237,7 @@
                     datasource += File.separator;
                 }
                 datasource += layerElement.getAttribute("data_source");
-		datasource = datasource.replaceAll("\\\\", "/");
+                datasource = datasource.replaceAll("\\\\", "/");
                 layer.setData(datasource);
             }
             else if(con_type.equals("SDE")) {
@@ -275,27 +273,28 @@
                 }
                 else {
                     prefix = layerElement.getAttribute("data_source");
-		    if(layerElement.hasAttribute("definition_query") &&
-		       !layerElement.getAttribute("definition_query").equals("")) {
-		        layer.setFilter("where " +
-		            layerElement.getAttribute("definition_query"));   
-		    }
+                    if(layerElement.hasAttribute("definition_query") &&
+                       !layerElement.getAttribute("definition_query")
+                                     .equals("")) {
+                        layer.setFilter("where " +
+                        layerElement.getAttribute("definition_query"));
+                    }
                 }
-
             }
             layer.setTemplate("PleaseInsertAValidTemplateForGFI");
 
-	    NodeList labels = layerElement.getElementsByTagName("label");
-	    if(labels.getLength() > 0) {
-		Element label = (Element)labels.item(0);
+            NodeList labels = layerElement.getElementsByTagName("label");
+            if(labels.getLength() > 0) {
+                Element label = (Element)labels.item(0);
                 String expr = label.getAttribute("expression");
-		expr = expr.replaceAll("\\[", "");
-		expr = expr.replaceAll("\\]", "");
-		if(!prefix.equals("")) {
-		    expr = prefix + "." + expr;
-		}
-		layer.setLabelitem(expr);
-	    }
+                expr = expr.replaceAll("\\[", "");
+                expr = expr.replaceAll("\\]", "");
+                if(!prefix.equals("")) {
+                    expr = prefix + "." + expr;
+                }
+                layer.setLabelitem(expr);
+            }
+
             //Write classes.
             writeClass(layer, layerElement);
         }
@@ -327,12 +326,12 @@
             }
             co.setName (name);
 
-       	    NodeList labels = layerElement.getElementsByTagName("label");
-	    if(labels.getLength() > 0) {
-	        Element labelElement = (Element)labels.item(0);
-		String  layerType = layerElement.getAttribute("type");
-		writeLabel(co, labelElement, layerType);
-	    } 
+            NodeList labels = layerElement.getElementsByTagName("label");
+            if(labels.getLength() > 0) {
+                Element labelElement = (Element)labels.item(0);
+                String  layerType = layerElement.getAttribute("type");
+                writeLabel(co, labelElement, layerType);
+            }
             if(classElement.hasAttribute("field_count")) {
                 co.setExpression(createExpression(classElement, i));
             }
@@ -342,16 +341,22 @@
                 Element elem = (Element)l.item(j);
 
                 String type = layerElement.getAttribute("type");
-                if(type.equals("point") && elem.getTagName().equals("symbol")) {
-                    MarkerStyleWriter swriter = new MarkerStyleWriter (this.map, co);
+                if(type.equals("point") &&
+                   elem.getTagName().equals("symbol")) {
+                    MarkerStyleWriter swriter =
+                        new MarkerStyleWriter (this.map, co);
                     swriter.write (elem);
                 }
-                else if(type.equals("line") && elem.getTagName().equals("symbol")) {
-                    LineStyleWriter swriter = new LineStyleWriter (this.map, co);
+                else if(type.equals("line") &&
+                        elem.getTagName().equals("symbol")) {
+                    LineStyleWriter swriter =
+                        new LineStyleWriter (this.map, co);
                     swriter.write (elem);
                 }
-                else if(type.equals("polygon") && elem.getTagName().equals("symbol")) {
-                    FillStyleWriter swriter = new FillStyleWriter (this.map, co);
+                else if(type.equals("polygon") &&
+                        elem.getTagName().equals("symbol")) {
+                    FillStyleWriter swriter =
+                        new FillStyleWriter (this.map, co);
                     swriter.write (elem);
                 }
             }
@@ -360,19 +365,19 @@
 
 
     private void writeLabel(
-	classObj co,
-       	Element labelElement,
-       	String layerType) {
+        classObj co,
+        Element labelElement,
+        String layerType) {
 
         labelObj label = co.getLabel();
-	Element symbol = (Element)labelElement.getFirstChild();
-	if(symbol != null && symbol.getTagName().equals("symbol")) {
-	    String type = symbol.getAttribute("type");
-	    if(type.equals("text")) {
-	    	label.setType(MS_FONT_TYPE.MS_TRUETYPE);
-	    }
-	    label.setSize(Double.parseDouble(symbol.getAttribute("size")));
-            
+        Element symbol = (Element)labelElement.getFirstChild();
+        if(symbol != null && symbol.getTagName().equals("symbol")) {
+            String type = symbol.getAttribute("type");
+            if(type.equals("text")) {
+                label.setType(MS_FONT_TYPE.MS_TRUETYPE);
+            }
+            label.setSize(Double.parseDouble(symbol.getAttribute("size")));
+
             if(symbol.hasAttribute("color")) {
                 String c = symbol.getAttribute("color");
                 Color col = Color.decode(c);
@@ -382,42 +387,42 @@
                     col.getBlue(),
                     -4);
                 label.setColor(color);
-	    }
-	    if(symbol.hasAttribute("font")) {
-	        String font = symbol.getAttribute("font");
-		fontSetObj fso = this.map.getFontset();
-		hashTableObj fonts = fso.getFonts();
-		String mapFont = fonts.get(font,"");
-		if(mapFont != null && !mapFont.equals("")) {
-		    label.setFont(font);
-		}
-		else {
-		    logger.info(
-			"Could not find font " + font + " in font set. " +
-			"Using FreeSans for labels.");
-                    label.setFont("FreeSans");
-		}
-	    }
+            }
+            if(symbol.hasAttribute("font")) {
+                String font = symbol.getAttribute("font");
+                fontSetObj fso = this.map.getFontset();
+                hashTableObj fonts = fso.getFonts();
+                String mapFont = fonts.get(font,"");
+                if(mapFont != null && !mapFont.equals("")) {
+                    label.setFont(font);
+                }
+                else {
+                    logger.info(
+                        "Could not find font " + font + " in font set. " +
+                        "Using FreeSans for labels.");
+                        label.setFont("FreeSans");
+                }
+            }
 
             if(labelElement.hasAttribute("max_scale")) {
-		double min =
-		    Double.parseDouble(labelElement.getAttribute("max_scale"));
-		if(min > 0) {
-	            label.setMinscaledenom(min);
-		}
-	    }
-	    if(labelElement.hasAttribute("min_scale")) {
-	        double max =
-		    Double.parseDouble(labelElement.getAttribute("min_scale"));
-		if(max > 0) {
-		    label.setMaxscaledenom(max);
-		}
-	    }
+                double min =
+                    Double.parseDouble(labelElement.getAttribute("max_scale"));
+                if(min > 0) {
+                    label.setMinscaledenom(min);
+                }
+            }
+            if(labelElement.hasAttribute("min_scale")) {
+                double max =
+                    Double.parseDouble(labelElement.getAttribute("min_scale"));
+                if(max > 0) {
+                    label.setMaxscaledenom(max);
+                }
+            }
 
-	    if(layerType.equals("point")) {
-	        label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue());
-	    }
-	}
+            if(layerType.equals("point")) {
+                label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue());
+            }
+        }
     }
 
 
@@ -441,14 +446,15 @@
                 expression += "[" + pre;
                 expression += ce.getAttribute("expression_field_0") + "]";
                 if(ce.hasAttribute("min_value")) {
-		    if(index == 0) {
-		        expression += " >= " + ce.getAttribute("min_value");
-		    }
-		    else {
+                    if(index == 0) {
+                        expression += " >= " + ce.getAttribute("min_value");
+                    }
+                    else {
                         expression += " > " + ce.getAttribute("min_value");
-		    }
-                    expression += " AND [" + pre;
-                    expression += ce.getAttribute("expression_field_0")+ "]";
+                    }
+                        expression += " AND [" + pre;
+                        expression += ce.getAttribute("expression_field_0");
+                        expression += "]";
                 }
                 expression += " " + ce.getAttribute("expression_operator");
                 expression += " " + ce.getAttribute("value") + ")";
@@ -478,7 +484,8 @@
                        pre = prefix + ".";
                     }
                     expression += "[" + pre;
-                    expression += ce.getAttribute("expression_field_" + i) + "]";
+                    expression += ce.getAttribute("expression_field_" + i);
+                    expression += "]";
                     expression += " " + ce.getAttribute("expression_operator");
                     expression += " " + ce.getAttribute("value_" + i);
                     if (i < count - 1) {
@@ -495,7 +502,8 @@
                        pre = prefix + ".";
                     }
                     expression += "\"[" + pre;
-                    expression += ce.getAttribute("expression_field_" + i) + "]\"";
+                    expression += ce.getAttribute("expression_field_" + i);
+                    expression += "]\"";
                     expression += " " + ce.getAttribute("expression_operator");
                     expression += " " + ce.getAttribute("value_" + i);
                     if (i < count - 1) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)