147 |
|
|
148 |
sub check_and_print ($$) { |
sub check_and_print ($$) { |
149 |
my ($input, $result) = @_; |
my ($input, $result) = @_; |
150 |
|
$input->{id_prefix} = ''; |
151 |
|
#$input->{nested} = 1/0; |
152 |
|
|
153 |
print_http_header_section ($input, $result); |
print_http_header_section ($input, $result); |
154 |
|
|
180 |
} |
} |
181 |
|
|
182 |
if (defined $doc or defined $el) { |
if (defined $doc or defined $el) { |
183 |
print_structure_dump_dom_section ($doc, $el); |
print_structure_dump_dom_section ($input, $doc, $el); |
184 |
my $elements = print_structure_error_dom_section ($doc, $el, $result); |
my $elements = print_structure_error_dom_section |
185 |
print_table_section ($elements->{table}) if @{$elements->{table}}; |
($input, $doc, $el, $result); |
186 |
print_id_section ($elements->{id}) if keys %{$elements->{id}}; |
print_table_section ($input, $elements->{table}) if @{$elements->{table}}; |
187 |
print_term_section ($elements->{term}) if keys %{$elements->{term}}; |
print_id_section ($input, $elements->{id}) if keys %{$elements->{id}}; |
188 |
print_class_section ($elements->{class}) if keys %{$elements->{class}}; |
print_term_section ($input, $elements->{term}) if keys %{$elements->{term}}; |
189 |
|
print_class_section ($input, $elements->{class}) if keys %{$elements->{class}}; |
190 |
} elsif (defined $manifest) { |
} elsif (defined $manifest) { |
191 |
print_structure_dump_manifest_section ($manifest); |
print_structure_dump_manifest_section ($input, $manifest); |
192 |
print_structure_error_manifest_section ($manifest, $result); |
print_structure_error_manifest_section ($input, $manifest, $result); |
193 |
} |
} |
194 |
} # check_and_print |
} # check_and_print |
195 |
|
|
199 |
defined $input->{header_status_text} or |
defined $input->{header_status_text} or |
200 |
@{$input->{header_field}}; |
@{$input->{header_field}}; |
201 |
|
|
202 |
push @nav, ['#source-header' => 'HTTP Header']; |
push @nav, ['#source-header' => 'HTTP Header'] unless $input->{nested}; |
203 |
print STDOUT qq[<div id="source-header" class="section"> |
print STDOUT qq[<div id="$input->{id_prefix}source-header" class="section"> |
204 |
<h2>HTTP Header</h2> |
<h2>HTTP Header</h2> |
205 |
|
|
206 |
<p><strong>Note</strong>: Due to the limitation of the |
<p><strong>Note</strong>: Due to the limitation of the |
234 |
require Whatpm::HTML; |
require Whatpm::HTML; |
235 |
|
|
236 |
print STDOUT qq[ |
print STDOUT qq[ |
237 |
<div id="parse-errors" class="section"> |
<div id="$input->{id_prefix}parse-errors" class="section"> |
238 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
239 |
|
|
240 |
<dl>]; |
<dl>]; |
241 |
push @nav, ['#parse-errors' => 'Parse Error']; |
push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested}; |
242 |
|
|
243 |
my $onerror = sub { |
my $onerror = sub { |
244 |
my (%opt) = @_; |
my (%opt) = @_; |
292 |
require Message::DOM::XMLParserTemp; |
require Message::DOM::XMLParserTemp; |
293 |
|
|
294 |
print STDOUT qq[ |
print STDOUT qq[ |
295 |
<div id="parse-errors" class="section"> |
<div id="$input->{id_prefix}parse-errors" class="section"> |
296 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
297 |
|
|
298 |
<dl>]; |
<dl>]; |
299 |
push @nav, ['#parse-errors' => 'Parse Error']; |
push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{prefix}; |
300 |
|
|
301 |
my $onerror = sub { |
my $onerror = sub { |
302 |
my $err = shift; |
my $err = shift; |
334 |
require Whatpm::CacheManifest; |
require Whatpm::CacheManifest; |
335 |
|
|
336 |
print STDOUT qq[ |
print STDOUT qq[ |
337 |
<div id="parse-errors" class="section"> |
<div id="$input->{id_prefix}parse-errors" class="section"> |
338 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
339 |
|
|
340 |
<dl>]; |
<dl>]; |
341 |
push @nav, ['#parse-errors' => 'Parse Error']; |
push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested}; |
342 |
|
|
343 |
my $onerror = sub { |
my $onerror = sub { |
344 |
my (%opt) = @_; |
my (%opt) = @_; |
345 |
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); |
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); |
346 |
print STDOUT qq[<dt class="$cls">], get_error_label (\%opt), qq[</dt>]; |
print STDOUT qq[<dt class="$cls">], get_error_label ($input, \%opt), |
347 |
|
qq[</dt>]; |
348 |
$type =~ tr/ /-/; |
$type =~ tr/ /-/; |
349 |
$type =~ s/\|/%7C/g; |
$type =~ s/\|/%7C/g; |
350 |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
371 |
|
|
372 |
my $s = \($enc->decode (${$_[0]})); |
my $s = \($enc->decode (${$_[0]})); |
373 |
my $i = 1; |
my $i = 1; |
374 |
push @nav, ['#source-string' => 'Source']; |
push @nav, ['#source-string' => 'Source'] unless $input->{nested}; |
375 |
print STDOUT qq[<div id="source-string" class="section"> |
print STDOUT qq[<div id="$input->{id_prefix}source-string" class="section"> |
376 |
<h2>Document Source</h2> |
<h2>Document Source</h2> |
377 |
<ol lang="">\n]; |
<ol lang="">\n]; |
378 |
if (length $$s) { |
if (length $$s) { |
379 |
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
380 |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1, |
381 |
|
"</li>\n"; |
382 |
$i++; |
$i++; |
383 |
} |
} |
384 |
if ($$s =~ /\G([^\x0A]+)/gc) { |
if ($$s =~ /\G([^\x0A]+)/gc) { |
385 |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1, |
386 |
|
"</li>\n"; |
387 |
} |
} |
388 |
} else { |
} else { |
389 |
print STDOUT q[<li id="line-1"></li>]; |
print STDOUT q[<li id="$input->{id_prefix}line-1"></li>]; |
390 |
} |
} |
391 |
print STDOUT "</ol></div>"; |
print STDOUT "</ol></div>"; |
392 |
} # print_input_string_section |
} # print_input_string_section |
403 |
next; |
next; |
404 |
} |
} |
405 |
|
|
406 |
my $node_id = 'node-'.refaddr $child; |
my $node_id = $input->{id_prefix} . 'node-'.refaddr $child; |
407 |
my $nt = $child->node_type; |
my $nt = $child->node_type; |
408 |
if ($nt == $child->ELEMENT_NODE) { |
if ($nt == $child->ELEMENT_NODE) { |
409 |
my $child_nsuri = $child->namespace_uri; |
my $child_nsuri = $child->namespace_uri; |
414 |
$r .= '<ul class="attributes">'; |
$r .= '<ul class="attributes">'; |
415 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
416 |
@{$child->attributes}) { |
@{$child->attributes}) { |
417 |
$r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $attr->[2] ? htescape ($attr->[2]) : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
$r .= qq[<li id="$input->{id_prefix}$attr->[3]" class="tree-attribute"><code title="@{[defined $attr->[2] ? htescape ($attr->[2]) : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
418 |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
419 |
} |
} |
420 |
$r .= '</ul>'; |
$r .= '</ul>'; |
483 |
print STDOUT $r; |
print STDOUT $r; |
484 |
} # print_document_tree |
} # print_document_tree |
485 |
|
|
486 |
sub print_structure_dump_dom_section ($$) { |
sub print_structure_dump_dom_section ($$$) { |
487 |
my ($doc, $el) = @_; |
my ($input, $doc, $el) = @_; |
488 |
|
|
489 |
print STDOUT qq[ |
print STDOUT qq[ |
490 |
<div id="document-tree" class="section"> |
<div id="$input->{id_prefix}document-tree" class="section"> |
491 |
<h2>Document Tree</h2> |
<h2>Document Tree</h2> |
492 |
]; |
]; |
493 |
push @nav, ['#document-tree' => 'Tree']; |
push @nav, ['#document-tree' => 'Tree'] unless $input->{nested}; |
494 |
|
|
495 |
print_document_tree ($el || $doc); |
print_document_tree ($el || $doc); |
496 |
|
|
497 |
print STDOUT qq[</div>]; |
print STDOUT qq[</div>]; |
498 |
} # print_structure_dump_dom_section |
} # print_structure_dump_dom_section |
499 |
|
|
500 |
sub print_structure_dump_manifest_section ($) { |
sub print_structure_dump_manifest_section ($$) { |
501 |
my $manifest = shift; |
my ($input, $manifest) = @_; |
502 |
|
|
503 |
print STDOUT qq[ |
print STDOUT qq[ |
504 |
<div id="dump-manifest" class="section"> |
<div id="$input->{id_prefix}dump-manifest" class="section"> |
505 |
<h2>Cache Manifest</h2> |
<h2>Cache Manifest</h2> |
506 |
]; |
]; |
507 |
push @nav, ['#dump-manifest' => 'Caceh Manifest']; |
push @nav, ['#dump-manifest' => 'Caceh Manifest'] unless $input->{nested}; |
508 |
|
|
509 |
print STDOUT qq[<dl><dt>Explicit entries</dt>]; |
print STDOUT qq[<dl><dt>Explicit entries</dt>]; |
510 |
for my $uri (@{$manifest->[0]}) { |
for my $uri (@{$manifest->[0]}) { |
531 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
532 |
} # print_structure_dump_manifest_section |
} # print_structure_dump_manifest_section |
533 |
|
|
534 |
sub print_structure_error_dom_section ($$$) { |
sub print_structure_error_dom_section ($$$$) { |
535 |
my ($doc, $el, $result) = @_; |
my ($input, $doc, $el, $result) = @_; |
536 |
|
|
537 |
print STDOUT qq[<div id="document-errors" class="section"> |
print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section"> |
538 |
<h2>Document Errors</h2> |
<h2>Document Errors</h2> |
539 |
|
|
540 |
<dl>]; |
<dl>]; |
541 |
push @nav, ['#document-errors' => 'Document Error']; |
push @nav, ['#document-errors' => 'Document Error'] unless $input->{nested}; |
542 |
|
|
543 |
require Whatpm::ContentChecker; |
require Whatpm::ContentChecker; |
544 |
my $onerror = sub { |
my $onerror = sub { |
547 |
$type =~ tr/ /-/; |
$type =~ tr/ /-/; |
548 |
$type =~ s/\|/%7C/g; |
$type =~ s/\|/%7C/g; |
549 |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
550 |
print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) . |
print STDOUT qq[<dt class="$cls">] . get_error_label ($input, \%opt) . |
551 |
qq[</dt>\n<dd class="$cls">], get_error_level_label (\%opt); |
qq[</dt>\n<dd class="$cls">], get_error_level_label (\%opt); |
552 |
print STDOUT $msg, "</dd>\n"; |
print STDOUT $msg, "</dd>\n"; |
553 |
add_error ('structure', \%opt => $result); |
add_error ('structure', \%opt => $result); |
568 |
} # print_structure_error_dom_section |
} # print_structure_error_dom_section |
569 |
|
|
570 |
sub print_structure_error_manifest_section ($$$) { |
sub print_structure_error_manifest_section ($$$) { |
571 |
my ($manifest, $result) = @_; |
my ($input, $manifest, $result) = @_; |
572 |
|
|
573 |
print STDOUT qq[<div id="document-errors" class="section"> |
print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section"> |
574 |
<h2>Document Errors</h2> |
<h2>Document Errors</h2> |
575 |
|
|
576 |
<dl>]; |
<dl>]; |
577 |
push @nav, ['#document-errors' => 'Document Error']; |
push @nav, ['#document-errors' => 'Document Error'] unless $input->{nested}; |
578 |
|
|
579 |
require Whatpm::CacheManifest; |
require Whatpm::CacheManifest; |
580 |
Whatpm::CacheManifest->check_manifest ($manifest, sub { |
Whatpm::CacheManifest->check_manifest ($manifest, sub { |
583 |
$type =~ tr/ /-/; |
$type =~ tr/ /-/; |
584 |
$type =~ s/\|/%7C/g; |
$type =~ s/\|/%7C/g; |
585 |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
586 |
print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) . |
print STDOUT qq[<dt class="$cls">] . get_error_label ($input, \%opt) . |
587 |
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
588 |
add_error ('structure', \%opt => $result); |
add_error ('structure', \%opt => $result); |
589 |
}); |
}); |
591 |
print STDOUT qq[</div>]; |
print STDOUT qq[</div>]; |
592 |
} # print_structure_error_manifest_section |
} # print_structure_error_manifest_section |
593 |
|
|
594 |
sub print_table_section ($) { |
sub print_table_section ($$) { |
595 |
my $tables = shift; |
my ($input, $tables) = @_; |
596 |
|
|
597 |
push @nav, ['#tables' => 'Tables']; |
push @nav, ['#tables' => 'Tables'] unless $input->{nested}; |
598 |
print STDOUT qq[ |
print STDOUT qq[ |
599 |
<div id="tables" class="section"> |
<div id="$input->{id_prefix}tables" class="section"> |
600 |
<h2>Tables</h2> |
<h2>Tables</h2> |
601 |
|
|
602 |
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]--> |
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]--> |
611 |
my $i = 0; |
my $i = 0; |
612 |
for my $table_el (@$tables) { |
for my $table_el (@$tables) { |
613 |
$i++; |
$i++; |
614 |
print STDOUT qq[<div class="section" id="table-$i"><h3>] . |
print STDOUT qq[<div class="section" id="$input->{id_prefix}table-$i"><h3>] . |
615 |
get_node_link ($table_el) . q[</h3>]; |
get_node_link ($input, $table_el) . q[</h3>]; |
616 |
|
|
617 |
## TODO: Make |ContentChecker| return |form_table| result |
## TODO: Make |ContentChecker| return |form_table| result |
618 |
## so that this script don't have to run the algorithm twice. |
## so that this script don't have to run the algorithm twice. |
644 |
|
|
645 |
print STDOUT '</div><script type="text/javascript">tableToCanvas ('; |
print STDOUT '</div><script type="text/javascript">tableToCanvas ('; |
646 |
print STDOUT JSON::objToJson ($table); |
print STDOUT JSON::objToJson ($table); |
647 |
print STDOUT qq[, document.getElementById ('table-$i'));</script>]; |
print STDOUT qq[, document.getElementById ('$input->{id_prefix}table-$i')]; |
648 |
|
print STDOUT qq[, '$input->{id_prefix}');</script>]; |
649 |
} |
} |
650 |
|
|
651 |
print STDOUT qq[</div>]; |
print STDOUT qq[</div>]; |
652 |
} # print_table_section |
} # print_table_section |
653 |
|
|
654 |
sub print_id_section ($) { |
sub print_id_section ($$) { |
655 |
my $ids = shift; |
my ($input, $ids) = @_; |
656 |
|
|
657 |
push @nav, ['#identifiers' => 'IDs']; |
push @nav, ['#identifiers' => 'IDs'] unless $input->{nested}; |
658 |
print STDOUT qq[ |
print STDOUT qq[ |
659 |
<div id="identifiers" class="section"> |
<div id="$input->{id_prefix}identifiers" class="section"> |
660 |
<h2>Identifiers</h2> |
<h2>Identifiers</h2> |
661 |
|
|
662 |
<dl> |
<dl> |
664 |
for my $id (sort {$a cmp $b} keys %$ids) { |
for my $id (sort {$a cmp $b} keys %$ids) { |
665 |
print STDOUT qq[<dt><code>@{[htescape $id]}</code></dt>]; |
print STDOUT qq[<dt><code>@{[htescape $id]}</code></dt>]; |
666 |
for (@{$ids->{$id}}) { |
for (@{$ids->{$id}}) { |
667 |
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
print STDOUT qq[<dd>].get_node_link ($input, $_).qq[</dd>]; |
668 |
} |
} |
669 |
} |
} |
670 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
671 |
} # print_id_section |
} # print_id_section |
672 |
|
|
673 |
sub print_term_section ($) { |
sub print_term_section ($$) { |
674 |
my $terms = shift; |
my ($input, $terms) = @_; |
675 |
|
|
676 |
push @nav, ['#terms' => 'Terms']; |
push @nav, ['#terms' => 'Terms'] unless $input->{nested}; |
677 |
print STDOUT qq[ |
print STDOUT qq[ |
678 |
<div id="terms" class="section"> |
<div id="$input->{id_prefix}terms" class="section"> |
679 |
<h2>Terms</h2> |
<h2>Terms</h2> |
680 |
|
|
681 |
<dl> |
<dl> |
683 |
for my $term (sort {$a cmp $b} keys %$terms) { |
for my $term (sort {$a cmp $b} keys %$terms) { |
684 |
print STDOUT qq[<dt>@{[htescape $term]}</dt>]; |
print STDOUT qq[<dt>@{[htescape $term]}</dt>]; |
685 |
for (@{$terms->{$term}}) { |
for (@{$terms->{$term}}) { |
686 |
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
print STDOUT qq[<dd>].get_node_link ($input, $_).qq[</dd>]; |
687 |
} |
} |
688 |
} |
} |
689 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
690 |
} # print_term_section |
} # print_term_section |
691 |
|
|
692 |
sub print_class_section ($) { |
sub print_class_section ($$) { |
693 |
my $classes = shift; |
my ($input, $classes) = @_; |
694 |
|
|
695 |
push @nav, ['#classes' => 'Classes']; |
push @nav, ['#classes' => 'Classes'] unless $input->{nested}; |
696 |
print STDOUT qq[ |
print STDOUT qq[ |
697 |
<div id="classes" class="section"> |
<div id="$input->{id_prefix}classes" class="section"> |
698 |
<h2>Classes</h2> |
<h2>Classes</h2> |
699 |
|
|
700 |
<dl> |
<dl> |
702 |
for my $class (sort {$a cmp $b} keys %$classes) { |
for my $class (sort {$a cmp $b} keys %$classes) { |
703 |
print STDOUT qq[<dt><code>@{[htescape $class]}</code></dt>]; |
print STDOUT qq[<dt><code>@{[htescape $class]}</code></dt>]; |
704 |
for (@{$classes->{$class}}) { |
for (@{$classes->{$class}}) { |
705 |
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
print STDOUT qq[<dd>].get_node_link ($input, $_).qq[</dd>]; |
706 |
} |
} |
707 |
} |
} |
708 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
829 |
<p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p> |
<p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p> |
830 |
</div>]; |
</div>]; |
831 |
push @nav, ['#result-summary' => 'Result']; |
push @nav, ['#result-summary' => 'Result']; |
832 |
} # print_Result_input_error_section |
} # print_result_input_error_section |
833 |
|
|
834 |
sub get_error_label ($) { |
sub get_error_label ($$) { |
835 |
my $err = shift; |
my ($input, $err) = @_; |
836 |
|
|
837 |
my $r = ''; |
my $r = ''; |
838 |
|
|
847 |
|
|
848 |
if (defined $err->{node}) { |
if (defined $err->{node}) { |
849 |
$r .= ' ' if length $r; |
$r .= ' ' if length $r; |
850 |
$r = get_node_link ($err->{node}); |
$r = get_node_link ($input, $err->{node}); |
851 |
} |
} |
852 |
|
|
853 |
if (defined $err->{index}) { |
if (defined $err->{index}) { |
916 |
return join '/', @r; |
return join '/', @r; |
917 |
} # get_node_path |
} # get_node_path |
918 |
|
|
919 |
sub get_node_link ($) { |
sub get_node_link ($$) { |
920 |
return qq[<a href="#node-@{[refaddr $_[0]]}">] . |
return qq[<a href="#$_[0]->{id_prefix}node-@{[refaddr $_[1]]}">] . |
921 |
htescape (get_node_path ($_[0])) . qq[</a>]; |
htescape (get_node_path ($_[1])) . qq[</a>]; |
922 |
} # get_node_link |
} # get_node_link |
923 |
|
|
924 |
{ |
{ |