Mercurial > mxd2map
comparison 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 |
comparison
equal
deleted
inserted
replaced
53:691864097eb1 | 55:f0c02ff120d6 |
---|---|
1 package de.intevation.mxd; | 1 package de.intevation.mxd; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.io.File; | 4 import java.io.File; |
5 import java.io.FileInputStream; | |
6 import java.io.BufferedInputStream; | |
7 import java.util.Properties; | |
5 | 8 |
6 import org.apache.log4j.Logger; | 9 import org.apache.log4j.Logger; |
7 import org.apache.log4j.PropertyConfigurator; | 10 import org.apache.log4j.PropertyConfigurator; |
8 | 11 |
9 import java.net.MalformedURLException; | 12 import java.net.MalformedURLException; |
44 logger = Logger.getLogger(Converter.class); | 47 logger = Logger.getLogger(Converter.class); |
45 } | 48 } |
46 | 49 |
47 | 50 |
48 /** | 51 /** |
52 * Entrypoint for the application. | |
53 */ | |
54 public static void main(String[] args) { | |
55 try{ | |
56 String mxdfile = ""; | |
57 String mapfile = ""; | |
58 String maptemplate = ""; | |
59 int ndx = 0; | |
60 if (args.length > 0) { | |
61 if (args[0].equals("-mxd") && args.length >= 2) { | |
62 mxdfile = args[1]; | |
63 ndx = 2; | |
64 } | |
65 } | |
66 if (args.length >= ndx + 2) { | |
67 if (args[ndx].equals("-map")) { | |
68 mapfile = args[ndx+1]; | |
69 ndx += 2; | |
70 } | |
71 } | |
72 if (args.length >= ndx + 2) { | |
73 if (args[ndx].equals("-template")) { | |
74 maptemplate = args[ndx+1]; | |
75 ndx += 2; | |
76 } | |
77 } | |
78 | |
79 if(mxdfile.equals("")) { | |
80 try { | |
81 mxdfile = readProperty("mxd"); | |
82 } | |
83 catch(Exception e) { | |
84 e.printStackTrace (); | |
85 } | |
86 } | |
87 if(mapfile.equals("")) { | |
88 try { | |
89 mapfile = readProperty("map"); | |
90 } | |
91 catch(Exception e) { | |
92 e.printStackTrace (); | |
93 } | |
94 } | |
95 if(maptemplate.equals("")) { | |
96 try { | |
97 maptemplate = readProperty("map-template"); | |
98 } | |
99 catch(Exception e) { | |
100 e.printStackTrace (); | |
101 } | |
102 } | |
103 | |
104 IReader reader = new MXDReader(); | |
105 reader.init(); | |
106 reader.setFilename(mxdfile); | |
107 reader.read(); | |
108 | |
109 IWriter writer = new MapScriptWriter(maptemplate, mapfile); | |
110 writer.write(reader.getMapDocument()); | |
111 reader.shutdown(); | |
112 } | |
113 catch(IOException e) { | |
114 e.printStackTrace(); | |
115 } | |
116 } | |
117 | |
118 private static String readProperty (String key) | |
119 throws Exception { | |
120 Properties properties = new Properties(); | |
121 BufferedInputStream stream = | |
122 new BufferedInputStream( | |
123 new FileInputStream("converter.properties") | |
124 ); | |
125 properties.load(stream); | |
126 stream.close(); | |
127 return properties.getProperty(key); | |
128 } | |
129 /** | |
49 * Trys to load the Log4j configuration | 130 * Trys to load the Log4j configuration |
50 * from ${config.dir}/log4j.properties. | 131 * from ${config.dir}/log4j.properties. |
51 */ | 132 */ |
52 public static final void configureLogging() { | 133 public static final void configureLogging() { |
53 File configDir = new File(CONFIG_PATH); | 134 File configDir = new File(CONFIG_PATH); |
60 mue.printStackTrace(System.err); | 141 mue.printStackTrace(System.err); |
61 } | 142 } |
62 } | 143 } |
63 } | 144 } |
64 | 145 |
65 /** | |
66 * Entrypoint for the application. | |
67 */ | |
68 public static void main(String[] args) { | |
69 try{ | |
70 | |
71 IReader reader = new MXDReader(); | |
72 IWriter writer = new MapScriptWriter(); | |
73 reader.init(); | |
74 | |
75 String path = System.getProperty("mxd.file"); | |
76 if (path.equals("${MXDFILE}")) { | |
77 System.out.println("No valid MXD file. Use ant parameter" + | |
78 " \"-DMXDFILE=path/to/file.mxd\"."); | |
79 System.exit(-1); | |
80 } | |
81 reader.setFilename(path); | |
82 | |
83 reader.read(); | |
84 writer.write(reader.getMapDocument()); | |
85 reader.shutdown(); | |
86 } | |
87 catch(IOException e) { | |
88 e.printStackTrace(); | |
89 } | |
90 } | |
91 } | 146 } |
92 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 147 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |