diff artifacts/src/main/java/org/dive4elements/river/wsplgen/ProblemObserver.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/wsplgen/ProblemObserver.java@bd047b71ab37
children 4897a58c8746
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/wsplgen/ProblemObserver.java	Thu Apr 25 15:23:37 2013 +0200
@@ -0,0 +1,115 @@
+package org.dive4elements.river.wsplgen;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.log4j.Logger;
+
+import org.dive4elements.river.artifacts.model.map.WSPLGENCalculation;
+import org.dive4elements.river.artifacts.model.map.WSPLGENJob;
+
+
+public class ProblemObserver extends JobObserver {
+
+    private static Logger logger = Logger.getLogger(ProblemObserver.class);
+
+
+    public static final Pattern WSPLGEN_ERROR_START = Pattern.compile(
+        ".*->(.*Fehler)(\\s*\\((\\d+)\\).*)*",
+        Pattern.DOTALL);
+
+    public static final Pattern WSPLGEN_ERROR_END = Pattern.compile(
+        ".*<-(.*Fehler).*",
+        Pattern.DOTALL);
+
+    public static final Pattern WSPLGEN_WARNING_START = Pattern.compile(
+        ".*->Warnung\\s*\\((\\d+)\\).*",
+        Pattern.DOTALL);
+
+    public static final Pattern WSPLGEN_WARNING_END = Pattern.compile(
+        ".*<-Warnung .*",
+        Pattern.DOTALL);
+
+
+    protected int error;
+    protected int warning;
+
+    protected WSPLGENCalculation calculation;
+
+
+    public ProblemObserver(WSPLGENJob job) {
+        super(job);
+        error       = -1;
+        warning     = -1;
+        calculation = job.getCalculation();
+    }
+
+
+    public void run() {
+        logger.debug("Start observation...");
+
+        super.run();
+    }
+
+
+    @Override
+    protected void prepareRegexes() {
+        // do nothing
+    }
+
+
+    @Override
+    protected void update(String log) {
+        Matcher startError = WSPLGEN_ERROR_START.matcher(log);
+        if (startError.matches()) {
+            if (startError.groupCount() >= 2) {
+                String tmp = startError.group(3);
+
+                if (tmp != null && tmp.length() > 0) {
+                    error = Integer.parseInt(tmp);
+                }
+                else error = 1;
+            }
+            else {
+                error = 1;
+            }
+
+            return;
+        }
+
+        Matcher endError = WSPLGEN_ERROR_END.matcher(log);
+        if (endError.matches()) {
+            error = -1;
+        }
+
+        if (error > 0) {
+            calculation.addError(new Integer(error), log);
+        }
+
+        Matcher startWarning = WSPLGEN_WARNING_START.matcher(log);
+        if (startWarning.matches()) {
+            warning = Integer.parseInt(startWarning.group(1));
+            return;
+        }
+
+        Matcher endWarning = WSPLGEN_WARNING_END.matcher(log);
+        if (endWarning.matches()) {
+            warning = -1;
+        }
+
+        if (warning > 0) {
+            calculation.addWarning(new Integer(warning), log);
+        }
+    }
+
+
+    public int numErrors() {
+        return calculation.numErrors();
+    }
+
+
+    public int numWarnings() {
+        return calculation.numWarnings();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=5 fenc=utf-8 :

http://dive4elements.wald.intevation.org