comparison 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
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.wsplgen;
2
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
5
6 import org.apache.log4j.Logger;
7
8 import org.dive4elements.river.artifacts.model.map.WSPLGENCalculation;
9 import org.dive4elements.river.artifacts.model.map.WSPLGENJob;
10
11
12 public class ProblemObserver extends JobObserver {
13
14 private static Logger logger = Logger.getLogger(ProblemObserver.class);
15
16
17 public static final Pattern WSPLGEN_ERROR_START = Pattern.compile(
18 ".*->(.*Fehler)(\\s*\\((\\d+)\\).*)*",
19 Pattern.DOTALL);
20
21 public static final Pattern WSPLGEN_ERROR_END = Pattern.compile(
22 ".*<-(.*Fehler).*",
23 Pattern.DOTALL);
24
25 public static final Pattern WSPLGEN_WARNING_START = Pattern.compile(
26 ".*->Warnung\\s*\\((\\d+)\\).*",
27 Pattern.DOTALL);
28
29 public static final Pattern WSPLGEN_WARNING_END = Pattern.compile(
30 ".*<-Warnung .*",
31 Pattern.DOTALL);
32
33
34 protected int error;
35 protected int warning;
36
37 protected WSPLGENCalculation calculation;
38
39
40 public ProblemObserver(WSPLGENJob job) {
41 super(job);
42 error = -1;
43 warning = -1;
44 calculation = job.getCalculation();
45 }
46
47
48 public void run() {
49 logger.debug("Start observation...");
50
51 super.run();
52 }
53
54
55 @Override
56 protected void prepareRegexes() {
57 // do nothing
58 }
59
60
61 @Override
62 protected void update(String log) {
63 Matcher startError = WSPLGEN_ERROR_START.matcher(log);
64 if (startError.matches()) {
65 if (startError.groupCount() >= 2) {
66 String tmp = startError.group(3);
67
68 if (tmp != null && tmp.length() > 0) {
69 error = Integer.parseInt(tmp);
70 }
71 else error = 1;
72 }
73 else {
74 error = 1;
75 }
76
77 return;
78 }
79
80 Matcher endError = WSPLGEN_ERROR_END.matcher(log);
81 if (endError.matches()) {
82 error = -1;
83 }
84
85 if (error > 0) {
86 calculation.addError(new Integer(error), log);
87 }
88
89 Matcher startWarning = WSPLGEN_WARNING_START.matcher(log);
90 if (startWarning.matches()) {
91 warning = Integer.parseInt(startWarning.group(1));
92 return;
93 }
94
95 Matcher endWarning = WSPLGEN_WARNING_END.matcher(log);
96 if (endWarning.matches()) {
97 warning = -1;
98 }
99
100 if (warning > 0) {
101 calculation.addWarning(new Integer(warning), log);
102 }
103 }
104
105
106 public int numErrors() {
107 return calculation.numErrors();
108 }
109
110
111 public int numWarnings() {
112 return calculation.numWarnings();
113 }
114 }
115 // vim:set ts=4 sw=4 si et sta sts=5 fenc=utf-8 :

http://dive4elements.wald.intevation.org