comparison flys-backend/src/main/java/de/intevation/flys/importer/PRFParser.java @ 1204:22858e7cca79

Integrated PRF parsing into importer. Needs testing! flys-backend/trunk@2309 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 07 Jul 2011 22:25:38 +0000
parents 7c88650ff548
children c7370734b872
comparison
equal deleted inserted replaced
1203:3c01bef43a98 1204:22858e7cca79
37 Pattern.compile("(\\d{4})"); 37 Pattern.compile("(\\d{4})");
38 38
39 public static final int MIN_YEAR = 1800; 39 public static final int MIN_YEAR = 1800;
40 public static final int MAX_YEAR = 2100; 40 public static final int MAX_YEAR = 2100;
41 41
42 public static final double X_EPSILON = 1e-4; 42 public interface Callback {
43 43 void prfParsed(PRFParser parser);
44 public interface PRFCallback { 44 } // interface Parser
45 void found(PRFParser parser);
46 } // interface PRFParser
47
48 public static final class XY
49 implements Comparable<XY>
50 {
51 protected double x;
52 protected double y;
53 protected int index;
54
55 public XY() {
56 }
57
58 public XY(double x, double y, int index) {
59 this.x = x;
60 this.y = y;
61 this.index = index;
62 }
63
64 @Override
65 public int compareTo(XY other) {
66 if (x + X_EPSILON < other.x) return -1;
67 if (x > other.x + X_EPSILON) return +1;
68 if (index < other.index) return -1;
69 if (index > other.index) return +1;
70 return 0;
71 }
72
73 public double getX() {
74 return x;
75 }
76
77 public void setX(double x) {
78 this.x = x;
79 }
80
81 public double getY() {
82 return y;
83 }
84
85 public void setY(double y) {
86 this.y = y;
87 }
88
89 public int getIndex() {
90 return index;
91 }
92
93 public void setIndex(int index) {
94 this.index = index;
95 }
96 } // class XY
97 45
98 public static class DataFormat { 46 public static class DataFormat {
99 47
100 protected int deleteChars; 48 protected int deleteChars;
101 protected int maxRepetitions; 49 protected int maxRepetitions;
430 data.clear(); 378 data.clear();
431 year = null; 379 year = null;
432 description = null; 380 description = null;
433 } 381 }
434 382
435 public static void parsePRFs(File root, PRFCallback callback) { 383 public void parsePRFs(File root, Callback callback) {
436
437 PRFParser parser = new PRFParser();
438 384
439 Stack<File> stack = new Stack<File>(); 385 Stack<File> stack = new Stack<File>();
440 stack.push(root); 386 stack.push(root);
441 387
442 while (!stack.empty()) { 388 while (!stack.empty()) {
450 } 396 }
451 } 397 }
452 else if (file.isFile() 398 else if (file.isFile()
453 && file.getName().toLowerCase().endsWith(".prf") 399 && file.getName().toLowerCase().endsWith(".prf")
454 ) { 400 ) {
455 parser.reset(); 401 reset();
456 boolean success = parser.parse(file); 402 boolean success = parse(file);
457 log.info("parsing " + (success ? "succeeded" : "failed")); 403 log.info("parsing " + (success ? "succeeded" : "failed"));
458 if (success && callback != null) { 404 if (success && callback != null) {
459 callback.found(parser); 405 callback.prfParsed(this);
460 } 406 }
461 } 407 }
462 } 408 }
463 } 409 }
464 410
465 public static void main(String [] args) { 411 public static void main(String [] args) {
466 412
413 PRFParser parser = new PRFParser();
414
467 for (String arg: args) { 415 for (String arg: args) {
468 parsePRFs(new File(arg), null); 416 parser.parsePRFs(new File(arg), null);
469 } 417 }
470 } 418 }
471 } 419 }
472 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 420 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org