Mercurial > mxd2map
annotate src/java/de/intevation/mxd/Converter.java @ 33:c51376f8e24c
Separated converter components into packages.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 12 Apr 2011 13:20:49 +0200 |
parents | 0e71a1f71ec0 |
children | 7a927921eb6c |
rev | line source |
---|---|
33
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
28
diff
changeset
|
1 package de.intevation.mxd; |
24
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
3 import java.io.IOException; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
4 import java.io.File; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
5 import java.io.FileOutputStream; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
6 import java.io.OutputStream; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
7 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
8 import org.apache.log4j.Logger; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
9 import org.apache.log4j.PropertyConfigurator; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
10 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
11 import java.net.MalformedURLException; |
24
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
33
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
28
diff
changeset
|
13 import de.intevation.mxd.reader.IReader; |
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
28
diff
changeset
|
14 import de.intevation.mxd.reader.MXDReader; |
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
28
diff
changeset
|
15 |
24
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 /** |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 * The entry point of the MXD converter tool. |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 * |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 */ |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 public class Converter { |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
23 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
24 * The logging is done via Log4j. To configure the logging |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
25 * a file 'log4j.properties' is search in the configuration |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
26 * directory. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
27 */ |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
28 public static final String LOG4J_PROPERTIES = "log4j.properties"; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
29 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
30 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
31 * |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
32 * The path of the configuration directory. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
33 */ |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
34 public static final String CONFIG_PATH = System.getProperty("config.dir", |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
35 "conf"); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
36 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
37 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
38 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
39 * The logger used in this class. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
40 */ |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
41 private static Logger logger; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
42 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
43 static { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
44 configureLogging(); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
45 logger = Logger.getLogger(Converter.class); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
46 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
47 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
48 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
49 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
50 * Trys to load the Log4j configuration |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
51 * from ${config.dir}/log4j.properties. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
52 */ |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
53 public static final void configureLogging() { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
54 File configDir = new File(CONFIG_PATH); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
55 File propFile = new File(configDir, LOG4J_PROPERTIES); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
56 if (propFile.isFile() && propFile.canRead()) { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
57 try { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
58 PropertyConfigurator.configure(propFile.toURI().toURL()); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
59 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
60 catch (MalformedURLException mue) { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
61 mue.printStackTrace(System.err); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
62 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
63 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
64 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
65 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
66 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
67 * Entrypoint for the application. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
68 */ |
24
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 public static void main(String[] args) { |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
70 try{ |
28
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
71 |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
72 IReader reader = new MXDReader(); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
73 reader.init(); |
28
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
74 |
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
75 String path = System.getProperty("mxd.file"); |
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
76 if (path.equals("${MXDFILE}")) { |
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
77 System.out.println("No valid MXD file. Use ant parameter" + |
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
78 " \"-DMXDFILE=path/to/file.mxd\"."); |
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
79 System.exit(-1); |
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
80 } |
0e71a1f71ec0
Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents:
25
diff
changeset
|
81 reader.setFilename(path); |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
82 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
83 reader.read(); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
84 reader.shutdown(); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
85 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
86 catch(IOException e){ |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
87 e.printStackTrace(); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
88 } |
24
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 } |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 } |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |