[PATCH] WST Import: Added parse error exception to WST parser

Wald Commits scm-commit at wald.intevation.org
Tue Oct 15 18:32:04 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1381854719 -7200
# Node ID 40e5ad76103c09ad7e801b6711f5601a111428ad
# Parent  f37c7e183b5ea8c525ce74a67b64c70e65a5b8b4
WST Import: Added parse error exception to WST parser.

diff -r f37c7e183b5e -r 40e5ad76103c backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Tue Oct 15 17:39:04 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Tue Oct 15 18:31:59 2013 +0200
@@ -356,12 +356,17 @@
                 continue;
             }
             log.info("found file '" + file.getName() + "'");
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(5);
-            iw.setDescription(FLOOD_PROTECTION + "/" + iw.getDescription());
-            floodProtection.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(5);
+                iw.setDescription(FLOOD_PROTECTION + "/" + iw.getDescription());
+                floodProtection.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
     }
 
@@ -768,12 +773,17 @@
                 continue;
             }
             log.info("found file '" + file.getName() + "'");
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(4);
-            iw.setDescription(FLOOD_WATER + "/" + iw.getDescription());
-            floodWater.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(4);
+                iw.setDescription(FLOOD_WATER + "/" + iw.getDescription());
+                floodWater.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
     }
 
@@ -805,7 +815,14 @@
             ImportWst iw = new ImportWst(ImportOfficialWstColumn.COLUMN_FACTORY);
 
             WstParser wstParser = new WstParser(iw);
-            wstParser.parse(file);
+            try {
+                wstParser.parse(file);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+                continue;
+            }
+
             iw.setKind(3);
             iw.setDescription(folder + "/" + iw.getDescription());
 
@@ -878,12 +895,17 @@
             }
             log.debug("Found WST file: " + file);
 
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(2);
-            iw.setDescription(FIXATIONS+ "/" + iw.getDescription());
-            fixations.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(2);
+                iw.setDescription(FIXATIONS+ "/" + iw.getDescription());
+                fixations.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
     }
 
@@ -922,12 +944,17 @@
             }
             log.debug("Found WST file: " + file);
 
-            WstParser wstParser = new WstParser();
-            wstParser.parse(file);
-            ImportWst iw = wstParser.getWst();
-            iw.setKind(1);
-            iw.setDescription(EXTRA_LONGITUDINALS + "/" + iw.getDescription());
-            extraWsts.add(iw);
+            try {
+                WstParser wstParser = new WstParser();
+                wstParser.parse(file);
+                ImportWst iw = wstParser.getWst();
+                iw.setKind(1);
+                iw.setDescription(EXTRA_LONGITUDINALS + "/" + iw.getDescription());
+                extraWsts.add(iw);
+            }
+            catch (WstParser.ParseException e) {
+                log.error(e);
+            }
         }
 
     }
@@ -939,9 +966,14 @@
         }
 
         WstParser wstParser = new WstParser();
-        wstParser.parse(wstFile);
-        wst = wstParser.getWst();
-        wst.setKmUp(wst.guessWaterLevelIncreasing());
+        try {
+            wstParser.parse(wstFile);
+            wst = wstParser.getWst();
+            wst.setKmUp(wst.guessWaterLevelIncreasing());
+        }
+        catch (WstParser.ParseException e) {
+            log.error(e);
+        }
     }
 
     public void parseGauges() throws IOException {
diff -r f37c7e183b5e -r 40e5ad76103c backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Tue Oct 15 17:39:04 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java	Tue Oct 15 18:31:59 2013 +0200
@@ -85,6 +85,15 @@
         this.wst = wst;
     }
 
+    public static final class ParseException extends Exception {
+        public ParseException() {
+        }
+
+        public ParseException(String msg) {
+            super(msg);
+        }
+    } // class ParseException
+
     /** Returns a new ImportTimeInterval with a date guessed from string. */
     public static ImportTimeInterval guessDate(String string) {
         try {
@@ -105,7 +114,7 @@
         return null;
     }
 
-    public void parse(File file) throws IOException {
+    public void parse(File file) throws IOException, ParseException {
 
         log.info("Parsing WST file '" + file + "'");
 


More information about the Dive4elements-commits mailing list