changeset 174:707f13cfba74

Improved the commandline arguments and save the mapfile in the correct directory.
author raimund.renkert@intevation.de
date Wed, 06 Jul 2011 18:38:40 +0200
parents 0a1435aa33d8
children f11d13940626
files ChangeLog build.xml src/java/de/intevation/mxd/Converter.java src/java/de/intevation/mxd/writer/MapScriptWriter.java src/java/de/intevation/mxd/writer/SymbolWriter.java
diffstat 5 files changed, 69 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jul 06 18:27:46 2011 +0200
+++ b/ChangeLog	Wed Jul 06 18:38:40 2011 +0200
@@ -1,3 +1,17 @@
+2011-07-06  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/Converter.java:
+	  Use the new jargs library for commandline arguments.
+
+	* build.xml:
+	  Added the new jargs library to the classpath.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Find out the correct path to save the mapfile.
+
+	* src/java/de/intevation/mxd/writer/SymbolWriter.java:
+	  Save the symbolset to the same directory as the mapfile.
+
 2011-07-06  Stephan Holl  <stephan.holl@intevation.de>
 
 	* mxd/Styles/scale/maxscale_100000.mxd,
--- a/build.xml	Wed Jul 06 18:27:46 2011 +0200
+++ b/build.xml	Wed Jul 06 18:38:40 2011 +0200
@@ -57,7 +57,7 @@
     <jar jarfile="${dist.dir}/${sample.dir}.jar" compress="true" basedir="${class.dir}">
       <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"/>
+	<attribute name="Class-Path" value="lib/log4j-1.2.16.jar lib/mapscript.jar lib/arcobjects.jar lib/jargs.jar"/>
       </manifest>
     </jar>
   </target>
--- a/src/java/de/intevation/mxd/Converter.java	Wed Jul 06 18:27:46 2011 +0200
+++ b/src/java/de/intevation/mxd/Converter.java	Wed Jul 06 18:38:40 2011 +0200
@@ -8,6 +8,8 @@
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
+import jargs.gnu.CmdLineParser;
+
 import java.net.MalformedURLException;
 
 import de.intevation.mxd.reader.IReader;
@@ -51,31 +53,30 @@
      * Entrypoint for the application.
      */
     public static void main(String[] args) {
+        CmdLineParser parser = new CmdLineParser();
+        CmdLineParser.Option mxd = parser.addStringOption('m', "mxd");
+        CmdLineParser.Option map = parser.addStringOption('a', "map");
+        CmdLineParser.Option temp = parser.addStringOption('t', "template");
+
+        try{
+            parser.parse(args);
+        }
+        catch(CmdLineParser.OptionException oe) {
+            logger.warn("Invalid options.");
+            printUsage();
+            System.exit(1);
+        }
+
         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("")) {
+            mxdfile = (String)parser.getOptionValue(mxd);
+            mapfile = (String)parser.getOptionValue(map);
+            maptemplate = (String)parser.getOptionValue(temp);
+
+            if(mxdfile == null) {
                 try {
                     mxdfile = readProperty("mxd");
                 }
@@ -83,7 +84,7 @@
                     e.printStackTrace ();
                 }
             }
-            if(mapfile.equals("")) {
+            if(mapfile == null) {
                 try {
                     mapfile = readProperty("map");
                 }
@@ -91,7 +92,7 @@
                     e.printStackTrace ();
                 }
             }
-            if(maptemplate.equals("")) {
+            if(maptemplate == null) {
                 try {
                     maptemplate = readProperty("map-template");
                 }
@@ -112,6 +113,7 @@
         }
         catch(Exception e) {
             logger.error(e.getMessage());
+            e.printStackTrace();
         }
     }
 
@@ -143,5 +145,11 @@
         }
     }
 
+    
+    private static void printUsage() {
+        System.out.println("Available parameters:[{-m,--mxd} path/to/mxd]\n" +
+                           "\t\t[{-a,--map} path/to/mapfile]\n" +
+                           "\t\t[{-t,--template} path/to/template]");
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Wed Jul 06 18:27:46 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Wed Jul 06 18:38:40 2011 +0200
@@ -50,8 +50,22 @@
     }
 
     public MapScriptWriter(String templ, String filename) {
+	String path = System.getProperty("user.dir");
         map = new mapObj(templ);
-        mapFilename = filename;
+	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;
+	}	
     }
 
     /**
@@ -75,8 +89,9 @@
         writeLayer();
         //Save the map.
         mapObj cloneMap = map.cloneMap();
-        cloneMap.save(mapFilename);
-        logger.info("Mapfile successfully created.");
+
+	cloneMap.save(mapFilename);
+        logger.info("Mapfile created: " + mapFilename);
         return true;
     }
 
--- a/src/java/de/intevation/mxd/writer/SymbolWriter.java	Wed Jul 06 18:27:46 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/SymbolWriter.java	Wed Jul 06 18:38:40 2011 +0200
@@ -13,6 +13,7 @@
 import edu.umn.gis.mapscript.pointObj;
 import edu.umn.gis.mapscript.MS_SYMBOL_TYPE;
 
+import java.io.File;
 
 /**
  * The interface to the mapfile writer.
@@ -157,6 +158,11 @@
         if(path.equals("")) {
             return;
         }
+
+        if (path.endsWith(".map")) {
+            path = path.substring(0, path.lastIndexOf(File.separator) + 1);
+            path += "symbols.sym";
+        }
         else {
             path += "symbols.sym";
         }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)