annotate src/java/de/intevation/mxd/Converter.java @ 43:ef7ca23c4233

Added comments, done some code styling and removed typos.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 15 Apr 2011 15:44:54 +0200
parents 60ed2164035a
children f0c02ff120d6
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
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
6 import org.apache.log4j.Logger;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
7 import org.apache.log4j.PropertyConfigurator;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
8
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
9 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
10
33
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 28
diff changeset
11 import de.intevation.mxd.reader.IReader;
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 28
diff changeset
12 import de.intevation.mxd.reader.MXDReader;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
13 import de.intevation.mxd.writer.IWriter;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
14 import de.intevation.mxd.writer.MapScriptWriter;
24
c0060abb7457 Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 /**
c0060abb7457 Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 * 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
17 *
c0060abb7457 Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 * @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
19 */
c0060abb7457 Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 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
21
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
22 /**
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
23 * 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
24 * 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
25 * directory.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
26 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
27 public static final String LOG4J_PROPERTIES = "log4j.properties";
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
28
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 * The path of the configuration directory.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
32 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
33 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
34 "conf");
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
35
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 * The logger used in this class.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
39 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
40 private static Logger logger;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
41
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
42 static {
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
43 configureLogging();
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
44 logger = Logger.getLogger(Converter.class);
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
45 }
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 * Trys to load the Log4j configuration
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
50 * from ${config.dir}/log4j.properties.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
51 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
52 public static final void configureLogging() {
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
53 File configDir = new File(CONFIG_PATH);
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
54 File propFile = new File(configDir, LOG4J_PROPERTIES);
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
55 if (propFile.isFile() && propFile.canRead()) {
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
56 try {
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
57 PropertyConfigurator.configure(propFile.toURI().toURL());
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
58 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
59 catch (MalformedURLException mue) {
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
60 mue.printStackTrace(System.err);
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
61 }
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 * Entrypoint for the application.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
67 */
24
c0060abb7457 Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 public static void main(String[] args) {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
69 try{
28
0e71a1f71ec0 Added parameter for MXD filename.
Raimund Renkert <rrenkert@intevation.de>
parents: 25
diff changeset
70
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
71 IReader reader = new MXDReader();
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
72 IWriter writer = new MapScriptWriter();
25
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();
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
84 writer.write(reader.getMapDocument());
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
85 reader.shutdown();
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
86 }
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
87 catch(IOException e) {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
88 e.printStackTrace();
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
89 }
24
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 }
c0060abb7457 Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 // 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)