comparison 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
comparison
equal deleted inserted replaced
173:0a1435aa33d8 174:707f13cfba74
5 import java.io.BufferedInputStream; 5 import java.io.BufferedInputStream;
6 import java.util.Properties; 6 import java.util.Properties;
7 7
8 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
9 import org.apache.log4j.PropertyConfigurator; 9 import org.apache.log4j.PropertyConfigurator;
10
11 import jargs.gnu.CmdLineParser;
10 12
11 import java.net.MalformedURLException; 13 import java.net.MalformedURLException;
12 14
13 import de.intevation.mxd.reader.IReader; 15 import de.intevation.mxd.reader.IReader;
14 import de.intevation.mxd.reader.MXDReader; 16 import de.intevation.mxd.reader.MXDReader;
49 51
50 /** 52 /**
51 * Entrypoint for the application. 53 * Entrypoint for the application.
52 */ 54 */
53 public static void main(String[] args) { 55 public static void main(String[] args) {
56 CmdLineParser parser = new CmdLineParser();
57 CmdLineParser.Option mxd = parser.addStringOption('m', "mxd");
58 CmdLineParser.Option map = parser.addStringOption('a', "map");
59 CmdLineParser.Option temp = parser.addStringOption('t', "template");
60
61 try{
62 parser.parse(args);
63 }
64 catch(CmdLineParser.OptionException oe) {
65 logger.warn("Invalid options.");
66 printUsage();
67 System.exit(1);
68 }
69
54 try{ 70 try{
55 String mxdfile = ""; 71 String mxdfile = "";
56 String mapfile = ""; 72 String mapfile = "";
57 String maptemplate = ""; 73 String maptemplate = "";
58 int ndx = 0;
59 if (args.length > 0) {
60 if (args[0].equals("-mxd") && args.length >= 2) {
61 mxdfile = args[1];
62 ndx = 2;
63 }
64 }
65 if (args.length >= ndx + 2) {
66 if (args[ndx].equals("-map")) {
67 mapfile = args[ndx+1];
68 ndx += 2;
69 }
70 }
71 if (args.length >= ndx + 2) {
72 if (args[ndx].equals("-template")) {
73 maptemplate = args[ndx+1];
74 ndx += 2;
75 }
76 }
77 74
78 if(mxdfile.equals("")) { 75 mxdfile = (String)parser.getOptionValue(mxd);
76 mapfile = (String)parser.getOptionValue(map);
77 maptemplate = (String)parser.getOptionValue(temp);
78
79 if(mxdfile == null) {
79 try { 80 try {
80 mxdfile = readProperty("mxd"); 81 mxdfile = readProperty("mxd");
81 } 82 }
82 catch(Exception e) { 83 catch(Exception e) {
83 e.printStackTrace (); 84 e.printStackTrace ();
84 } 85 }
85 } 86 }
86 if(mapfile.equals("")) { 87 if(mapfile == null) {
87 try { 88 try {
88 mapfile = readProperty("map"); 89 mapfile = readProperty("map");
89 } 90 }
90 catch(Exception e) { 91 catch(Exception e) {
91 e.printStackTrace (); 92 e.printStackTrace ();
92 } 93 }
93 } 94 }
94 if(maptemplate.equals("")) { 95 if(maptemplate == null) {
95 try { 96 try {
96 maptemplate = readProperty("map-template"); 97 maptemplate = readProperty("map-template");
97 } 98 }
98 catch(Exception e) { 99 catch(Exception e) {
99 e.printStackTrace (); 100 e.printStackTrace ();
110 writer.write(reader.getMapDocument()); 111 writer.write(reader.getMapDocument());
111 reader.shutdown(); 112 reader.shutdown();
112 } 113 }
113 catch(Exception e) { 114 catch(Exception e) {
114 logger.error(e.getMessage()); 115 logger.error(e.getMessage());
116 e.printStackTrace();
115 } 117 }
116 } 118 }
117 119
118 private static String readProperty (String key) 120 private static String readProperty (String key)
119 throws Exception { 121 throws Exception {
141 mue.printStackTrace(System.err); 143 mue.printStackTrace(System.err);
142 } 144 }
143 } 145 }
144 } 146 }
145 147
148
149 private static void printUsage() {
150 System.out.println("Available parameters:[{-m,--mxd} path/to/mxd]\n" +
151 "\t\t[{-a,--map} path/to/mapfile]\n" +
152 "\t\t[{-t,--template} path/to/template]");
153 }
146 } 154 }
147 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 155 // 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)