comparison flys-artifacts/src/main/java/de/intevation/flys/wsplgen/ProblemObserver.java @ 3814:8083f6384023

merged flys-artifacts/pre2.6-2012-01-04
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:56 +0200
parents 74142aa5d938
children 453d2d0c4258
comparison
equal deleted inserted replaced
1491:2a00f4849738 3814:8083f6384023
1 package de.intevation.flys.wsplgen;
2
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
5
6 import org.apache.log4j.Logger;
7
8 import de.intevation.flys.artifacts.model.WSPLGENCalculation;
9 import de.intevation.flys.artifacts.model.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