| 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 |
|
return $_[0]->{output}; |
| 18 |
|
} # output |
| 19 |
|
|
| 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 $class = qq[level-$error_level layer-$error_layer]; |
| 55 |
|
|
| 56 |
|
$out->start_tag ('dt', class => $class); |
| 57 |
|
my $has_location; |
| 58 |
|
|
| 59 |
sub get_error_label ($$) { |
## URL |
| 60 |
my $self = shift; |
|
| 61 |
my ($input, $err) = @_; |
if (defined $opt{url}) { |
| 62 |
|
$out->url ($opt{url}); |
| 63 |
|
$has_location = 1; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
my $r = ''; |
## Line & column number |
| 67 |
|
|
| 68 |
my $line; |
my $line; |
| 69 |
my $column; |
my $column; |
| 70 |
|
|
| 71 |
if (defined $err->{node}) { |
if (defined $opt{node}) { |
| 72 |
$line = $err->{node}->get_user_data ('manakai_source_line'); |
$line = $opt{node}->get_user_data ('manakai_source_line'); |
| 73 |
if (defined $line) { |
if (defined $line) { |
| 74 |
$column = $err->{node}->get_user_data ('manakai_source_column'); |
$column = $opt{node}->get_user_data ('manakai_source_column'); |
| 75 |
} else { |
} else { |
| 76 |
if ($err->{node}->node_type == $err->{node}->ATTRIBUTE_NODE) { |
if ($opt{node}->node_type == $opt{node}->ATTRIBUTE_NODE) { |
| 77 |
my $owner = $err->{node}->owner_element; |
my $owner = $opt{node}->owner_element; |
| 78 |
$line = $owner->get_user_data ('manakai_source_line'); |
if ($owner) { |
| 79 |
$column = $owner->get_user_data ('manakai_source_column'); |
$line = $owner->get_user_data ('manakai_source_line'); |
| 80 |
|
$column = $owner->get_user_data ('manakai_source_column'); |
| 81 |
|
} |
| 82 |
} else { |
} else { |
| 83 |
my $parent = $err->{node}->parent_node; |
my $parent = $opt{node}->parent_node; |
| 84 |
if ($parent) { |
if ($parent) { |
| 85 |
$line = $parent->get_user_data ('manakai_source_line'); |
$line = $parent->get_user_data ('manakai_source_line'); |
| 86 |
$column = $parent->get_user_data ('manakai_source_column'); |
$column = $parent->get_user_data ('manakai_source_column'); |
| 89 |
} |
} |
| 90 |
} |
} |
| 91 |
unless (defined $line) { |
unless (defined $line) { |
| 92 |
if (defined $err->{token} and defined $err->{token}->{line}) { |
if (defined $opt{token} and defined $opt{token}->{line}) { |
| 93 |
$line = $err->{token}->{line}; |
$line = $opt{token}->{line}; |
| 94 |
$column = $err->{token}->{column}; |
$column = $opt{token}->{column}; |
| 95 |
} elsif (defined $err->{line}) { |
} elsif (defined $opt{line}) { |
| 96 |
$line = $err->{line}; |
$line = $opt{line}; |
| 97 |
$column = $err->{column}; |
$column = $opt{column}; |
| 98 |
} |
} |
| 99 |
} |
} |
| 100 |
|
|
| 101 |
if (defined $line) { |
if (defined $line) { |
| 102 |
if (defined $column and $column > 0) { |
if (defined $column and $column > 0) { |
| 103 |
$r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a> column $column]; |
$out->xref ('Line ' . $line, target => 'line-' . $line); |
| 104 |
|
$out->text (' column ' . $column); |
| 105 |
} else { |
} else { |
| 106 |
$line = $line - 1 || 1; |
$line = $line - 1 || 1; |
| 107 |
$r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a>]; |
$out->xref ('Line ' . $line, target => 'line-' . $line); |
| 108 |
} |
} |
| 109 |
|
$has_location = 1; |
| 110 |
} |
} |
| 111 |
|
|
| 112 |
if (defined $err->{node}) { |
## Node path |
| 113 |
$r .= ' ' if length $r; |
|
| 114 |
$r .= $self->get_node_link ($input, $err->{node}); |
if (defined $opt{node}) { |
| 115 |
|
$out->html (' '); |
| 116 |
|
$out->node_link ($opt{node}); |
| 117 |
|
$has_location = 1; |
| 118 |
} |
} |
| 119 |
|
|
| 120 |
if (defined $err->{index}) { |
if (defined $opt{index}) { |
| 121 |
if (length $r) { |
if ($opt{index_has_link}) { |
| 122 |
$r .= ', Index ' . (0+$err->{index}); |
$out->html (' '); |
| 123 |
|
$out->xref ('Index ' . (0+$opt{index}), |
| 124 |
|
target => 'index-' . (0+$opt{index})); |
| 125 |
} else { |
} else { |
| 126 |
$r .= "<a href='#$input->{id_prefix}index-@{[0+$err->{index}]}'>Index " |
$out->text (' Index ' . (0+$opt{index})); |
| 127 |
. (0+$err->{index}) . '</a>'; |
} |
| 128 |
|
$has_location = 1; |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
if (defined $opt{value}) { |
| 132 |
|
$out->html (' '); |
| 133 |
|
$out->code ($opt{value}); |
| 134 |
|
$has_location = 1; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
unless ($has_location) { |
| 138 |
|
if (defined $opt{input}) { |
| 139 |
|
if (defined $opt{input}->{container_node}) { |
| 140 |
|
my $original_input = $out->input; |
| 141 |
|
$out->input ($opt{input}->{parent_input}); |
| 142 |
|
$out->node_link ($opt{input}->{container_node}); |
| 143 |
|
$out->input ($original_input); |
| 144 |
|
$has_location = 1; |
| 145 |
|
} elsif (defined $opt{input}->{request_uri}) { |
| 146 |
|
$out->url ($opt{input}->{request_uri}); |
| 147 |
|
$has_location = 1; |
| 148 |
|
} elsif (defined $opt{input}->{uri}) { |
| 149 |
|
$out->url ($opt{input}->{uri}); |
| 150 |
|
$has_location = 1; |
| 151 |
|
} |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
unless ($has_location) { |
| 155 |
|
$out->text ('Unknown location'); |
| 156 |
} |
} |
| 157 |
} |
} |
| 158 |
|
|
| 159 |
|
$out->start_tag ('dd', class => $class); |
| 160 |
|
|
| 161 |
|
## Error level |
| 162 |
|
|
| 163 |
|
if ($error_level eq 'm') { |
| 164 |
|
$out->html (qq[<strong><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level |
| 165 |
|
error</a></strong>: ]); |
| 166 |
|
} elsif ($error_level eq 's') { |
| 167 |
|
$out->html (qq[<strong><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level |
| 168 |
|
error</a></strong>: ]); |
| 169 |
|
} elsif ($error_level eq 'w') { |
| 170 |
|
$out->html (qq[<strong><a href="../error-description#level-w">Warning</a></strong>: ]); |
| 171 |
|
} elsif ($error_level eq 'u') { |
| 172 |
|
$out->html (qq[<strong><a href="../error-description#level-u">Not |
| 173 |
|
supported</a></strong>: ]); |
| 174 |
|
} elsif ($error_level eq 'i') { |
| 175 |
|
$out->html (qq[<strong><a href="../error-description#level-i">Information</a></strong>: ]); |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
## Error message |
| 179 |
|
|
| 180 |
|
$out->text ($error_type_text); |
| 181 |
|
|
| 182 |
|
## Additional error description |
| 183 |
|
|
| 184 |
|
if (defined $opt{text}) { |
| 185 |
|
$out->html (' (<q>'); |
| 186 |
|
$out->text ($opt{text}); |
| 187 |
|
$out->html ('</q>)'); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
## Link to a long description |
| 191 |
|
|
| 192 |
|
my $fragment = $opt{type}; |
| 193 |
|
$fragment =~ tr/ /-/; |
| 194 |
|
$fragment = $out->encode_url_component ($fragment); |
| 195 |
|
$out->text (' ['); |
| 196 |
|
$out->link ('Description', url => '../error-description#' . $fragment, |
| 197 |
|
rel => 'help'); |
| 198 |
|
$out->text (']'); |
| 199 |
|
|
| 200 |
|
|
| 201 |
|
# my ($type, $cls, $msg) = main::get_text ($opt{type}, $opt{level}); |
| 202 |
|
# $out->html (qq[<dt class="$cls">] . $result->get_error_label ($input, \%opt)); |
| 203 |
|
|
| 204 |
|
$error_layer = 'char' |
| 205 |
|
if $error_layer eq 'charset' or $error_layer eq 'encode'; |
| 206 |
|
if ($error_level eq 's') { |
| 207 |
|
$self->{$error_layer}->{should}++; |
| 208 |
|
$self->{$error_layer}->{score_min} -= 2; |
| 209 |
|
$self->{conforming_min} = 0; |
| 210 |
|
} elsif ($error_level eq 'w') { |
| 211 |
|
$self->{$error_layer}->{warning}++; |
| 212 |
|
} elsif ($error_level eq 'u') { |
| 213 |
|
$self->{$error_layer}->{unsupported}++; |
| 214 |
|
$self->{unsupported} = 1; |
| 215 |
|
} elsif ($error_level eq 'i') { |
| 216 |
|
# |
| 217 |
|
} else { |
| 218 |
|
$self->{$error_layer}->{must}++; |
| 219 |
|
$self->{$error_layer}->{score_max} -= 2; |
| 220 |
|
$self->{$error_layer}->{score_min} -= 2; |
| 221 |
|
$self->{conforming_min} = 0; |
| 222 |
|
$self->{conforming_max} = 0; |
| 223 |
|
} |
| 224 |
|
} # add_error |
| 225 |
|
|
| 226 |
|
sub generate_result_section ($) { |
| 227 |
|
my $result = shift; |
| 228 |
|
|
| 229 |
|
my $out = $result->output; |
| 230 |
|
|
| 231 |
if (defined $err->{value}) { |
$out->start_section (id => 'result-summary', |
| 232 |
$r .= ' ' if length $r; ## BUG: v must be escaped |
title => 'Result'); |
| 233 |
$r .= '<q><code>' . ($err->{value}) . '</code></q>'; |
|
| 234 |
} |
if ($result->{unsupported} and $result->{conforming_max}) { |
| 235 |
|
$out->html (qq[<p class=uncertain id=result-para>The conformance |
| 236 |
return $r; |
checker cannot decide whether the document is conforming or |
| 237 |
} # get_error_label |
not, since the document contains one or more unsupported |
| 238 |
|
features. The document might or might not be conforming.</p>]); |
| 239 |
sub get_error_level_label ($) { |
} elsif ($result->{conforming_min}) { |
| 240 |
my $self = shift; |
$out->html (qq[<p class=PASS id=result-para>No conformance-error is |
| 241 |
my $err = shift; |
found in this document.</p>]); |
| 242 |
|
} elsif ($result->{conforming_max}) { |
| 243 |
my $r = ''; |
$out->html (qq[<p class=SEE-RESULT id=result-para>This document |
| 244 |
|
is <strong>likely <em>non</em>-conforming</strong>, but in rare case |
| 245 |
if (not defined $err->{level} or $err->{level} eq 'm') { |
it might be conforming.</p>]); |
|
$r = qq[<strong><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level |
|
|
error</a></strong>: ]; |
|
|
} elsif ($err->{level} eq 's') { |
|
|
$r = qq[<strong><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level |
|
|
error</a></strong>: ]; |
|
|
} elsif ($err->{level} eq 'w') { |
|
|
$r = qq[<strong><a href="../error-description#level-w">Warning</a></strong>: |
|
|
]; |
|
|
} elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') { |
|
|
$r = qq[<strong><a href="../error-description#level-u">Not |
|
|
supported</a></strong>: ]; |
|
|
} elsif ($err->{level} eq 'i') { |
|
|
$r = qq[<strong><a href="../error-description#level-i">Information</a></strong>: ]; |
|
| 246 |
} else { |
} else { |
| 247 |
my $elevel = htescape ($err->{level}); |
$out->html (qq[<p class=FAIL id=result-para>This document is |
| 248 |
$r = qq[<strong><a href="../error-description#level-$elevel">$elevel</a></strong>: |
<strong><em>non</em>-conforming</strong>.</p>]); |
| 249 |
]; |
} |
| 250 |
} |
|
| 251 |
|
$out->html (qq[<table> |
| 252 |
return $r; |
<colgroup><col><colgroup><col><col><col><colgroup><col> |
| 253 |
} # get_error_level_label |
<thead> |
| 254 |
|
<tr><th scope=col></th> |
| 255 |
sub get_node_path ($) { |
<th scope=col><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level |
| 256 |
my $self = shift; |
Errors</a></th> |
| 257 |
my $node = shift; |
<th scope=col><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level |
| 258 |
my @r; |
Errors</a></th> |
| 259 |
while (defined $node) { |
<th scope=col><a href="../error-description#level-w">Warnings</a></th> |
| 260 |
my $rs; |
<th scope=col>Score</th></tr></thead><tbody>]); |
| 261 |
if ($node->node_type == 1) { |
|
| 262 |
$rs = $node->node_name; |
## TODO: Introduce "N/A" value (e.g. Character layer is not applicable |
| 263 |
$node = $node->parent_node; |
## to binary formats) |
| 264 |
} elsif ($node->node_type == 2) { |
|
| 265 |
$rs = '@' . $node->node_name; |
my $must_error = 0; |
| 266 |
$node = $node->owner_element; |
my $should_error = 0; |
| 267 |
} elsif ($node->node_type == 3) { |
my $warning = 0; |
| 268 |
$rs = '"' . $node->data . '"'; |
my $score_min = 0; |
| 269 |
$node = $node->parent_node; |
my $score_max = 0; |
| 270 |
} elsif ($node->node_type == 9) { |
my $score_base = 20; |
| 271 |
@r = ('') unless @r; |
my $score_unit = $score_base / 100; |
| 272 |
$rs = ''; |
for ( |
| 273 |
$node = $node->parent_node; |
[Transfer => 'transfer', ''], |
| 274 |
|
[Character => 'char', ''], |
| 275 |
|
[Syntax => 'syntax', '#parse-errors'], |
| 276 |
|
[Structure => 'structure', '#document-errors'], |
| 277 |
|
) { |
| 278 |
|
$must_error += ($result->{$_->[1]}->{must} += 0); |
| 279 |
|
$should_error += ($result->{$_->[1]}->{should} += 0); |
| 280 |
|
$warning += ($result->{$_->[1]}->{warning} += 0); |
| 281 |
|
$score_min += (($result->{$_->[1]}->{score_min} *= $score_unit) += $score_base); |
| 282 |
|
$score_max += (($result->{$_->[1]}->{score_max} *= $score_unit) += $score_base); |
| 283 |
|
|
| 284 |
|
my $uncertain = $result->{$_->[1]}->{unsupported} ? '?' : ''; |
| 285 |
|
my $label = $_->[0]; |
| 286 |
|
if ($result->{$_->[1]}->{must} or |
| 287 |
|
$result->{$_->[1]}->{should} or |
| 288 |
|
$result->{$_->[1]}->{warning} or |
| 289 |
|
$result->{$_->[1]}->{unsupported}) { |
| 290 |
|
$label = qq[<a href="$_->[2]">$label</a>]; |
| 291 |
|
} |
| 292 |
|
|
| 293 |
|
$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>]); |
| 294 |
|
if ($uncertain) { |
| 295 |
|
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">−∞..$result->{$_->[1]}->{score_max}]); |
| 296 |
|
} elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { |
| 297 |
|
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}]); |
| 298 |
} else { |
} else { |
| 299 |
$rs = '#' . $node->node_type; |
$out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}]); |
|
$node = $node->parent_node; |
|
| 300 |
} |
} |
| 301 |
unshift @r, $rs; |
$out->html (qq[ / 20]); |
| 302 |
} |
} |
|
return join '/', @r; |
|
|
} # get_node_path |
|
| 303 |
|
|
| 304 |
use Scalar::Util qw/refaddr/; |
$score_max += $score_base; |
| 305 |
|
|
| 306 |
sub get_node_link ($$) { |
$out->html (qq[ |
| 307 |
my $self = shift; |
<tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>−∞..$score_base / 20 |
| 308 |
return qq[<a href="#$_[0]->{id_prefix}node-@{[refaddr $_[1]]}">] . |
</tbody> |
| 309 |
($self->get_node_path ($_[1])) . qq[</a>]; |
<tfoot><tr class=uncertain><th scope=row>Total</th> |
| 310 |
## BUG: ^ must be escaped |
<td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td> |
| 311 |
} # get_node_link |
<td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td> |
| 312 |
|
<td>$warning?</td> |
| 313 |
|
<td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>−∞..$score_max</strong> / 100 |
| 314 |
|
</table> |
| 315 |
|
|
| 316 |
|
<p><strong>Important</strong>: This conformance checking service |
| 317 |
|
is <em>under development</em>. The result above might be <em>wrong</em>.</p>]); |
| 318 |
|
$out->end_section; |
| 319 |
|
} # generate_result_section |
| 320 |
|
|
| 321 |
1; |
1; |