5 |
return bless {}, shift; |
return bless {}, shift; |
6 |
} # new |
} # new |
7 |
|
|
8 |
|
sub output ($;$) { |
9 |
|
if (@_ > 1) { |
10 |
|
if (defined $_[1]) { |
11 |
|
$_[0]->{output} = $_[1]; |
12 |
|
} else { |
13 |
|
delete $_[0]->{output}; |
14 |
|
} |
15 |
|
} |
16 |
|
|
17 |
sub get_error_label ($$) { |
return $_[0]->{output}; |
18 |
my $self = shift; |
} # output |
19 |
my ($input, $err) = @_; |
|
20 |
|
sub add_error ($%) { |
21 |
|
my ($self, %opt) = @_; |
22 |
|
|
23 |
|
my $out = $self->output; |
24 |
|
|
25 |
|
my $error_level = $opt{level}; |
26 |
|
if (not defined $error_level) { |
27 |
|
$error_level = 'm'; ## NOTE: Unknown - an error of the implementation |
28 |
|
} elsif ({ |
29 |
|
m => 1, s => 1, w => 1, i => 1, u => 1, |
30 |
|
}->{$error_level}) { |
31 |
|
# |
32 |
|
} else { |
33 |
|
$error_level = 'm'; ## NOTE: Unknown - an error of the implementation |
34 |
|
} |
35 |
|
|
36 |
|
my $error_layer = $opt{layer}; |
37 |
|
if (not defined $error_layer) { |
38 |
|
$error_layer = 'syntax'; ## NOTE: Unknown - an error of the implementation |
39 |
|
} elsif ({ |
40 |
|
transfer => 1, |
41 |
|
encode => 1, |
42 |
|
charset => 1, |
43 |
|
syntax => 1, |
44 |
|
structure => 1, |
45 |
|
semantics => 1, |
46 |
|
}->{$error_layer}) { |
47 |
|
# |
48 |
|
} else { |
49 |
|
$error_layer = 'syntax'; ## NOTE: Unknown - an error of the implementation |
50 |
|
} |
51 |
|
|
52 |
|
my $error_type_text = $opt{type}; |
53 |
|
|
54 |
my $r = ''; |
my $class = qq[level-$error_level layer-$error_layer]; |
55 |
|
|
56 |
|
$out->start_tag ('dt', class => $class); |
57 |
|
|
58 |
|
## URL |
59 |
|
|
60 |
|
if (defined $opt{url}) { |
61 |
|
$out->url ($opt{url}); |
62 |
|
} |
63 |
|
|
64 |
|
## Line & column number |
65 |
|
|
66 |
my $line; |
my $line; |
67 |
my $column; |
my $column; |
68 |
|
|
69 |
if (defined $err->{node}) { |
if (defined $opt{node}) { |
70 |
$line = $err->{node}->get_user_data ('manakai_source_line'); |
$line = $opt{node}->get_user_data ('manakai_source_line'); |
71 |
if (defined $line) { |
if (defined $line) { |
72 |
$column = $err->{node}->get_user_data ('manakai_source_column'); |
$column = $opt{node}->get_user_data ('manakai_source_column'); |
73 |
} else { |
} else { |
74 |
if ($err->{node}->node_type == $err->{node}->ATTRIBUTE_NODE) { |
if ($opt{node}->node_type == $opt{node}->ATTRIBUTE_NODE) { |
75 |
my $owner = $err->{node}->owner_element; |
my $owner = $opt{node}->owner_element; |
76 |
$line = $owner->get_user_data ('manakai_source_line'); |
if ($owner) { |
77 |
$column = $owner->get_user_data ('manakai_source_column'); |
$line = $owner->get_user_data ('manakai_source_line'); |
78 |
|
$column = $owner->get_user_data ('manakai_source_column'); |
79 |
|
} |
80 |
} else { |
} else { |
81 |
my $parent = $err->{node}->parent_node; |
my $parent = $opt{node}->parent_node; |
82 |
if ($parent) { |
if ($parent) { |
83 |
$line = $parent->get_user_data ('manakai_source_line'); |
$line = $parent->get_user_data ('manakai_source_line'); |
84 |
$column = $parent->get_user_data ('manakai_source_column'); |
$column = $parent->get_user_data ('manakai_source_column'); |
87 |
} |
} |
88 |
} |
} |
89 |
unless (defined $line) { |
unless (defined $line) { |
90 |
if (defined $err->{token} and defined $err->{token}->{line}) { |
if (defined $opt{token} and defined $opt{token}->{line}) { |
91 |
$line = $err->{token}->{line}; |
$line = $opt{token}->{line}; |
92 |
$column = $err->{token}->{column}; |
$column = $opt{token}->{column}; |
93 |
} elsif (defined $err->{line}) { |
} elsif (defined $opt{line}) { |
94 |
$line = $err->{line}; |
$line = $opt{line}; |
95 |
$column = $err->{column}; |
$column = $opt{column}; |
96 |
} |
} |
97 |
} |
} |
98 |
|
|
99 |
if (defined $line) { |
if (defined $line) { |
100 |
if (defined $column and $column > 0) { |
if (defined $column and $column > 0) { |
101 |
$r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a> column $column]; |
$out->xref ('Line ' . $line, target => 'line-' . $line); |
102 |
|
$out->text (' column ' . $column); |
103 |
} else { |
} else { |
104 |
$line = $line - 1 || 1; |
$line = $line - 1 || 1; |
105 |
$r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a>]; |
$out->xref ('Line ' . $line, target => 'line-' . $line); |
106 |
} |
} |
107 |
} |
} |
108 |
|
|
109 |
if (defined $err->{node}) { |
## Node path |
110 |
$r .= ' ' if length $r; |
|
111 |
$r .= $self->get_node_link ($input, $err->{node}); |
if (defined $opt{node}) { |
112 |
|
$out->html (' '); |
113 |
|
$out->node_link ($opt{node}); |
114 |
} |
} |
115 |
|
|
116 |
if (defined $err->{index}) { |
if (defined $opt{index}) { |
117 |
if (length $r) { |
if ($opt{index_has_link}) { |
118 |
$r .= ', Index ' . (0+$err->{index}); |
$out->html (' '); |
119 |
|
$out->xref ('Index ' . (0+$opt{index}), |
120 |
|
target => 'index-' . (0+$opt{index})); |
121 |
} else { |
} else { |
122 |
$r .= "<a href='#$input->{id_prefix}index-@{[0+$err->{index}]}'>Index " |
$out->text (' Index ' . (0+$opt{index})); |
|
. (0+$err->{index}) . '</a>'; |
|
123 |
} |
} |
124 |
} |
} |
125 |
|
|
126 |
if (defined $err->{value}) { |
if (defined $opt{value}) { |
127 |
$r .= ' ' if length $r; ## BUG: v must be escaped |
$out->html (' '); |
128 |
$r .= '<q><code>' . ($err->{value}) . '</code></q>'; |
$out->code ($opt{value}); |
129 |
} |
} |
130 |
|
|
131 |
|
$out->start_tag ('dd', class => $class); |
132 |
|
$out->text ($error_type_text); |
133 |
|
|
134 |
|
if (defined $opt{text}) { |
135 |
|
$out->html (' (<q>'); |
136 |
|
$out->text ($opt{text}); |
137 |
|
$out->html ('</q>)'); |
138 |
|
} |
139 |
|
|
140 |
|
my $fragment = $opt{type}; |
141 |
|
$fragment =~ tr/ /-/; |
142 |
|
$fragment = $out->encode_url_component ($fragment); |
143 |
|
$out->text (' ['); |
144 |
|
$out->link ('Description', url => '../error-description#' . $fragment); |
145 |
|
$out->text (']'); |
146 |
|
|
147 |
|
|
148 |
|
# my ($type, $cls, $msg) = main::get_text ($opt{type}, $opt{level}); |
149 |
|
# $out->html (qq[<dt class="$cls">] . $result->get_error_label ($input, \%opt)); |
150 |
|
|
151 |
|
$error_layer = 'char' |
152 |
|
if $error_layer eq 'charset' or $error_layer eq 'encode'; |
153 |
|
if ($error_level eq 's') { |
154 |
|
$self->{$error_layer}->{should}++; |
155 |
|
$self->{$error_layer}->{score_min} -= 2; |
156 |
|
$self->{conforming_min} = 0; |
157 |
|
} elsif ($error_level eq 'w') { |
158 |
|
$self->{$error_layer}->{warning}++; |
159 |
|
} elsif ($error_level eq 'u') { |
160 |
|
$self->{$error_layer}->{unsupported}++; |
161 |
|
$self->{unsupported} = 1; |
162 |
|
} elsif ($error_level eq 'i') { |
163 |
|
# |
164 |
|
} else { |
165 |
|
$self->{$error_layer}->{must}++; |
166 |
|
$self->{$error_layer}->{score_max} -= 2; |
167 |
|
$self->{$error_layer}->{score_min} -= 2; |
168 |
|
$self->{conforming_min} = 0; |
169 |
|
$self->{conforming_max} = 0; |
170 |
|
} |
171 |
|
} # add_error |
172 |
|
|
173 |
|
sub generate_result_section ($) { |
174 |
|
my $result = shift; |
175 |
|
|
176 |
|
my $out = $result->output; |
177 |
|
|
178 |
|
$out->start_section (id => 'result-summary', |
179 |
|
title => 'Result'); |
180 |
|
|
181 |
|
if ($result->{unsupported} and $result->{conforming_max}) { |
182 |
|
$out->html (qq[<p class=uncertain id=result-para>The conformance |
183 |
|
checker cannot decide whether the document is conforming or |
184 |
|
not, since the document contains one or more unsupported |
185 |
|
features. The document might or might not be conforming.</p>]); |
186 |
|
} elsif ($result->{conforming_min}) { |
187 |
|
$out->html (qq[<p class=PASS id=result-para>No conformance-error is |
188 |
|
found in this document.</p>]); |
189 |
|
} elsif ($result->{conforming_max}) { |
190 |
|
$out->html (qq[<p class=SEE-RESULT id=result-para>This document |
191 |
|
is <strong>likely <em>non</em>-conforming</strong>, but in rare case |
192 |
|
it might be conforming.</p>]); |
193 |
|
} else { |
194 |
|
$out->html (qq[<p class=FAIL id=result-para>This document is |
195 |
|
<strong><em>non</em>-conforming</strong>.</p>]); |
196 |
|
} |
197 |
|
|
198 |
|
$out->html (qq[<table> |
199 |
|
<colgroup><col><colgroup><col><col><col><colgroup><col> |
200 |
|
<thead> |
201 |
|
<tr><th scope=col></th> |
202 |
|
<th scope=col><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level |
203 |
|
Errors</a></th> |
204 |
|
<th scope=col><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level |
205 |
|
Errors</a></th> |
206 |
|
<th scope=col><a href="../error-description#level-w">Warnings</a></th> |
207 |
|
<th scope=col>Score</th></tr></thead><tbody>]); |
208 |
|
|
209 |
|
## TODO: Introduce "N/A" value (e.g. Character layer is not applicable |
210 |
|
## to binary formats) |
211 |
|
|
212 |
|
my $must_error = 0; |
213 |
|
my $should_error = 0; |
214 |
|
my $warning = 0; |
215 |
|
my $score_min = 0; |
216 |
|
my $score_max = 0; |
217 |
|
my $score_base = 20; |
218 |
|
my $score_unit = $score_base / 100; |
219 |
|
for ( |
220 |
|
[Transfer => 'transfer', ''], |
221 |
|
[Character => 'char', ''], |
222 |
|
[Syntax => 'syntax', '#parse-errors'], |
223 |
|
[Structure => 'structure', '#document-errors'], |
224 |
|
) { |
225 |
|
$must_error += ($result->{$_->[1]}->{must} += 0); |
226 |
|
$should_error += ($result->{$_->[1]}->{should} += 0); |
227 |
|
$warning += ($result->{$_->[1]}->{warning} += 0); |
228 |
|
$score_min += (($result->{$_->[1]}->{score_min} *= $score_unit) += $score_base); |
229 |
|
$score_max += (($result->{$_->[1]}->{score_max} *= $score_unit) += $score_base); |
230 |
|
|
231 |
|
my $uncertain = $result->{$_->[1]}->{unsupported} ? '?' : ''; |
232 |
|
my $label = $_->[0]; |
233 |
|
if ($result->{$_->[1]}->{must} or |
234 |
|
$result->{$_->[1]}->{should} or |
235 |
|
$result->{$_->[1]}->{warning} or |
236 |
|
$result->{$_->[1]}->{unsupported}) { |
237 |
|
$label = qq[<a href="$_->[2]">$label</a>]; |
238 |
|
} |
239 |
|
|
240 |
|
$out->html (qq[<tr class="@{[$uncertain ? 'uncertain' : '']}"><th scope=row>$label</th><td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{must}$uncertain</td><td class="@{[$result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">$result->{$_->[1]}->{should}$uncertain</td><td>$result->{$_->[1]}->{warning}$uncertain</td>]); |
241 |
|
if ($uncertain) { |
242 |
|
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">−∞..$result->{$_->[1]}->{score_max}]); |
243 |
|
} elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { |
244 |
|
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}]); |
245 |
|
} else { |
246 |
|
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}]); |
247 |
|
} |
248 |
|
$out->html (qq[ / 20]); |
249 |
|
} |
250 |
|
|
251 |
|
$score_max += $score_base; |
252 |
|
|
253 |
|
$out->html (qq[ |
254 |
|
<tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>−∞..$score_base / 20 |
255 |
|
</tbody> |
256 |
|
<tfoot><tr class=uncertain><th scope=row>Total</th> |
257 |
|
<td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td> |
258 |
|
<td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td> |
259 |
|
<td>$warning?</td> |
260 |
|
<td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>−∞..$score_max</strong> / 100 |
261 |
|
</table> |
262 |
|
|
263 |
|
<p><strong>Important</strong>: This conformance checking service |
264 |
|
is <em>under development</em>. The result above might be <em>wrong</em>.</p>]); |
265 |
|
$out->end_section; |
266 |
|
} # generate_result_section |
267 |
|
|
268 |
|
sub _get_error_label ($$) { |
269 |
|
my $self = shift; |
270 |
|
my ($input, $err) = @_; |
271 |
|
|
272 |
|
|
|
return $r; |
|
273 |
} # get_error_label |
} # get_error_label |
274 |
|
|
275 |
sub get_error_level_label ($) { |
sub get_error_level_label ($) { |