Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/parsers/MorphologicalWidthParser.java @ 5792:06036bc6fb19
Add WMS URL menu entry again and print the wms_url
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 23 Apr 2013 15:30:06 +0200 |
parents | b3dd14fc13a6 |
children |
rev | line source |
---|---|
2821
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer.parsers; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.math.BigDecimal; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.text.NumberFormat; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.text.ParseException; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import java.util.ArrayList; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import java.util.List; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import java.util.regex.Matcher; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import java.util.regex.Pattern; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import org.apache.log4j.Logger; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.flys.importer.ImportMorphWidth; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.flys.importer.ImportMorphWidthValue; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.flys.importer.ImportUnit; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 public class MorphologicalWidthParser extends LineParser { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 private static final Logger log = |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 Logger.getLogger(MorphologicalWidthParser.class); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 public static final NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 public static final Pattern META_UNIT = |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 Pattern.compile("^Einheit: \\[(.*)\\].*"); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 protected List<ImportMorphWidth> morphWidths; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 protected ImportMorphWidth current; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 public MorphologicalWidthParser() { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 morphWidths = new ArrayList<ImportMorphWidth>(); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 @Override |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 protected void reset() { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 current = new ImportMorphWidth(); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 @Override |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 protected void finish() { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 if (current != null) { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 morphWidths.add(current); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 @Override |
4193
f63b39799d2d
Adapted DB schema (added relation measurement_station); improved importer to read files from filesystem with measurement stations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3662
diff
changeset
|
55 protected void handleLine(int lineNum, String line) { |
2821
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 if (line.startsWith(START_META_CHAR)) { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 handleMetaLine(stripMetaLine(line)); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 else { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 handleDataLine(line); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 protected void handleMetaLine(String line) { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 if (handleMetaUnit(line)) { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 return; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 else { |
3662
0d27d02b1208
backend: Completed the error messages of the importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2821
diff
changeset
|
70 log.warn("MWP: Unknown meta line: '" + line + "'"); |
2821
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 protected boolean handleMetaUnit(String line) { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 Matcher m = META_UNIT.matcher(line); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 if (m.matches()) { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 String unit = m.group(1); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 current.setUnit(new ImportUnit(unit)); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 return true; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 return false; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 protected void handleDataLine(String line) { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 String[] vals = line.split(SEPERATOR_CHAR); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 if (vals == null || vals.length < 2) { |
3662
0d27d02b1208
backend: Completed the error messages of the importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2821
diff
changeset
|
94 log.warn("MWP: skip invalid data line: '" + line + "'"); |
2821
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 return; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 try { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 BigDecimal km = new BigDecimal(nf.parse(vals[0]).doubleValue()); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 BigDecimal width = new BigDecimal(nf.parse(vals[1]).doubleValue()); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 String desc = vals.length > 2 ? vals[2] : null; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 current.addValue(new ImportMorphWidthValue( |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 km, |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 width, |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 desc |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 )); |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 catch (ParseException pe) { |
5490
b3dd14fc13a6
Parsers: do not call warnings error
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5016
diff
changeset
|
111 log.warn("MWP: unparseable number in data row: " + line); |
2821
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 public List<ImportMorphWidth> getMorphologicalWidths() { |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 return morphWidths; |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 } |
0a536eb5d668
Added parser for parsing morphological widths.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |