Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java @ 1213:cc88db4a5b34
Added method
walkTree() to traverse a directory tree. To be reused in HYK parser.
flys-backend/trunk@2339 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 15 Jul 2011 15:36:59 +0000 |
parents | f08fe480092c |
children | f8b5c37f15e4 |
comparison
equal
deleted
inserted
replaced
1212:dd948530fd57 | 1213:cc88db4a5b34 |
---|---|
1 package de.intevation.flys.importer.parsers; | 1 package de.intevation.flys.importer.parsers; |
2 | 2 |
3 import java.util.Map; | 3 import java.util.Map; |
4 import java.util.Stack; | |
5 import java.util.TreeMap; | 4 import java.util.TreeMap; |
6 import java.util.List; | 5 import java.util.List; |
7 import java.util.ArrayList; | 6 import java.util.ArrayList; |
8 import java.util.Collections; | 7 import java.util.Collections; |
9 | 8 |
17 import java.io.IOException; | 16 import java.io.IOException; |
18 | 17 |
19 import org.apache.log4j.Logger; | 18 import org.apache.log4j.Logger; |
20 | 19 |
21 import de.intevation.flys.importer.XY; | 20 import de.intevation.flys.importer.XY; |
21 | |
22 import de.intevation.flys.utils.FileTools; | |
22 | 23 |
23 public class PRFParser | 24 public class PRFParser |
24 { | 25 { |
25 private static Logger log = Logger.getLogger(PRFParser.class); | 26 private static Logger log = Logger.getLogger(PRFParser.class); |
26 | 27 |
381 data.clear(); | 382 data.clear(); |
382 year = null; | 383 year = null; |
383 description = null; | 384 description = null; |
384 } | 385 } |
385 | 386 |
386 public void parsePRFs(File root, Callback callback) { | 387 public void parsePRFs(File root, final Callback callback) { |
387 | 388 |
388 Stack<File> stack = new Stack<File>(); | 389 FileTools.walkTree(root, new FileTools.FileVisitor() { |
389 stack.push(root); | 390 @Override |
390 | 391 public boolean visit(File file) { |
391 while (!stack.empty()) { | 392 if (file.isFile() |
392 File file = stack.pop(); | 393 && file.getName().toLowerCase().endsWith(".prf") |
393 if (file.isDirectory()) { | 394 && (callback == null || callback.prfAccept(file))) { |
394 File [] files = file.listFiles(); | 395 reset(); |
395 if (files != null) { | 396 boolean success = parse(file); |
396 for (File f: files) { | 397 log.info("parsing " + (success ? "succeeded" : "failed")); |
397 stack.push(f); | 398 if (success && callback != null) { |
399 callback.prfParsed(PRFParser.this); | |
398 } | 400 } |
399 } | 401 } |
400 } | 402 return true; |
401 else if (file.isFile() | 403 } |
402 && file.getName().toLowerCase().endsWith(".prf") | 404 }); |
403 && (callback == null || callback.prfAccept(file)) | |
404 ) { | |
405 reset(); | |
406 boolean success = parse(file); | |
407 log.info("parsing " + (success ? "succeeded" : "failed")); | |
408 if (success && callback != null) { | |
409 callback.prfParsed(this); | |
410 } | |
411 } | |
412 } | |
413 } | 405 } |
414 | 406 |
415 public static void main(String [] args) { | 407 public static void main(String [] args) { |
416 | 408 |
417 PRFParser parser = new PRFParser(); | 409 PRFParser parser = new PRFParser(); |