diff src/java/de/intevation/mxd/Converter.java @ 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 39957898c694
children f4eb506499f5
line wrap: on
line diff
--- 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 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)