comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java @ 3660:976ead36192d

backend: Mention backend warnings in importer. flys-backend/trunk@5254 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 Aug 2012 17:13:47 +0000
parents 36edf9a71cbd
children e8381265871f
comparison
equal deleted inserted replaced
3659:36edf9a71cbd 3660:976ead36192d
232 } 232 }
233 233
234 public boolean parse(File file) { 234 public boolean parse(File file) {
235 235
236 if (!(file.isFile() && file.canRead())) { 236 if (!(file.isFile() && file.canRead())) {
237 log.warn("cannot open file '" + file + "'"); 237 log.warn("PRF: cannot open file '" + file + "'");
238 return false; 238 return false;
239 } 239 }
240 240
241 log.info("parsing PRF file: '" + file + "'"); 241 log.info("parsing PRF file: '" + file + "'");
242 242
265 new FileInputStream(file), ENCODING)); 265 new FileInputStream(file), ENCODING));
266 266
267 String line = in.readLine(); 267 String line = in.readLine();
268 268
269 if (line == null || (line = line.trim()).length() == 0) { 269 if (line == null || (line = line.trim()).length() == 0) {
270 log.warn("file is empty."); 270 log.warn("PRF: file is empty.");
271 return false; 271 return false;
272 } 272 }
273 273
274 Matcher m = DATA_PATTERN.matcher(line); 274 Matcher m = DATA_PATTERN.matcher(line);
275 275
276 if (!m.matches()) { 276 if (!m.matches()) {
277 log.warn("First line does not look like a PRF data pattern."); 277 log.warn("PRF: First line does not look like a PRF data pattern.");
278 return false; 278 return false;
279 } 279 }
280 280
281 DataFormat dataFormat = new DataFormat(m); 281 DataFormat dataFormat = new DataFormat(m);
282 282
283 if ((line = in.readLine()) == null 283 if ((line = in.readLine()) == null
284 || (line = line.trim()).length() == 0) { 284 || (line = line.trim()).length() == 0) {
285 log.warn("premature EOF. Expected integer in line 2"); 285 log.warn("PRF: premature EOF. Expected integer in line 2");
286 return false; 286 return false;
287 } 287 }
288 288
289 try { 289 try {
290 if (Integer.parseInt(line) != dataFormat.maxRepetitions) { 290 if (Integer.parseInt(line) != dataFormat.maxRepetitions) {
291 log.warn("Expected " + 291 log.warn("PRF: Expected " +
292 dataFormat.maxRepetitions + " in line 2"); 292 dataFormat.maxRepetitions + " in line 2");
293 return false; 293 return false;
294 } 294 }
295 } 295 }
296 catch (NumberFormatException nfe) { 296 catch (NumberFormatException nfe) {
297 log.warn("invalid integer in line 2", nfe); 297 log.warn("PRF: invalid integer in line 2", nfe);
298 return false; 298 return false;
299 } 299 }
300 300
301 if ((line = in.readLine()) == null) { 301 if ((line = in.readLine()) == null) {
302 log.warn( 302 log.warn(
303 "premature EOF. Expected pattern for km extraction"); 303 "PRF: premature EOF. Expected pattern for km extraction");
304 return false; 304 return false;
305 } 305 }
306 306
307 m = KM_PATTERN.matcher(line); 307 m = KM_PATTERN.matcher(line);
308 308
309 if (!m.matches()) { 309 if (!m.matches()) {
310 log.warn( 310 log.warn(
311 "line 4 does not look like a PRF km extraction pattern."); 311 "PRF: line 4 does not look like a PRF km extraction pattern.");
312 return false; 312 return false;
313 } 313 }
314 314
315 KMFormat kmFormat = new KMFormat(m); 315 KMFormat kmFormat = new KMFormat(m);
316 316
317 if ((line = in.readLine()) == null 317 if ((line = in.readLine()) == null
318 || (line = line.trim()).length() == 0) { 318 || (line = line.trim()).length() == 0) {
319 log.warn("premature EOF. Expected skip row count."); 319 log.warn("PRF: premature EOF. Expected skip row count.");
320 return false; 320 return false;
321 } 321 }
322 322
323 int lineSkipCount; 323 int lineSkipCount;
324 try { 324 try {
326 throw new IllegalArgumentException(lineSkipCount + " < 0"); 326 throw new IllegalArgumentException(lineSkipCount + " < 0");
327 } 327 }
328 } 328 }
329 catch (NumberFormatException nfe) { 329 catch (NumberFormatException nfe) {
330 log.warn( 330 log.warn(
331 "line 5 is not an positive integer."); 331 "PRF: line 5 is not an positive integer.");
332 return false; 332 return false;
333 } 333 }
334 334
335 int skip = lineSkipCount; 335 int skip = lineSkipCount;
336 336
342 double km; 342 double km;
343 try { 343 try {
344 km = kmFormat.extractKm(line); 344 km = kmFormat.extractKm(line);
345 } 345 }
346 catch (NumberFormatException iae) { 346 catch (NumberFormatException iae) {
347 log.warn("cannot extract km in line + " + in.getLineNumber()); 347 log.warn("PRF: cannot extract km in line " + in.getLineNumber());
348 return false; 348 return false;
349 } 349 }
350 350
351 Double station = Double.valueOf(km); 351 Double station = Double.valueOf(km);
352 352

http://dive4elements.wald.intevation.org