| 2 |
use strict; |
use strict; |
| 3 |
|
|
| 4 |
sub new ($) { |
sub new ($) { |
| 5 |
return bless {}, shift; |
return bless { |
| 6 |
|
global_status => 'conforming', |
| 7 |
|
# or, 'should-error', 'non-conforming', 'uncertain' |
| 8 |
|
subdoc_results => [], |
| 9 |
|
}, shift; |
| 10 |
} # new |
} # new |
| 11 |
|
|
| 12 |
sub output ($;$) { |
sub output ($;$) { |
| 21 |
return $_[0]->{output}; |
return $_[0]->{output}; |
| 22 |
} # output |
} # output |
| 23 |
|
|
| 24 |
|
sub parent_result ($;$) { |
| 25 |
|
if (@_ > 1) { |
| 26 |
|
if (defined $_[1]) { |
| 27 |
|
$_[0]->{parent_result} = $_[1]; |
| 28 |
|
} else { |
| 29 |
|
delete $_[0]->{parent_result}; |
| 30 |
|
} |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
return $_[0]->{parent_result}; |
| 34 |
|
} # parent_result |
| 35 |
|
|
| 36 |
|
sub layer_applicable ($$) { |
| 37 |
|
my $self = shift; |
| 38 |
|
my $layer = shift; |
| 39 |
|
$self->{layers}->{$layer}->{applicable} = 1; |
| 40 |
|
} # layer_applicable |
| 41 |
|
|
| 42 |
|
sub layer_uncertain ($$) { |
| 43 |
|
my $self = shift; |
| 44 |
|
my $layer = shift; |
| 45 |
|
$self->{layers}->{$layer}->{uncertain} ||= 1; |
| 46 |
|
$self->{layers}->{$layer}->{applicable} = 1; |
| 47 |
|
$self->{global_status} = 'uncertain' |
| 48 |
|
unless $self->{global_status} eq 'non-conforming'; |
| 49 |
|
} # layer_uncertain |
| 50 |
|
|
| 51 |
sub add_error ($%) { |
sub add_error ($%) { |
| 52 |
my ($self, %opt) = @_; |
my ($self, %opt) = @_; |
| 53 |
|
|
| 54 |
my $out = $self->output; |
my $out = $self->output; |
| 55 |
|
$out->has_error (1); |
| 56 |
|
|
| 57 |
my $error_level = $opt{level}; |
my $error_level = $opt{level}; |
| 58 |
if (not defined $error_level) { |
if (not defined $error_level) { |
| 194 |
} |
} |
| 195 |
|
|
| 196 |
unless ($has_location) { |
unless ($has_location) { |
| 197 |
$out->text ('Unknown location'); |
$out->nl_text ('Unknown location'); |
| 198 |
} |
} |
| 199 |
} |
} |
| 200 |
|
|
| 201 |
$out->start_tag ('dd', class => $class); |
$out->start_tag ('dd', class => $class); |
| 202 |
|
|
| 203 |
## Error level |
## Error level |
| 204 |
|
$out->nl_text ('Error level ' . $error_level); |
| 205 |
|
$out->text (': '); |
| 206 |
|
|
|
if ($error_level eq 'm') { |
|
|
$out->html (qq[<strong><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level |
|
|
error</a></strong>: ]); |
|
|
} elsif ($error_level eq 's') { |
|
|
$out->html (qq[<strong><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level |
|
|
error</a></strong>: ]); |
|
|
} elsif ($error_level eq 'w') { |
|
|
$out->html (qq[<strong><a href="../error-description#level-w">Warning</a></strong>: ]); |
|
|
} elsif ($error_level eq 'u') { |
|
|
$out->html (qq[<strong><a href="../error-description#level-u">Not |
|
|
supported</a></strong>: ]); |
|
|
} elsif ($error_level eq 'i') { |
|
|
$out->html (qq[<strong><a href="../error-description#level-i">Information</a></strong>: ]); |
|
|
} |
|
|
|
|
| 207 |
## Error message |
## Error message |
|
|
|
| 208 |
$out->nl_text ($error_type_text, node => $opt{node}, text => $opt{text}); |
$out->nl_text ($error_type_text, node => $opt{node}, text => $opt{text}); |
| 209 |
|
|
| 210 |
## Additional error description |
## Additional error description |
|
|
|
| 211 |
if (defined $opt{text}) { |
if (defined $opt{text}) { |
| 212 |
$out->html (' (<q>'); |
$out->html (' (<q>'); |
| 213 |
$out->text ($opt{text}); |
$out->text ($opt{text}); |
| 224 |
rel => 'help'); |
rel => 'help'); |
| 225 |
$out->text (']'); |
$out->text (']'); |
| 226 |
|
|
| 227 |
|
if ($error_level eq 'm') { |
| 228 |
# my ($type, $cls, $msg) = main::get_text ($opt{type}, $opt{level}); |
$self->{layers}->{$error_layer}->{must}++; |
| 229 |
# $out->html (qq[<dt class="$cls">] . $result->get_error_label ($input, \%opt)); |
$self->{global_status} = 'non-conforming'; |
| 230 |
|
} elsif ($error_level eq 's') { |
| 231 |
$error_layer = 'char' |
$self->{layers}->{$error_layer}->{should}++; |
| 232 |
if $error_layer eq 'charset' or $error_layer eq 'encode'; |
$self->{global_status} = 'should-error' |
| 233 |
if ($error_level eq 's') { |
unless {'non-conforming' => 1, |
| 234 |
$self->{$error_layer}->{should}++; |
uncertain => 1}->{$self->{global_status}}; |
|
$self->{$error_layer}->{score_min} -= 2; |
|
|
$self->{conforming_min} = 0; |
|
| 235 |
} elsif ($error_level eq 'w') { |
} elsif ($error_level eq 'w') { |
| 236 |
$self->{$error_layer}->{warning}++; |
$self->{layers}->{$error_layer}->{warning}++; |
| 237 |
} elsif ($error_level eq 'u') { |
} elsif ($error_level eq 'u') { |
| 238 |
$self->{$error_layer}->{unsupported}++; |
$self->{layers}->{$error_layer}->{uncertain}++; |
| 239 |
$self->{unsupported} = 1; |
$self->{global_status} = 'uncertain' |
| 240 |
|
unless $self->{global_status} eq 'non-conforming'; |
| 241 |
} elsif ($error_level eq 'i') { |
} elsif ($error_level eq 'i') { |
| 242 |
# |
$self->{layers}->{$error_layer}->{info}++; |
|
} else { |
|
|
$self->{$error_layer}->{must}++; |
|
|
$self->{$error_layer}->{score_max} -= 2; |
|
|
$self->{$error_layer}->{score_min} -= 2; |
|
|
$self->{conforming_min} = 0; |
|
|
$self->{conforming_max} = 0; |
|
| 243 |
} |
} |
| 244 |
} # add_error |
} # add_error |
| 245 |
|
|
| 246 |
sub generate_result_section ($) { |
sub generate_result_section ($) { |
| 247 |
my $result = shift; |
my $self = shift; |
| 248 |
|
|
| 249 |
|
my $result = $self; |
| 250 |
|
|
| 251 |
my $out = $result->output; |
my $out = $result->output; |
| 252 |
|
|
| 253 |
$out->start_section (id => 'result-summary', |
$out->start_section (role => 'result'); |
|
title => 'Result'); |
|
| 254 |
|
|
| 255 |
if ($result->{unsupported} and $result->{conforming_max}) { |
my $para_class = { |
| 256 |
$out->html (qq[<p class=uncertain id=result-para>The conformance |
'conforming' => 'result-para no-error', |
| 257 |
checker cannot decide whether the document is conforming or |
'should-error' => 'result-para should-errors', |
| 258 |
not, since the document contains one or more unsupported |
'non-conforming' => 'result-para must-errors', |
| 259 |
features. The document might or might not be conforming.</p>]); |
'uncertain' => 'result-para uncertain', |
| 260 |
} elsif ($result->{conforming_min}) { |
}->{$self->{global_status}}; |
| 261 |
$out->html (qq[<p class=PASS id=result-para>No conformance-error is |
$out->start_tag ('p', class => $para_class); |
| 262 |
found in this document.</p>]); |
$out->nl_text ('Conformance is ' . $self->{global_status}); |
| 263 |
} elsif ($result->{conforming_max}) { |
$out->end_tag ('p'); |
|
$out->html (qq[<p class=SEE-RESULT id=result-para>This document |
|
|
is <strong>likely <em>non</em>-conforming</strong>, but in rare case |
|
|
it might be conforming.</p>]); |
|
|
} else { |
|
|
$out->html (qq[<p class=FAIL id=result-para>This document is |
|
|
<strong><em>non</em>-conforming</strong>.</p>]); |
|
|
} |
|
| 264 |
|
|
| 265 |
$out->html (qq[<table> |
$out->html (qq[<table> |
| 266 |
<colgroup><col><colgroup><col><col><col><colgroup><col> |
<colgroup><col><col><colgroup><col><col><col><col><colgroup><col> |
| 267 |
<thead> |
<thead> |
| 268 |
<tr><th scope=col></th> |
<tr><th scope=col colspan=2>]); |
| 269 |
<th scope=col><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level |
for ('Error level m', 'Error level s', 'Error level w', |
| 270 |
Errors</a></th> |
'Error level i', 'Score') { |
| 271 |
<th scope=col><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level |
$out->start_tag ('th'); |
| 272 |
Errors</a></th> |
$out->nl_text ($_); |
| 273 |
<th scope=col><a href="../error-description#level-w">Warnings</a></th> |
} |
| 274 |
<th scope=col>Score</th></tr></thead><tbody>]); |
|
| 275 |
|
my $maindoc_status = {must => 0, should => 0, warning => 0, info => 0, |
| 276 |
## TODO: Introduce "N/A" value (e.g. Character layer is not applicable |
uncertain => 0, applicable => 1}; |
| 277 |
## to binary formats) |
my $subdocs_status = {must => 0, should => 0, warning => 0, info => 0, |
| 278 |
|
uncertain => 0, applicable => 1}; |
| 279 |
my $must_error = 0; |
my $global_status = {must => 0, should => 0, warning => 0, info => 0, |
| 280 |
my $should_error = 0; |
uncertain => 0, applicable => 1}; |
| 281 |
my $warning = 0; |
|
| 282 |
my $score_min = 0; |
my $score_unit = 2; |
| 283 |
my $score_max = 0; |
|
| 284 |
my $score_base = 20; |
my @row = ( |
| 285 |
my $score_unit = $score_base / 100; |
sub { |
| 286 |
for ( |
$out->start_tag ('tbody'); |
| 287 |
[Transfer => 'transfer', '#transfer-errors'], |
$out->start_tag ('tr'); |
| 288 |
[Character => 'char', ''], |
$out->start_tag ('th', colspan => 7, scope => 'col'); |
| 289 |
[Syntax => 'syntax', '#parse-errors'], |
$out->nl_text ('Main document'); |
| 290 |
[Structure => 'structure', '#document-errors'], |
}, |
| 291 |
) { |
{label => 'Transfer L.', status => $self->{layers}->{transfer}, |
| 292 |
$must_error += ($result->{$_->[1]}->{must} += 0); |
target => 'transfer-errors', score_base => 20, |
| 293 |
$should_error += ($result->{$_->[1]}->{should} += 0); |
parent_status => $maindoc_status}, |
| 294 |
$warning += ($result->{$_->[1]}->{warning} += 0); |
{label => 'Encode L.', status => $self->{layers}->{encode}, |
| 295 |
$score_min += (($result->{$_->[1]}->{score_min} *= $score_unit) += $score_base); |
score_base => 10, |
| 296 |
$score_max += (($result->{$_->[1]}->{score_max} *= $score_unit) += $score_base); |
parent_status => $maindoc_status}, |
| 297 |
|
{label => 'Char L.', status => $self->{layers}->{charset}, |
| 298 |
my $uncertain = $result->{$_->[1]}->{unsupported} ? '?' : ''; |
score_base => 10, |
| 299 |
my $label = $_->[0]; |
parent_status => $maindoc_status}, |
| 300 |
if ($result->{$_->[1]}->{must} or |
{label => 'Syntax L.', status => $self->{layers}->{syntax}, |
| 301 |
$result->{$_->[1]}->{should} or |
target => 'parse-errors', score_base => 20, |
| 302 |
$result->{$_->[1]}->{warning} or |
parent_status => $maindoc_status}, |
| 303 |
$result->{$_->[1]}->{unsupported}) { |
{label => 'Structure L.', status => $self->{layers}->{structure}, |
| 304 |
$label = qq[<a href="$_->[2]">$label</a>]; |
target => 'document-errors', score_base => 20, |
| 305 |
} |
parent_status => $maindoc_status}, |
| 306 |
|
{label => 'Semantics L.', status => $self->{layers}->{semantics}, |
| 307 |
$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>]); |
score_base => 20, |
| 308 |
if ($uncertain) { |
parent_status => $maindoc_status}, |
| 309 |
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">−∞..$result->{$_->[1]}->{score_max}]); |
); |
| 310 |
} elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { |
|
| 311 |
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}]); |
if (@{$self->{subdoc_results}}) { |
| 312 |
} else { |
push @row, {label => 'Subtotal', status => $maindoc_status, |
| 313 |
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}]); |
score_base => 100, |
| 314 |
|
parent_status => $global_status, is_total => 1}; |
| 315 |
|
push @row, sub { |
| 316 |
|
$out->start_tag ('tbody'); |
| 317 |
|
$out->start_tag ('tr'); |
| 318 |
|
$out->start_tag ('th', colspan => 7, scope => 'col'); |
| 319 |
|
$out->nl_text ('Subdocuments'); |
| 320 |
|
}; |
| 321 |
|
for (@{$self->{subdoc_results}}) { |
| 322 |
|
push @row, {label => '#' . $_->{input}->full_subdocument_index, |
| 323 |
|
status => $_, |
| 324 |
|
target => $_->{input}->id_prefix . 'result-summary', |
| 325 |
|
score_base => 100, parent_status => $subdocs_status}; |
| 326 |
} |
} |
| 327 |
$out->html (qq[ / 20]); |
push @row, {label => 'Subtotal', status => $subdocs_status, |
| 328 |
|
score_base => 100 * @{$self->{subdoc_results}}, |
| 329 |
|
parent_status => $global_status, is_total => 1}; |
| 330 |
|
} else { |
| 331 |
|
$global_status = $maindoc_status; |
| 332 |
} |
} |
| 333 |
|
|
| 334 |
$score_max += $score_base; |
push @row, sub { |
| 335 |
|
$out->start_tag ('tfoot'); |
| 336 |
|
}; |
| 337 |
|
push @row, {label => 'Total', status => $global_status, |
| 338 |
|
score_base => 100 * (@{$self->{subdoc_results}} + 1), |
| 339 |
|
parent_status => {}, is_total => 1}; |
| 340 |
|
|
| 341 |
|
for my $x (@row) { |
| 342 |
|
if (ref $x eq 'CODE') { |
| 343 |
|
$x->(); |
| 344 |
|
next; |
| 345 |
|
} |
| 346 |
|
|
| 347 |
|
$x->{parent_status}->{$_} += $x->{status}->{$_} |
| 348 |
|
for qw/must should warning info uncertain/; |
| 349 |
|
|
| 350 |
|
my $row_class = $x->{status}->{uncertain} ? 'uncertain' : ''; |
| 351 |
|
$row_class .= ' total' if $x->{is_total}; |
| 352 |
|
$out->start_tag ('tr', class => $row_class); |
| 353 |
|
my $uncertain = $x->{status}->{uncertain} ? '?' : ''; |
| 354 |
|
|
| 355 |
|
$out->start_tag ('td', class => 'subrow') unless $x->{is_total}; |
| 356 |
|
|
| 357 |
|
## Layer name |
| 358 |
|
$out->start_tag ('th', colspan => $x->{is_total} ? 2 : 1, |
| 359 |
|
scope => 'row'); |
| 360 |
|
if (defined $x->{target} and |
| 361 |
|
($x->{status}->{must} or $x->{status}->{should} or |
| 362 |
|
$x->{status}->{warning} or $x->{status}->{info} or |
| 363 |
|
$x->{status}->{uncertain})) { |
| 364 |
|
$out->xref ($x->{label}, target => $x->{target}); |
| 365 |
|
} else { |
| 366 |
|
$out->nl_text ($x->{label}); |
| 367 |
|
} |
| 368 |
|
|
| 369 |
|
## MUST-level errors |
| 370 |
|
$out->start_tag ('td', class => $x->{status}->{must} ? 'must-errors' : ''); |
| 371 |
|
if ($x->{status}->{applicable}) { |
| 372 |
|
$out->text (($x->{status}->{must} or 0) . $uncertain); |
| 373 |
|
} else { |
| 374 |
|
$out->nl_text ('N/A'); |
| 375 |
|
} |
| 376 |
|
|
| 377 |
|
## SHOULD-level errors |
| 378 |
|
$out->start_tag ('td', |
| 379 |
|
class => $x->{status}->{should} ? 'should-errors' : ''); |
| 380 |
|
if ($x->{status}->{applicable}) { |
| 381 |
|
$out->text (($x->{status}->{should} or 0) . $uncertain); |
| 382 |
|
} else { |
| 383 |
|
$out->nl_text ('N/A'); |
| 384 |
|
} |
| 385 |
|
|
| 386 |
|
## Warnings |
| 387 |
|
$out->start_tag ('td', class => $x->{status}->{warning} ? 'warnings' : ''); |
| 388 |
|
if ($x->{status}->{applicable}) { |
| 389 |
|
$out->text (($x->{status}->{warning} or 0) . $uncertain); |
| 390 |
|
} else { |
| 391 |
|
$out->nl_text ('N/A'); |
| 392 |
|
} |
| 393 |
|
|
| 394 |
$out->html (qq[ |
## Informations |
| 395 |
<tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>−∞..$score_base / 20 |
$out->start_tag ('td', class => $x->{status}->{info} ? 'infos' : ''); |
| 396 |
</tbody> |
if ($x->{status}->{applicable}) { |
| 397 |
<tfoot><tr class=uncertain><th scope=row>Total</th> |
$out->text (($x->{status}->{info} or 0) . $uncertain); |
| 398 |
<td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td> |
} else { |
| 399 |
<td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td> |
$out->nl_text ('N/A'); |
| 400 |
<td>$warning?</td> |
} |
| 401 |
<td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>−∞..$score_max</strong> / 100 |
|
| 402 |
</table> |
## Score |
| 403 |
|
$out->start_tag ('td', |
| 404 |
|
class => $x->{status}->{must} ? 'score must-errors' : |
| 405 |
|
$x->{status}->{should} ? 'score should-errors' : |
| 406 |
|
'score'); |
| 407 |
|
|
| 408 |
|
my $max_score = $x->{score_base}; |
| 409 |
|
$max_score -= $x->{status}->{must} * $score_unit; |
| 410 |
|
my $min_score = $max_score; |
| 411 |
|
$min_score -= $x->{status}->{should} * $score_unit; |
| 412 |
|
|
| 413 |
|
$out->start_tag ('strong'); |
| 414 |
|
if ($x->{status}->{uncertain}) { |
| 415 |
|
$out->html ('−∞ '); # negative inifinity |
| 416 |
|
$out->nl_text ('...'); |
| 417 |
|
$out->html ($max_score < 0 ? |
| 418 |
|
' −' . substr ($max_score, 1) : ' ' . $max_score); |
| 419 |
|
} elsif ($min_score != $max_score) { |
| 420 |
|
$out->html ($min_score < 0 ? |
| 421 |
|
'−' . substr ($min_score, 1) . ' ': $min_score . ' '); |
| 422 |
|
$out->nl_text ('...'); |
| 423 |
|
$out->html ($max_score < 0 ? |
| 424 |
|
' −' . substr ($max_score, 1) : ' ' . $max_score); |
| 425 |
|
} else { |
| 426 |
|
$out->html ($max_score < 0 ? |
| 427 |
|
'−' . substr ($max_score, 1) : $max_score); |
| 428 |
|
} |
| 429 |
|
$out->end_tag ('strong'); |
| 430 |
|
|
| 431 |
|
$out->text (' / ' . $x->{score_base}); |
| 432 |
|
} |
| 433 |
|
|
| 434 |
|
$out->end_tag ('table'); |
| 435 |
|
|
| 436 |
|
my $parent = $self->parent_result; |
| 437 |
|
if ($parent) { |
| 438 |
|
$global_status->{input} = $out->input; |
| 439 |
|
push @{$parent->{subdoc_results}}, $global_status; |
| 440 |
|
} |
| 441 |
|
|
| 442 |
<p><strong>Important</strong>: This conformance checking service |
$out->nl_text ('This checker is work in progress.'); |
|
is <em>under development</em>. The result above might be <em>wrong</em>.</p>]); |
|
| 443 |
$out->end_section; |
$out->end_section; |
| 444 |
} # generate_result_section |
} # generate_result_section |
| 445 |
|
|