comparison backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadLSParser.java @ 8042:9342d7fe0ee7

Introduce LineParserException for CSV file parsing.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 16 Jul 2014 18:33:28 +0200
parents fd3a24336e6a
children bd0dea643440
comparison
equal deleted inserted replaced
8041:01ad09af0975 8042:9342d7fe0ee7
114 description = null; 114 description = null;
115 } 115 }
116 116
117 117
118 @Override 118 @Override
119 protected void handleLine(int lineNum, String line) { 119 protected void handleLine(int lineNum, String line) throws LineParserException {
120 if (line.startsWith(START_META_CHAR)) { 120 if (line.startsWith(START_META_CHAR)) {
121 handleMetaLine(stripMetaLine(line)); 121 handleMetaLine(stripMetaLine(line));
122 } 122 }
123 else { 123 else {
124 handleDataLine(line); 124 handleDataLine(line);
125 } 125 }
126 } 126 }
127 127
128 128
129 protected void handleMetaLine(String line) { 129 protected void handleMetaLine(String line) throws LineParserException {
130 if (handleMetaUnit(line)) { 130 if (handleMetaUnit(line)) {
131 return; 131 return;
132 } 132 }
133 else if (handleMetaFraction(line)) { 133 if (handleMetaFraction(line)) {
134 return; 134 return;
135 } 135 }
136 else if (handleMetaFractionName(line)) { 136 if (handleMetaFractionName(line)) {
137 return; 137 return;
138 } 138 }
139 else if (handleColumnNames(line)) { 139 if (handleColumnNames(line)) {
140 return; 140 return;
141 } 141 }
142 else { 142 log.warn("SLLSP: Unknown meta line: '" + line + "'");
143 log.warn("SLLSP: Unknown meta line: '" + line + "'");
144 }
145 } 143 }
146 144
147 145
148 protected boolean handleMetaUnit(String line) { 146 protected boolean handleMetaUnit(String line) {
149 Matcher m = META_UNIT.matcher(line); 147 Matcher m = META_UNIT.matcher(line);
219 217
220 return false; 218 return false;
221 } 219 }
222 220
223 221
224 public boolean handleColumnNames(String line) { 222 public boolean handleColumnNames(String line) throws LineParserException {
225 Matcher m = META_COLUMN_NAMES.matcher(line); 223 Matcher m = META_COLUMN_NAMES.matcher(line);
226 224
227 if (m.matches()) { 225 if (m.matches()) {
228 columnNames = line.split(SEPERATOR_CHAR); 226 columnNames = line.split(SEPERATOR_CHAR);
229 227
230 // 'Fluss-km', 'Hinweise' and at least one data column required 228 // 'Fluss-km', 'Hinweise' and at least one data column required
231 if (columnNames.length < 3) { 229 if (columnNames.length < 3) {
232 log.error("SLLSP: missing columns."); 230 throw new LineParserException("SLLSP: missing columns.");
233 return true;
234 } 231 }
235 232
236 initializeSedimentLoadLSs(); 233 initializeSedimentLoadLSs();
237 234
238 return true; 235 return true;

http://dive4elements.wald.intevation.org