1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
package org.webmacro.engine; |
25 | |
|
26 | |
import org.slf4j.Logger; |
27 | |
import org.slf4j.LoggerFactory; |
28 | |
import org.webmacro.Broker; |
29 | |
import org.webmacro.Context; |
30 | |
import org.webmacro.PropertyException; |
31 | |
import org.webmacro.util.Settings; |
32 | |
|
33 | |
import java.util.ArrayList; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public class DebugEvaluationExceptionHandler implements EvaluationExceptionHandler |
64 | |
{ |
65 | |
|
66 | 0 | static Logger _log = LoggerFactory.getLogger(DebugEvaluationExceptionHandler.class); |
67 | |
|
68 | |
public DebugEvaluationExceptionHandler () |
69 | 0 | { |
70 | 0 | } |
71 | |
|
72 | |
public DebugEvaluationExceptionHandler (Broker b) |
73 | 0 | { |
74 | 0 | init(b, b.getSettings()); |
75 | 0 | } |
76 | |
|
77 | |
public void init (Broker b, Settings config) |
78 | |
{ |
79 | 0 | } |
80 | |
|
81 | |
public void evaluate (Variable variable, Context context, Exception problem) throws PropertyException |
82 | |
{ |
83 | 0 | handleError(variable, context, problem); |
84 | 0 | } |
85 | |
|
86 | |
public String expand (Variable variable, Context context, Exception problem) throws PropertyException |
87 | |
{ |
88 | 0 | return handleError(variable, context, problem); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
private String handleError (Variable variable, Context context, Exception problem) throws PropertyException |
93 | |
{ |
94 | |
String strError; |
95 | |
|
96 | 0 | ArrayList arlErrors = null; |
97 | 0 | PropertyException propEx = null; |
98 | 0 | if (problem instanceof PropertyException) |
99 | |
{ |
100 | 0 | propEx = (PropertyException) problem; |
101 | |
} |
102 | |
else |
103 | |
{ |
104 | 0 | propEx = new PropertyException("Error expanding $" + variable.getVariableName()); |
105 | |
} |
106 | 0 | propEx.setContextLocation(context.getCurrentLocation()); |
107 | 0 | strError = propEx.getMessage(); |
108 | |
|
109 | 0 | if ((context.containsKey("WMERROR")) && (context.get("WMERROR") instanceof ArrayList)) |
110 | |
{ |
111 | 0 | arlErrors = (ArrayList) context.get("WMERROR"); |
112 | |
} |
113 | |
else |
114 | |
{ |
115 | 0 | arlErrors = new ArrayList(); |
116 | 0 | context.put("WMERROR", arlErrors); |
117 | |
} |
118 | |
|
119 | 0 | if (strError.lastIndexOf("\r\n") >= 0) |
120 | |
{ |
121 | 0 | strError = strError.substring(strError.lastIndexOf("\r\n")); |
122 | 0 | strError = strError.trim(); |
123 | |
} |
124 | |
|
125 | 0 | if (!arlErrors.contains(strError)) |
126 | |
{ |
127 | 0 | arlErrors.add(strError); |
128 | |
} |
129 | |
|
130 | 0 | if (_log != null) |
131 | |
{ |
132 | 0 | _log.warn(strError, propEx); |
133 | |
} |
134 | |
|
135 | 0 | throw propEx; |
136 | |
} |
137 | |
|
138 | |
|
139 | |
public String warningString (String strText) throws PropertyException |
140 | |
{ |
141 | 0 | throw new PropertyException("Evaluation warning: " + strText); |
142 | |
} |
143 | |
|
144 | |
|
145 | |
public String errorString (String strText) throws PropertyException |
146 | |
{ |
147 | 0 | throw new PropertyException("Evaluation error: " + strText); |
148 | |
} |
149 | |
} |
150 | |
|