# HG changeset patch # User raimund.renkert@intevation.de # Date 1309970320 -7200 # Node ID 707f13cfba74a91c9bde4e8b565057628585dbe1 # Parent 0a1435aa33d81282f8b6927e86fe5634e0067ceb Improved the commandline arguments and save the mapfile in the correct directory. diff -r 0a1435aa33d8 -r 707f13cfba74 ChangeLog --- 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 + + * 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 * mxd/Styles/scale/maxscale_100000.mxd, diff -r 0a1435aa33d8 -r 707f13cfba74 build.xml --- 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 @@ - + diff -r 0a1435aa33d8 -r 707f13cfba74 src/java/de/intevation/mxd/Converter.java --- 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 : diff -r 0a1435aa33d8 -r 707f13cfba74 src/java/de/intevation/mxd/writer/MapScriptWriter.java --- 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; } diff -r 0a1435aa33d8 -r 707f13cfba74 src/java/de/intevation/mxd/writer/SymbolWriter.java --- 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"; }