Mercurial > mxd2map
diff src/java/de/intevation/mxd/Converter.java @ 55:f0c02ff120d6
Read filenames from properties file or commandline arguments.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 16 May 2011 18:21:27 +0200 |
parents | ef7ca23c4233 |
children | e19c5eb43099 |
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/Converter.java Wed May 11 10:10:18 2011 +0200 +++ b/src/java/de/intevation/mxd/Converter.java Mon May 16 18:21:27 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 :