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 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public class DefaultEvaluationExceptionHandler implements EvaluationExceptionHandler |
47 | |
{ |
48 | |
|
49 | 2 | static Logger _log = LoggerFactory.getLogger(DefaultEvaluationExceptionHandler.class); |
50 | |
|
51 | |
public DefaultEvaluationExceptionHandler () |
52 | 6 | { |
53 | 6 | } |
54 | |
|
55 | |
public DefaultEvaluationExceptionHandler (Broker b) |
56 | 0 | { |
57 | 0 | init(b, b.getSettings()); |
58 | 0 | } |
59 | |
|
60 | |
public void init (Broker b, Settings config) |
61 | |
{ |
62 | 6 | } |
63 | |
|
64 | |
public void evaluate (Variable variable, Context context, Exception problem) |
65 | |
throws PropertyException |
66 | |
{ |
67 | |
|
68 | |
|
69 | 0 | if (problem instanceof PropertyException) |
70 | |
{ |
71 | 0 | ((PropertyException) problem) |
72 | |
.setContextLocation(context.getCurrentLocation()); |
73 | |
} |
74 | |
else |
75 | |
{ |
76 | |
|
77 | 0 | problem = new PropertyException("Error evaluating $" |
78 | |
+ variable.getVariableName(), |
79 | |
problem, |
80 | |
context.getCurrentLocation()); |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | 0 | if (_log != null) |
86 | |
{ |
87 | 0 | _log.error(problem.getMessage()); |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | 0 | if (problem instanceof PropertyException.NoSuchVariableException |
93 | |
|| problem instanceof PropertyException.NullValueException |
94 | |
|| problem instanceof PropertyException.NullToStringException) |
95 | |
{ |
96 | |
|
97 | 0 | return; |
98 | |
} |
99 | |
else |
100 | |
{ |
101 | |
|
102 | 0 | throw (PropertyException) problem; |
103 | |
|
104 | |
} |
105 | |
} |
106 | |
|
107 | |
public String expand (Variable variable, Context context, Exception problem) |
108 | |
throws PropertyException |
109 | |
{ |
110 | |
|
111 | |
|
112 | 30 | if (problem instanceof PropertyException) |
113 | |
{ |
114 | 30 | ((PropertyException) problem) |
115 | |
.setContextLocation(context.getCurrentLocation()); |
116 | |
} |
117 | |
else |
118 | |
{ |
119 | |
|
120 | 0 | problem = new PropertyException("Error expanding $" |
121 | |
+ variable.getVariableName(), |
122 | |
problem, |
123 | |
context.getCurrentLocation()); |
124 | |
} |
125 | |
|
126 | |
|
127 | 30 | if (_log != null) |
128 | |
{ |
129 | 30 | _log.error(problem.getMessage()); |
130 | |
} |
131 | |
|
132 | |
|
133 | 30 | if (problem instanceof PropertyException.NoSuchVariableException |
134 | |
|| problem instanceof PropertyException.UndefinedVariableException |
135 | |
|| problem instanceof PropertyException.NullValueException |
136 | |
|| problem instanceof PropertyException.NullToStringException) |
137 | |
{ |
138 | |
|
139 | 30 | return errorString(problem.getMessage()); |
140 | |
} |
141 | |
else |
142 | |
{ |
143 | |
|
144 | 0 | throw (PropertyException) problem; |
145 | |
} |
146 | |
} |
147 | |
|
148 | |
|
149 | |
public String warningString (String warningText) |
150 | |
{ |
151 | 0 | return "<!-- " + warningText + " -->"; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
public String errorString (String errorText) |
156 | |
{ |
157 | 30 | return "<!-- " + errorText + " -->"; |
158 | |
} |
159 | |
} |