--- test/html-webhacc/cc.cgi 2007/07/01 10:02:24 1.8
+++ test/html-webhacc/cc.cgi 2008/07/21 09:15:55 1.57
@@ -1,47 +1,36 @@
#!/usr/bin/perl
use strict;
+use utf8;
use lib qw[/home/httpd/html/www/markup/html/whatpm
- /home/wakaba/work/manakai/lib
- /home/wakaba/public_html/-temp/wiki/lib];
+ /home/wakaba/work/manakai2/lib];
use CGI::Carp qw[fatalsToBrowser];
use Scalar::Util qw[refaddr];
-use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module
+ require WebHACC::Input;
+ require WebHACC::Result;
+ require WebHACC::Output;
-sub htescape ($) {
- my $s = $_[0];
- $s =~ s/&/&/g;
- $s =~ s/</g;
- $s =~ s/>/>/g;
- $s =~ s/"/"/g;
- $s =~ s!([\x00-\x09\x0B-\x1F\x7F-\x80])!sprintf 'U+%04X', ord $1!ge;
- return $s;
-} # htescape
+my $out;
-my $http = SuikaWiki::Input::HTTP->new;
-
-## TODO: _charset_
+ require Message::DOM::DOMImplementation;
+ my $dom = Message::DOM::DOMImplementation->new;
+{
+ use Message::CGI::HTTP;
+ my $http = Message::CGI::HTTP->new;
- if ($http->meta_variable ('PATH_INFO') ne '/') {
+ if ($http->get_meta_variable ('PATH_INFO') ne '/') {
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400";
exit;
}
-
- my $input_format = $http->parameter ('i') || 'text/html';
- my $inner_html_element = $http->parameter ('e');
- my $input_uri = 'thismessage:/';
-
- my $s = $http->parameter ('s');
- if (length $s > 1000_000) {
- print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long";
- exit;
- }
-
+
load_text_catalog ('en'); ## TODO: conneg
- my @nav;
- print STDOUT qq[Content-Type: text/html; charset=utf-8
+ $out = WebHACC::Output->new;
+ $out->handle (*STDOUT);
+ $out->set_utf8;
+ $out->set_flush;
+ $out->html (qq[Content-Type: text/html; charset=utf-8
@@ -50,382 +39,110 @@
-Web Document Conformance Checker (beta)
+
+]);
-
-
-- Document URI
- <@{[htescape $input_uri]}>
-- Internet Media Type
- @{[htescape $input_format]}
-]; # no
yet
- push @nav, ['#document-info' => 'Information'];
+ my $input = get_input_document ($http, $dom);
- require Message::DOM::DOMImplementation;
- my $dom = Message::DOM::DOMImplementation->____new;
- my $doc;
- my $el;
-
- if ($input_format eq 'text/html') {
- require Encode;
- require Whatpm::HTML;
-
- $s = Encode::decode ('utf-8', $s);
-
- print STDOUT qq[
-
Character Encoding
-
(none)
-
-
-
-
-
Document Source
-];
- push @nav, ['#source-string' => 'Source'];
- print_source_string (\$s);
- print STDOUT qq[
-
-
-
-
Parse Errors
-
-
-];
- push @nav, ['#parse-errors' => 'Parse Error'];
-
- my $onerror = sub {
- my (%opt) = @_;
- my ($cls, $msg) = get_text ($opt{type}, $opt{level});
- if ($opt{column} > 0) {
- print STDOUT qq[- Line $opt{line} column $opt{column}
\n];
- } else {
- $opt{line} = $opt{line} - 1 || 1;
- print STDOUT qq[- Line $opt{line}
\n];
- }
- $opt{type} =~ tr/ /-/;
- $opt{type} =~ s/\|/%7C/g;
- $msg .= qq[ [Description]];
- print STDOUT qq[- $msg
\n];
- };
-
- $doc = $dom->create_document;
- if (defined $inner_html_element and length $inner_html_element) {
- $el = $doc->create_element_ns
- ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]);
- Whatpm::HTML->set_inner_html ($el, $s, $onerror);
- } else {
- Whatpm::HTML->parse_string ($s => $doc, $onerror);
- }
+ $out->input ($input);
+ $out->unset_flush;
- print STDOUT qq[
-
-
-];
- } elsif ($input_format eq 'application/xhtml+xml') {
- require Message::DOM::XMLParserTemp;
- require Encode;
-
- my $t = Encode::decode ('utf-8', $s);
-
- print STDOUT qq[
-Character Encoding
- (none)
-
-
-
-
-
Document Source
-];
- push @nav, ['#source-string' => 'Source'];
- print_source_string (\$t);
- print STDOUT qq[
-
-
-
-
Parse Errors
-
-
];
- push @nav, ['#parse-errors' => 'Parse Error'];
-
- my $onerror = sub {
- my $err = shift;
- my $line = $err->location->line_number;
- print STDOUT qq[- Line $line column ];
- print STDOUT $err->location->column_number, "
- ";
- print STDOUT htescape $err->text, "
\n";
- return 1;
- };
-
- open my $fh, '<', \$s;
- $doc = Message::DOM::XMLParserTemp->parse_byte_stream
- ($fh => $dom, $onerror, charset => 'utf-8');
-
- print STDOUT qq[
-
-];
- } else {
- print STDOUT qq[
-
-
-
-
-
Media type @{[htescape $input_format]}
is not supported!
-
-];
- push @nav, ['#result-summary' => 'Result'];
- }
+ my $result = WebHACC::Result->new;
+ $result->output ($out);
+ $result->{conforming_min} = 1;
+ $result->{conforming_max} = 1;
+ $out->html ('');
- if (defined $doc or defined $el) {
- print STDOUT qq[
-
-
Document Tree
-];
- push @nav, ['#document-tree' => 'Tree'];
-
- print_document_tree ($el || $doc);
-
- print STDOUT qq[
-
-
-
-
Document Errors
-
-
];
- push @nav, ['#document-errors' => 'Document Error'];
-
- require Whatpm::ContentChecker;
- my $onerror = sub {
- my %opt = @_;
- my ($cls, $msg) = get_text ($opt{type}, $opt{level});
- $opt{type} = $opt{level} . ':' . $opt{type} if defined $opt{level};
- $opt{type} =~ tr/ /-/;
- $opt{type} =~ s/\|/%7C/g;
- $msg .= qq[ [Description]];
- print STDOUT qq[- ] . get_node_link ($opt{node}) .
- qq[
\n- ], $msg, "
\n";
- };
-
- my $elements;
- if ($el) {
- $elements = Whatpm::ContentChecker->check_element ($el, $onerror);
- } else {
- $elements = Whatpm::ContentChecker->check_document ($doc, $onerror);
- }
+ check_and_print ($input => $result => $out);
+
+ $result->generate_result_section;
- print STDOUT qq[
-
-];
-
- if (@{$elements->{table}}) {
- require JSON;
-
- print STDOUT qq[
-
-
Tables
-
-
-
-
-];
-
- my $i = 0;
- for my $table_el (@{$elements->{table}}) {
- $i++;
- print STDOUT qq[
] .
- get_node_link ($table_el) . q[
];
-
- my $table = Whatpm::HTMLTable->form_table ($table_el);
-
- for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) {
- next unless $_;
- delete $_->{element};
- }
-
- for (@{$table->{row_group}}) {
- next unless $_;
- next unless $_->{element};
- $_->{type} = $_->{element}->manakai_local_name;
- delete $_->{element};
- }
-
- for (@{$table->{cell}}) {
- next unless $_;
- for (@{$_}) {
- next unless $_;
- for (@$_) {
- $_->{id} = refaddr $_->{element} if defined $_->{element};
- delete $_->{element};
- }
- }
- }
-
- print STDOUT '];
- }
-
- print STDOUT qq[
];
- }
+ $out->nav_list;
- if (keys %{$elements->{term}}) {
- print STDOUT qq[
-
-
Terms
-
-
-];
- for my $term (sort {$a cmp $b} keys %{$elements->{term}}) {
- print STDOUT qq[- @{[htescape $term]}
];
- for (@{$elements->{term}->{$term}}) {
- print STDOUT qq[- ].get_node_link ($_).qq[
];
- }
- }
- print STDOUT qq[
];
- }
- }
-
- ## TODO: Show result
-
- print STDOUT qq[
-
-];
- for (@nav) {
- print STDOUT qq[- $_->[1]
];
- }
- print STDOUT qq[
-
-
-