Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/parsers/StaFileParser.java @ 5825:f529495f901d
moved directories to org.dive4elements.river.etl
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:42:54 +0200 |
parents | 54077c9c9305 |
children |
rev | line source |
---|---|
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer.parsers; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.File; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.io.IOException; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.io.LineNumberReader; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.io.FileInputStream; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.io.InputStreamReader; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import java.math.BigDecimal; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.regex.Pattern; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.util.regex.Matcher; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
14 import java.util.Date; |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.util.HashMap; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import java.util.ArrayList; |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
17 import java.util.List; |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.apache.log4j.Logger; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.flys.importer.ImportMainValueType; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.importer.ImportMainValue; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.flys.importer.ImportNamedMainValue; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.flys.importer.ImportGauge; |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
25 import de.intevation.flys.importer.ImportTimeInterval; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
26 import de.intevation.flys.utils.DateGuesser; |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public class StaFileParser |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 private static Logger log = Logger.getLogger(StaFileParser.class); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public static final String ENCODING = "ISO-8859-1"; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 public static final String TYPES = |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 System.getProperty("flys.backend.main.value.types", "QWTD"); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
5176
6553c8e364db
import gauge number by default (made by S. Teichmann)
Tom Gottfried <tom@intevation.de>
parents:
3660
diff
changeset
|
37 public static final boolean NOT_PARSE_GAUGE_NUMBERS = |
6553c8e364db
import gauge number by default (made by S. Teichmann)
Tom Gottfried <tom@intevation.de>
parents:
3660
diff
changeset
|
38 Boolean.getBoolean("flys.backend.sta.not.parse.gauge.numbers"); |
2377
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
39 |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 public static final Pattern QWTD_ = |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 Pattern.compile("\\s*([^\\s]+)\\s+([^\\s]+)\\s+([" + |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Pattern.quote(TYPES) + "]).*"); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
44 public static final class NameAndTimeInterval { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
45 private String name; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
46 private ImportTimeInterval timeInterval; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
47 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
48 public NameAndTimeInterval(String name) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
49 this(name, null); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
50 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
51 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
52 public NameAndTimeInterval(String name, ImportTimeInterval timeInterval) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
53 this.name = name; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
54 this.timeInterval = timeInterval; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
55 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
56 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
57 public String getName() { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
58 return name; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
59 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
60 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
61 public ImportTimeInterval getTimeInterval() { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
62 return timeInterval; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
63 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
64 } // class NameAndTimeInterval |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
65 |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 public StaFileParser() { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 public boolean parse(ImportGauge gauge) throws IOException { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 File file = gauge.getStaFile(); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 log.info("parsing STA file: " + file); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 LineNumberReader in = null; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 try { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 in = |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 new LineNumberReader( |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 new InputStreamReader( |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 new FileInputStream(file), ENCODING)); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 String line = in.readLine(); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 if (line == null) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 log.warn("STA file is empty."); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 return false; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 if (line.length() < 37) { |
3660
976ead36192d
backend: Mention backend warnings in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2377
diff
changeset
|
89 log.warn("First line in STA file is too short."); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 return false; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
2377
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
92 |
5691
dc2daadbdd0c
StaFileParser: use correct substring for gauge name
Tom Gottfried <tom@intevation.de>
parents:
5632
diff
changeset
|
93 String gaugeName = line.substring(16, 28).trim(); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
2371
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
95 Long gaugeNumber = null; |
2377
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
96 |
5176
6553c8e364db
import gauge number by default (made by S. Teichmann)
Tom Gottfried <tom@intevation.de>
parents:
3660
diff
changeset
|
97 if (!NOT_PARSE_GAUGE_NUMBERS) { |
5632
33aa0d152f54
StaFileParser: take correct substring for gauge number
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5176
diff
changeset
|
98 String gaugeNumberString = line.substring(8, 16).trim(); |
2377
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
99 |
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
100 try { |
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
101 gaugeNumber = Long.parseLong(gaugeNumberString); |
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
102 } |
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
103 catch (NumberFormatException nfe) { |
3660
976ead36192d
backend: Mention backend warnings in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2377
diff
changeset
|
104 log.warn("STA: '" + gaugeNumberString + |
2377
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
105 "' is not a valid long number."); |
d183ae164cfc
Make parsing of official numbers out of STA files being enabled with new system property.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2371
diff
changeset
|
106 } |
2371
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
107 } |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
108 |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
109 gauge.setName(gaugeName); |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
110 gauge.setOfficialNumber(gaugeNumber); |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
111 |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
112 if (log.isDebugEnabled()) { |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
113 log.debug( |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
114 "name/number: '" + gaugeName + "' '" + gaugeNumber + "'"); |
fe89d6cf55fb
Added support for official gauge numbers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1211
diff
changeset
|
115 } |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 String [] values = line.substring(38).trim().split("\\s+", 2); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 if (values.length < 2) { |
3660
976ead36192d
backend: Mention backend warnings in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2377
diff
changeset
|
120 log.warn("STA: Not enough columns for aeo and datum."); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 try { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 gauge.setAeo(new BigDecimal(values[0].replace(",", "."))); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 gauge.setDatum(new BigDecimal(values[1].replace(",", "."))); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 catch (NumberFormatException nfe) { |
3660
976ead36192d
backend: Mention backend warnings in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2377
diff
changeset
|
127 log.warn("STA: cannot parse aeo or datum."); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 return false; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 line = in.readLine(); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 if (line == null) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 log.warn("STA file has not enough lines"); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 return false; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 if (line.length() < 36) { |
3660
976ead36192d
backend: Mention backend warnings in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2377
diff
changeset
|
139 log.warn("STA: second line is too short"); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 return false; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 try { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 gauge.setStation( |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 new BigDecimal(line.substring(29, 36).trim())); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 catch (NumberFormatException nfe) { |
3660
976ead36192d
backend: Mention backend warnings in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2377
diff
changeset
|
148 log.warn("STA: parsing of the datum of the gauge failed"); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 return false; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 // overread the next six lines |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 for (int i = 0; i < 6; ++i) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 if ((line = in.readLine()) == null) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 log.warn("STA file is too short"); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 return false; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 HashMap<String, ImportMainValueType> types = |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 new HashMap<String, ImportMainValueType>(); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 ArrayList<ImportNamedMainValue> namedMainValues = |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 new ArrayList<ImportNamedMainValue>(); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 ArrayList<ImportMainValue> mainValues = |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 new ArrayList<ImportMainValue>(); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 while ((line = in.readLine()) != null) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 Matcher m = QWTD_.matcher(line); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 if (m.matches()) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 BigDecimal value; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 try { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 value = new BigDecimal(m.group(2).replace(",", ".")); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 catch (NumberFormatException nfe) { |
3660
976ead36192d
backend: Mention backend warnings in importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2377
diff
changeset
|
177 log.warn("STA: value not parseable in line " |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 + in.getLineNumber()); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 continue; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 String typeString = m.group(3); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 log.debug("\t type: " + typeString); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 ImportMainValueType type = types.get(typeString); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 if (type == null) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 type = new ImportMainValueType(typeString); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 types.put(typeString, type); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 String name = m.group(1); |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
189 NameAndTimeInterval nat = parseName(name); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 ImportNamedMainValue namedMainValue = |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
191 new ImportNamedMainValue(type, nat.getName()); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 namedMainValues.add(namedMainValue); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
194 ImportMainValue mainValue = new ImportMainValue( |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
195 gauge, |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
196 namedMainValue, |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
197 value, |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
198 nat.getTimeInterval()); |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 mainValues.add(mainValue); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 else { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 // TODO: treat as a comment |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 gauge.setMainValueTypes( |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 new ArrayList<ImportMainValueType>(types.values())); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 gauge.setNamedMainValues(namedMainValues); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 gauge.setMainValues(mainValues); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 finally { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 if (in != null) { |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 in.close(); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 log.info("finished parsing STA file: " + file); |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 return true; |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 } |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
219 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
220 protected NameAndTimeInterval parseName(String name) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
221 List<String> result = new ArrayList<String>(); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
222 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
223 unbracket(name, 0, result); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
224 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
225 int length = result.size(); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
226 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
227 if (length < 1) { // Should not happen. |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
228 return new NameAndTimeInterval(name); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
229 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
230 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
231 if (length == 1) { // No date at all -> use first part. |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
232 return new NameAndTimeInterval(result.get(0).trim()); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
233 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
234 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
235 if (length == 2) { // e.g. W(1994) or W(1994 - 1999) |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
236 String type = result.get(0).trim(); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
237 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
238 ImportTimeInterval timeInterval = getTimeInterval( |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
239 result.get(1).trim()); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
240 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
241 if (timeInterval == null) { // No date at all. |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
242 type = name; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
243 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
244 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
245 return new NameAndTimeInterval(type, timeInterval); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
246 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
247 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
248 if (length == 3) { // e.g W(Q(1994)) or W(Q(1994 - 1999)) |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
249 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
250 String type = |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
251 result.get(0).trim() + "(" + |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
252 result.get(1).trim() + ")"; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
253 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
254 ImportTimeInterval timeInterval = getTimeInterval( |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
255 result.get(2).trim()); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
256 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
257 if (timeInterval == null) { // No date at all. |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
258 type = name; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
259 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
260 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
261 return new NameAndTimeInterval(type, timeInterval); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
262 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
263 |
5736
ab4419948655
Backend: Forgot to handle the unlikely case that there are more than 2 nested brackets in main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5735
diff
changeset
|
264 // more than 3 elements return unmodified. |
ab4419948655
Backend: Forgot to handle the unlikely case that there are more than 2 nested brackets in main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5735
diff
changeset
|
265 |
ab4419948655
Backend: Forgot to handle the unlikely case that there are more than 2 nested brackets in main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5735
diff
changeset
|
266 return new NameAndTimeInterval(name); |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
267 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
268 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
269 private static ImportTimeInterval getTimeInterval(String datePart) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
270 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
271 int minus = datePart.indexOf('-'); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
272 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
273 if (minus < 0) { // '-' not found |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
274 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
275 Date date = null; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
276 try { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
277 date = DateGuesser.guessDate(datePart); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
278 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
279 catch (IllegalArgumentException iae) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
280 log.warn("STA: Invalid date '" + datePart + "'"); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
281 return null; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
282 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
283 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
284 return new ImportTimeInterval(date); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
285 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
286 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
287 // Found '-' so we have <from> - <to> |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
288 String startPart = datePart.substring(0, minus).trim(); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
289 String endPart = datePart.substring(minus).trim(); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
290 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
291 Date startDate = null; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
292 Date endDate = null; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
293 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
294 try { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
295 startDate = DateGuesser.guessDate(startPart); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
296 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
297 catch (IllegalArgumentException iae) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
298 log.warn("STA: Invalid start date '" + startPart + "'"); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
299 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
300 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
301 try { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
302 endDate = DateGuesser.guessDate(endPart); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
303 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
304 catch (IllegalArgumentException iae) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
305 log.warn("STA: Invalid end date '" + endPart + "'"); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
306 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
307 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
308 if (startDate == null) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
309 log.warn("STA: Need start date."); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
310 return null; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
311 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
312 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
313 return new ImportTimeInterval(startDate, endDate); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
314 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
315 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
316 private static int unbracket(String s, int index, List<String> result) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
317 StringBuilder sb = new StringBuilder(); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
318 int length = s.length(); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
319 while (index < length) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
320 char c = s.charAt(index); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
321 switch (c) { |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
322 case '(': |
5738
54077c9c9305
Backend: Fix Stack overflow.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5737
diff
changeset
|
323 index = unbracket(s, index+1, result); |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
324 break; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
325 case ')': |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
326 result.add(0, sb.toString()); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
327 return index+1; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
328 default: |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
329 sb.append(c); |
5737
ce002608992d
Backend: Forget to increment index.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5736
diff
changeset
|
330 ++index; |
5735
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
331 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
332 } |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
333 result.add(0, sb.toString()); |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
334 |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
335 return index; |
c75be5205a69
Backend: Parse time intervals for main values.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5691
diff
changeset
|
336 } |
1211
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
337 } |
f08fe480092c
Moved file parsers to separate package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
338 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |