Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java @ 238:a157c6042cb4
ODV-export for timeseries completed.
gnv-artifacts/trunk@306 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 09 Nov 2009 13:48:50 +0000 |
parents | |
children | 3ea030aafe65 |
comparison
equal
deleted
inserted
replaced
237:56dcedc4a96c | 238:a157c6042cb4 |
---|---|
1 package de.intevation.gnv.exports; | |
2 | |
3 import java.util.List; | |
4 import java.util.ArrayList; | |
5 import java.util.Date; | |
6 import java.text.DateFormat; | |
7 import java.text.SimpleDateFormat; | |
8 | |
9 import org.apache.log4j.Logger; | |
10 | |
11 import com.vividsolutions.jts.io.WKTReader; | |
12 import com.vividsolutions.jts.io.ParseException; | |
13 import com.vividsolutions.jts.geom.Point; | |
14 | |
15 import de.intevation.gnv.geobackend.base.Result; | |
16 import de.intevation.gnv.transition.exception.TransitionException; | |
17 | |
18 /** | |
19 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | |
20 */ | |
21 public class SimpleOdvDataCollector | |
22 extends ShapeDataCollector | |
23 { | |
24 private static Logger log = Logger.getLogger(SimpleOdvDataCollector.class); | |
25 | |
26 public static final String SRC_FORMAT = "yyyy.MM.dd HH:mm:ss"; | |
27 public static final String DEST_FORMAT = "yyyy-MM-dd HH:mm"; | |
28 | |
29 public static DateFormat srcFormat = new SimpleDateFormat(SRC_FORMAT); | |
30 public static DateFormat destFormat = new SimpleDateFormat(DEST_FORMAT); | |
31 | |
32 public SimpleOdvDataCollector(String[] names) { | |
33 super(names); | |
34 } | |
35 | |
36 public String[] getData(Result result) | |
37 throws TransitionException | |
38 { | |
39 if (rd == null) | |
40 init(result); | |
41 | |
42 try { | |
43 String [] entries = new String[names.length+1]; | |
44 int j = 0; | |
45 for (int i = 0; i < names.length; i++) { | |
46 | |
47 if (names[i].equals("SHAPE")) { | |
48 Point p = (Point)wktReader.read(result.getString("SHAPE")); | |
49 | |
50 entries[j++] = ""+p.getX(); | |
51 entries[j++] = ""+p.getY(); | |
52 } | |
53 // Change the datetime format from yyyy.MM.dd HH:mm:ss to | |
54 // yyyy-MM-dd HH:mm | |
55 else if (names[i].equals("TIMEVALUE")) { | |
56 Date source = srcFormat.parse(result.getString(names[i])); | |
57 entries[j++] = destFormat.format(source); | |
58 } | |
59 else { | |
60 entries[j++] = result.getString(names[i]); | |
61 } | |
62 } | |
63 | |
64 return entries; | |
65 } | |
66 catch (ParseException pe) { | |
67 log.error(pe, pe); | |
68 throw new TransitionException( | |
69 "Error occured while parsing source data."); | |
70 } | |
71 catch (java.text.ParseException pe) { | |
72 log.error(pe, pe); | |
73 throw new TransitionException( | |
74 "Error occured while parsing source data."); | |
75 } | |
76 } | |
77 } |