changeset 6335:b2a470c148a7

Backend: First steps to integrate parsing of official config files.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 14 Jun 2013 13:01:26 +0200
parents 9231940bd192
children c4fbd85a33ee
files backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java backend/src/main/java/org/dive4elements/river/importer/parsers/OfficialLinesConfigParser.java
diffstat 2 files changed, 90 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- /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 :

http://dive4elements.wald.intevation.org