--- test/html-webhacc/cc.cgi 2007/09/02 08:40:49 1.18 +++ test/html-webhacc/cc.cgi 2007/09/10 11:51:09 1.19 @@ -83,13 +83,14 @@ ]; - print_http_header_section ($input); + my $result = {}; + print_http_header_section ($input, $result); my $doc; my $el; if ($input->{media_type} eq 'text/html') { - ($doc, $el) = print_syntax_error_html_section ($input); + ($doc, $el) = print_syntax_error_html_section ($input, $result); print_source_string_section (\($input->{s}), $input->{charset}); } elsif ({ 'text/xml' => 1, @@ -99,7 +100,7 @@ 'application/xhtml+xml' => 1, 'application/xml' => 1, }->{$input->{media_type}}) { - ($doc, $el) = print_syntax_error_xml_section ($input); + ($doc, $el) = print_syntax_error_xml_section ($input, $result); print_source_string_section (\($input->{s}), $doc->input_encoding); } else { ## TODO: Change HTTP status code?? @@ -108,14 +109,14 @@ if (defined $doc or defined $el) { print_structure_dump_section ($doc, $el); - my $elements = print_structure_error_section ($doc, $el); + my $elements = print_structure_error_section ($doc, $el, $result); print_table_section ($elements->{table}) if @{$elements->{table}}; print_id_section ($elements->{id}) if keys %{$elements->{id}}; print_term_section ($elements->{term}) if keys %{$elements->{term}}; print_class_section ($elements->{class}) if keys %{$elements->{class}}; } - ## TODO: Show result + print_result_section ($result); } else { print STDOUT qq[]; print_result_input_error_section ($input); @@ -141,8 +142,36 @@ exit; -sub print_http_header_section ($) { - my $input = shift; +sub add_error ($$$) { + my ($layer, $err, $result) = @_; + if (defined $err->{level}) { + if ($err->{level} eq 's') { + $result->{$layer}->{should}++; + $result->{$layer}->{score_min} -= 2; + $result->{conforming_min} = 0; + } elsif ($err->{level} eq 'w' or $err->{level} eq 'g') { + $result->{$layer}->{warning}++; + } elsif ($err->{level} eq 'unsupported') { + $result->{$layer}->{unsupported}++; + $result->{unsupported} = 1; + } else { + $result->{$layer}->{must}++; + $result->{$layer}->{score_max} -= 2; + $result->{$layer}->{score_min} -= 2; + $result->{conforming_min} = 0; + $result->{conforming_max} = 0; + } + } else { + $result->{$layer}->{must}++; + $result->{$layer}->{score_max} -= 2; + $result->{$layer}->{score_min} -= 2; + $result->{conforming_min} = 0; + $result->{conforming_max} = 0; + } +} # add_error + +sub print_http_header_section ($$) { + my ($input, $result) = @_; return unless defined $input->{header_status_code} or defined $input->{header_status_text} or @{$input->{header_field}}; @@ -175,8 +204,8 @@ print STDOUT qq[]; } # print_http_header_section -sub print_syntax_error_html_section ($) { - my $input = shift; +sub print_syntax_error_html_section ($$) { + my ($input, $result) = @_; require Encode; require Whatpm::HTML; @@ -207,6 +236,8 @@ $type =~ s/\|/%7C/g; $msg .= qq[ [Description]]; print STDOUT qq[
$msg
\n]; + + add_error ('syntax', \%opt => $result); }; my $doc = $dom->create_document; @@ -226,8 +257,8 @@ return ($doc, $el); } # print_syntax_error_html_section -sub print_syntax_error_xml_section ($) { - my $input = shift; +sub print_syntax_error_xml_section ($$) { + my ($input, $result) = @_; require Message::DOM::XMLParserTemp; @@ -244,6 +275,14 @@ print STDOUT qq[
Line $line column ]; print STDOUT $err->location->column_number, "
"; print STDOUT htescape $err->text, "
\n"; + + add_error ('syntax', {type => $err->text, + level => [ + $err->SEVERITY_FATAL_ERROR => 'm', + $err->SEVERITY_ERROR => 'm', + $err->SEVERITY_WARNING => 's', + ]->[$err->severity]} => $result); + return 1; }; @@ -374,8 +413,8 @@ print STDOUT qq[]; } # print_structure_dump_section -sub print_structure_error_section ($$) { - my ($doc, $el) = @_; +sub print_structure_error_section ($$$) { + my ($doc, $el, $result) = @_; print STDOUT qq[

Document Errors

@@ -392,6 +431,7 @@ $msg .= qq[ [Description]]; print STDOUT qq[
] . get_node_link ($opt{node}) . qq[
\n
], $msg, "
\n"; + add_error ('structure', \%opt => $result); }; my $elements; @@ -524,6 +564,89 @@ print STDOUT qq[
]; } # print_class_section +sub print_result_section ($) { + my $result = shift; + + print STDOUT qq[ +
+

Result

]; + + if ($result->{unsupported}) { + print STDOUT qq[

The conformance + checker cannot decide whether the document is conforming or + not, since the document contains one or more unsupported + features.

]; + } elsif ($result->{conforming_min}) { + print STDOUT qq[

No conformance-error is + found in this document.

]; + } elsif ($result->{conforming_max}) { + print STDOUT qq[

This document + is likely non-conforming, but in rare case + it might be conforming.

]; + } else { + print STDOUT qq[

This document is + non-conforming.

]; + } + + print STDOUT qq[ ++ + +]; + + my $must_error = 0; + my $should_error = 0; + my $warning = 0; + my $score_min = 0; + my $score_max = 0; + my $score_base = 20; + for ( + [Transfer => 'transfer', ''], + [Character => 'char', ''], + [Syntax => 'syntax', '#parse-errors'], + [Structure => 'structure', '#document-errors'], + ) { + $must_error += ($result->{$_->[1]}->{must} += 0); + $should_error += ($result->{$_->[1]}->{should} += 0); + $warning += ($result->{$_->[1]}->{warning} += 0); + $score_min += ($result->{$_->[1]}->{score_min} += $score_base); + $score_max += ($result->{$_->[1]}->{score_max} += $score_base); + + my $uncertain = $result->{$_->[1]}->{unsupported} ? '?' : ''; + my $label = $_->[0]; + if ($result->{$_->[1]}->{must} or + $result->{$_->[1]}->{should} or + $result->{$_->[1]}->{warning} or + $result->{$_->[1]}->{unsupported}) { + $label = qq[$label]; + } + + print STDOUT qq[]; + if ($uncertain) { + print qq[]; + } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { + print qq[]; + } else { + print qq[]; + } + } + + $score_max += $score_base; + + print STDOUT qq[ + + + +
MUST-level +ErrorsSHOULD-level +ErrorsWarningsScore
$label$result->{$_->[1]}->{must}$uncertain$result->{$_->[1]}->{should}$uncertain$result->{$_->[1]}->{warning}$uncertain−∞..$result->{$_->[1]}->{score_max}$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max} + $score_base
$result->{$_->[1]}->{score_min}
Semantics0?0?0?−∞..$score_base
Total$must_error?$should_error?$warning?−∞..$score_max
+ +

Important: This conformance checking service +is under development. The result above might be wrong.

+
]; + push @nav, ['#result-summary' => 'Result']; +} # print_result_section + sub print_result_unknown_type_section ($) { my $input = shift; @@ -791,4 +914,4 @@ =cut -## $Date: 2007/09/02 08:40:49 $ +## $Date: 2007/09/10 11:51:09 $