[Dive4elements-commits] [PATCH] Backend: First steps to integrate parsing of official config files

Wald Commits scm-commit at wald.intevation.org
Fri Jun 14 13:02:04 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1371207686 -7200
# Node ID b2a470c148a7ee4fb0a5b609b901eec57043167a
# Parent  9231940bd1923732d2e5f5b559dc5705c18728eb
Backend: First steps to integrate parsing of official config files.

diff -r 9231940bd192 -r b2a470c148a7 backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Fri Jun 14 12:32:28 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Fri Jun 14 13:01:26 2013 +0200
@@ -24,6 +24,7 @@
 import org.dive4elements.river.importer.parsers.HYKParser;
 import org.dive4elements.river.importer.parsers.MeasurementStationsParser;
 import org.dive4elements.river.importer.parsers.MorphologicalWidthParser;
+import org.dive4elements.river.importer.parsers.OfficialLinesConfigParser;
 import org.dive4elements.river.importer.parsers.PRFParser;
 import org.dive4elements.river.importer.parsers.PegelGltParser;
 import org.dive4elements.river.importer.parsers.SQRelationParser;
@@ -75,6 +76,9 @@
     public static final String OFFICIAL_LINES =
         "Amtl_Linien.wst";
 
+    public static final String OFFICIAL_LINES_CONFIG =
+        "Amtl_Linien.config";
+
     public static final String FLOOD_WATER = "HW-Marken";
 
     public static final String FLOOD_PROTECTION =
@@ -793,6 +797,28 @@
             ImportWst iw = wstParser.getWst();
             iw.setKind(3);
             iw.setDescription(folder + "/" + iw.getDescription());
+
+            File configFile = FileTools.repair(new File(dir, OFFICIAL_LINES_CONFIG));
+            if (!configFile.isFile() || !configFile.canRead()) {
+                log.warn("no config file for official lines found");
+            }
+            else {
+                OfficialLinesConfigParser olcp = new OfficialLinesConfigParser();
+                try {
+                    olcp.parse(configFile);
+                }
+                catch (IOException ioe) {
+                    log.warn("Error reading offical lines config", ioe);
+                }
+                List<String> mainValueNames = olcp.getMainValueNames();
+                if (mainValueNames.isEmpty()) {
+                    log.warn("config file for offical lines contains no entries");
+                }
+                else {
+                    // TODO: Join against main values.
+                }
+            }
+
             officialLines.add(iw);
         } // for all folders
 
diff -r 9231940bd192 -r b2a470c148a7 backend/src/main/java/org/dive4elements/river/importer/parsers/OfficialLinesConfigParser.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/OfficialLinesConfigParser.java	Fri Jun 14 13:01:26 2013 +0200
@@ -0,0 +1,64 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.importer.parsers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+public class OfficialLinesConfigParser {
+
+    private static Logger log = Logger.getLogger(OfficialLinesConfigParser.class);
+
+    public static final String ENCODING = "ISO-8859-1";
+
+    private List<String> mainValueNames;
+
+    public OfficialLinesConfigParser() {
+        mainValueNames = new ArrayList<String>();
+    }
+
+    public void reset() {
+        mainValueNames.clear();
+    }
+
+    public void parse(File file) throws IOException {
+
+        log.info("Parsing offical lines config file: " + file);
+
+        LineNumberReader reader =
+            new LineNumberReader(
+            new InputStreamReader(
+            new FileInputStream(file), ENCODING));
+
+        try {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                if ((line = line.trim()).length() == 0 || line.charAt(0) == '*') {
+                    continue;
+                }
+                mainValueNames.add(line);
+            }
+        }
+        finally {
+            reader.close();
+        }
+    }
+
+    public List<String> getMainValueNames() {
+        return mainValueNames;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list