]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpsbabel/GpsBabelCall.java
Improve GPX importer
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.gis / src / main / java / org / argeo / slc / gpsbabel / GpsBabelCall.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.gpsbabel;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.argeo.slc.SlcException;
23 import org.argeo.slc.core.execution.tasks.SystemCall;
24 import org.springframework.beans.factory.InitializingBean;
25
26 public class GpsBabelCall extends SystemCall implements InitializingBean {
27 private String executable = "/usr/bin/gpsbabel";
28 private String inputFormat;
29 private String inputFile;
30 private String outputFormat;
31 private String outputFile;
32
33 public GpsBabelCall() {
34 super();
35 }
36
37 public GpsBabelCall(String inputFormat, String inputFile,
38 String outputFormat, String outputFile) {
39 super();
40 this.inputFormat = inputFormat;
41 this.inputFile = inputFile;
42 this.outputFormat = outputFormat;
43 this.outputFile = outputFile;
44 try {
45 afterPropertiesSet();
46 } catch (Exception e) {
47 throw new SlcException("Cannot configure gpsbabel call", e);
48 }
49 }
50
51 public void afterPropertiesSet() throws Exception {
52 List<Object> command = new ArrayList<Object>();
53 command.add(executable);
54 command.add("-i");
55 command.add(inputFormat);
56 command.add("-f");
57 command.add(inputFile);
58 command.add("-o");
59 command.add(outputFormat);
60 command.add("-F");
61 command.add(outputFile);
62 setCommand(command);
63
64 setStdOutLogLevel(LOG_STDOUT);
65 setExceptionOnFailed(true);
66 }
67
68 public final static void main(String[] args) {
69 String output = new GpsBabelCall("garmin,get_posn", "usb:", "csv", "-")
70 .function();
71 System.out.println("output='" + output + "'");
72 }
73 }