changeset 56:08913299e34f

Merged with Stephans commit.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 17 May 2011 11:55:03 +0200
parents f0c02ff120d6 (diff) 2cbf8bdf20b2 (current diff)
children 8da6555f1c12
files ChangeLog
diffstat 5 files changed, 120 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 16 16:20:13 2011 +0200
+++ b/ChangeLog	Tue May 17 11:55:03 2011 +0200
@@ -1,3 +1,18 @@
+2011-05-16  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* build.xml: Set the classpath for the executabel jar file. The path to
+	  the external libraries (lib/) is relative to the executable.
+
+	* src/java/de/intevation/mxd/Converter.java:
+	  Use commandline arguments to set the filenames for the MXD-, MAP- and
+	  the template file. If no arguments are used, read the filenames from
+	  the converter.properties file.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Use the template file for mapfile creation.
+
+	* converter.properties.sample: New. Example for the properties file.
+
 2011-05-16  Stephan Holl  <stephan.holl@intevation.de>
 
 	* doku/funktionsweise/Makefile,
--- a/build.xml	Mon May 16 16:20:13 2011 +0200
+++ b/build.xml	Tue May 17 11:55:03 2011 +0200
@@ -56,8 +56,9 @@
     <mkdir dir="${dist.dir}" />
     <jar jarfile="${dist.dir}/${sample.dir}.jar" compress="true" basedir="${class.dir}">
       <manifest>
-        <attribute name="Main-Class" value="${main.class}"/>
-      </manifest>	
+        <attribute name="Main-Class" value="de.intevation.mxd.Converter"/>
+        <attribute name="Class-Path" value="lib/log4j-1.2.16.jar lib/mapscript.jar lib/arcobjects.jar"/>
+      </manifest>
     </jar>
   </target>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/converter.properties.sample	Tue May 17 11:55:03 2011 +0200
@@ -0,0 +1,4 @@
+# Java properties file for the MXD Converter Tool.
+mxd = \\full\\path\\to\\mxd-file
+map = \\full\\path\\to\\map-file
+map-template = \\full\\path\\to\\mapfile-template
--- a/src/java/de/intevation/mxd/Converter.java	Mon May 16 16:20:13 2011 +0200
+++ b/src/java/de/intevation/mxd/Converter.java	Tue May 17 11:55:03 2011 +0200
@@ -2,6 +2,9 @@
 
 import java.io.IOException;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.util.Properties;
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
@@ -46,6 +49,84 @@
 
 
     /**
+     * Entrypoint for the application.
+     */
+    public static void main(String[] args) {
+        try{
+            String mxdfile = "";
+            String mapfile = "";
+            String maptemplate = "";
+            int ndx = 0;
+            if (args.length > 0) {
+                if (args[0].equals("-mxd") && args.length >= 2) {
+                    mxdfile = args[1];
+                    ndx = 2;
+                }
+            }
+            if (args.length >= ndx + 2) {
+                if (args[ndx].equals("-map")) {
+                    mapfile = args[ndx+1];
+                    ndx += 2;
+                }
+            }
+            if (args.length >= ndx + 2) {
+                if (args[ndx].equals("-template")) {
+                    maptemplate = args[ndx+1];
+                    ndx += 2;
+                }
+            }
+
+            if(mxdfile.equals("")) {
+                try {
+                    mxdfile = readProperty("mxd");
+                }
+                catch(Exception e) {
+                    e.printStackTrace ();
+                }
+            }
+            if(mapfile.equals("")) {
+                try {
+                    mapfile = readProperty("map");
+                }
+                catch(Exception e) {
+                    e.printStackTrace ();
+                }
+            }
+            if(maptemplate.equals("")) {
+                try {
+                    maptemplate = readProperty("map-template");
+                }
+                catch(Exception e) {
+                    e.printStackTrace ();
+                }
+            }
+
+            IReader reader = new MXDReader();
+            reader.init();
+            reader.setFilename(mxdfile);
+            reader.read();
+
+            IWriter writer = new MapScriptWriter(maptemplate, mapfile);
+            writer.write(reader.getMapDocument());
+            reader.shutdown();
+        }
+        catch(IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static String readProperty (String key)
+    throws Exception {
+        Properties properties = new Properties();
+        BufferedInputStream stream =
+            new BufferedInputStream(
+                new FileInputStream("converter.properties")
+            );
+        properties.load(stream);
+        stream.close();
+        return properties.getProperty(key);
+    }
+    /**
      * Trys to load the Log4j configuration
      * from ${config.dir}/log4j.properties.
      */
@@ -62,31 +143,5 @@
         }
     }
 
-    /**
-     * Entrypoint for the application.
-     */
-    public static void main(String[] args) {
-        try{
-
-            IReader reader = new MXDReader();
-            IWriter writer = new MapScriptWriter();
-            reader.init();
-
-            String path = System.getProperty("mxd.file");
-            if (path.equals("${MXDFILE}")) {
-                System.out.println("No valid MXD file. Use ant parameter" +
-                                   " \"-DMXDFILE=path/to/file.mxd\".");
-                System.exit(-1);
-            }
-            reader.setFilename(path);
-
-            reader.read();
-            writer.write(reader.getMapDocument());
-            reader.shutdown();
-        }
-        catch(IOException e) {
-            e.printStackTrace();
-        }
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon May 16 16:20:13 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Tue May 17 11:55:03 2011 +0200
@@ -44,18 +44,16 @@
      */
     private Document root;
     private mapObj map;
-
+    private String mapFilename;
 
-    /**
-     * TODO: Workarround to import the Mapfile-Template, it should be done
-     * via a property file, currently hardcoded.
-     */
     public MapScriptWriter() {
-        map = new mapObj("z:/mxd-testbed_sh/mapserver/mapfile/mxd.map");
+        map = new mapObj("");
+        mapFilename = "";
     }
 
-    public MapScriptWriter(String path) {
-        map = new mapObj(path);
+    public MapScriptWriter(String templ, String filename) {
+        map = new mapObj(templ);
+        mapFilename = filename;
     }
 
     /**
@@ -73,17 +71,13 @@
             root,
             "/mxd/file",
             XPathConstants.NODE);
-        String filename = fileNode.getAttribute("name");
-        if(filename.endsWith(".mxd")) {
-            filename = filename.replace(".mxd", ".map");
-        }
         //Write the map attributes.
         writeMap();
         //Write the layers.
         writeLayer();
         //Save the map.
         mapObj cloneMap = map.cloneMap();
-        cloneMap.save(filename);
+        cloneMap.save(mapFilename);
         return true;
     }
 
@@ -242,14 +236,16 @@
             styleObj style = new styleObj(co);
             style.setAngle(
                 Double.parseDouble(symbolElement.getAttribute("angle")));
-            String c = symbolElement.getAttribute("color");
-            Color col = Color.decode(c);
-            colorObj color = new colorObj(
-                col.getRed(),
-                col.getGreen(),
-                col.getBlue(),
-                -4);
-            style.setColor(color);
+            if(symbolElement.hasAttribute("color")) {
+                String c = symbolElement.getAttribute("color");
+                Color col = Color.decode(c);
+                colorObj color = new colorObj(
+                    col.getRed(),
+                    col.getGreen(),
+                    col.getBlue(),
+                    -4);
+                style.setColor(color);
+            }
             style.setSize(Double.parseDouble(
                 symbolElement.getAttribute("size")));
             if(symbolElement.hasAttribute("outline_color")) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)