Mercurial > mxd2map
annotate src/java/de/intevation/mxd/Converter.java @ 255:5c80058c08f6
Replaced error outputs with logging messages.
author | raimund renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 15 Aug 2011 14:12:19 +0200 |
parents | df4e0946ef02 |
children | 10e0aa283217 |
rev | line source |
---|---|
243
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
1 /* |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
3 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
4 * This file is part of MXD2map. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
5 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
6 * This program is free software under the LGPL (>=v2.1) |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
7 * Read the file LICENCE.txt coming with the software for details |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
8 * or visit http://www.gnu.org/licenses/ if it does not exist. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
9 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
10 * MXD2map has been developed on behalf of the |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
12 * by Intevation GmbH. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
13 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
14 * Authors: |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
15 * Raimund Renkert <raimund.renkert@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
17 * Stephan Holl <stephan.holl@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
18 */ |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
180
diff
changeset
|
19 |
33
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
28
diff
changeset
|
20 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
|
21 |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
22 import java.io.File; |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
23 import java.io.FileInputStream; |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
24 import java.io.BufferedInputStream; |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
25 import java.util.Properties; |
25
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 import org.apache.log4j.Logger; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
28 import org.apache.log4j.PropertyConfigurator; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
29 |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
30 import jargs.gnu.CmdLineParser; |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
31 |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
32 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
|
33 |
33
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
28
diff
changeset
|
34 import de.intevation.mxd.reader.IReader; |
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
28
diff
changeset
|
35 import de.intevation.mxd.reader.MXDReader; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
34
diff
changeset
|
36 import de.intevation.mxd.writer.IWriter; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
34
diff
changeset
|
37 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
|
38 /** |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 * 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
|
40 * |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
174
diff
changeset
|
41 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
24
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 */ |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 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
|
44 |
25
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 * 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
|
47 * 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
|
48 * directory. |
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 public static final String LOG4J_PROPERTIES = "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 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
53 * |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
54 * The path of the configuration directory. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
55 */ |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
56 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
|
57 "conf"); |
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 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
60 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
61 * The logger used in this class. |
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 private static Logger logger; |
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 static { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
66 configureLogging(); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
67 logger = Logger.getLogger(Converter.class); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
68 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
69 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
70 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
71 /** |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
72 * Entrypoint for the application. |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
73 */ |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
74 public static void main(String[] args) { |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
75 CmdLineParser parser = new CmdLineParser(); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
76 CmdLineParser.Option mxd = parser.addStringOption('m', "mxd"); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
77 CmdLineParser.Option map = parser.addStringOption('a', "map"); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
78 CmdLineParser.Option temp = parser.addStringOption('t', "template"); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
79 |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
80 try{ |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
81 parser.parse(args); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
82 } |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
83 catch(CmdLineParser.OptionException oe) { |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
84 logger.warn("Invalid options."); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
85 printUsage(); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
86 System.exit(1); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
87 } |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
88 |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
89 try{ |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
90 String mxdfile = ""; |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
91 String mapfile = ""; |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
92 String maptemplate = ""; |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
93 |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
94 mxdfile = (String)parser.getOptionValue(mxd); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
95 mapfile = (String)parser.getOptionValue(map); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
96 maptemplate = (String)parser.getOptionValue(temp); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
97 |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
98 if(mxdfile == null) { |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
99 try { |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
100 mxdfile = readProperty("mxd"); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
101 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
102 catch(Exception e) { |
255
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
103 logger.warn( |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
104 "No property file found. " + |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
105 "Please provide a valid property file or append " + |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
106 "parameters for mxd file, map file and template."); |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
107 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
108 } |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
109 if(mapfile == null) { |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
110 try { |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
111 mapfile = readProperty("map"); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
112 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
113 catch(Exception e) { |
255
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
114 logger.warn( |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
115 "No property file found. " + |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
116 "Please provide a valid property file or append " + |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
117 "parameters for mxd file, map file and template."); |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
118 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
119 } |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
120 if(maptemplate == null) { |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
121 try { |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
122 maptemplate = readProperty("map-template"); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
123 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
124 catch(Exception e) { |
255
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
125 logger.warn( |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
126 "No property file found. " + |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
127 "Please provide a valid property file or append " + |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
128 "parameters for mxd file, map file and template."); |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
129 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
130 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
131 |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
132 IReader reader = new MXDReader(); |
86
e19c5eb43099
Instantiate the mapscript writer before loading the MXD file.
Raimund Renkert <rrenkert@intevation.de>
parents:
55
diff
changeset
|
133 IWriter writer = new MapScriptWriter(maptemplate, mapfile); |
e19c5eb43099
Instantiate the mapscript writer before loading the MXD file.
Raimund Renkert <rrenkert@intevation.de>
parents:
55
diff
changeset
|
134 |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
135 reader.init(); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
136 reader.setFilename(mxdfile); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
137 reader.read(); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
138 |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
139 writer.write(reader.getMapDocument()); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
140 reader.shutdown(); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
141 } |
86
e19c5eb43099
Instantiate the mapscript writer before loading the MXD file.
Raimund Renkert <rrenkert@intevation.de>
parents:
55
diff
changeset
|
142 catch(Exception e) { |
255
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
143 logger.debug(e.getMessage()); |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
144 logger.error( |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
145 "General error." + |
5c80058c08f6
Replaced error outputs with logging messages.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
146 " See logging file for more information."); |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
147 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
148 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
149 |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
150 private static String readProperty (String key) |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
151 throws Exception { |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
152 Properties properties = new Properties(); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
153 BufferedInputStream stream = |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
154 new BufferedInputStream( |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
155 new FileInputStream("converter.properties") |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
156 ); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
157 properties.load(stream); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
158 stream.close(); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
159 return properties.getProperty(key); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
160 } |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
161 /** |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
162 * Trys to load the Log4j configuration |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
163 * from ${config.dir}/log4j.properties. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
164 */ |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
165 public static final void configureLogging() { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
166 File configDir = new File(CONFIG_PATH); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
167 File propFile = new File(configDir, LOG4J_PROPERTIES); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
168 if (propFile.isFile() && propFile.canRead()) { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
169 try { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
170 PropertyConfigurator.configure(propFile.toURI().toURL()); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
171 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
172 catch (MalformedURLException mue) { |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
173 mue.printStackTrace(System.err); |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
174 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
175 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
176 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
24
diff
changeset
|
177 |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
174
diff
changeset
|
178 |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
179 private static void printUsage() { |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
180 System.out.println("Available parameters:[{-m,--mxd} path/to/mxd]\n" + |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
181 "\t\t[{-a,--map} path/to/mapfile]\n" + |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
182 "\t\t[{-t,--template} path/to/template]"); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
118
diff
changeset
|
183 } |
24
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 } |
c0060abb7457
Added source directory and an initial entry class for a MXD converter tool.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |