--- test/html-webhacc/cc.cgi 2007/07/16 13:56:26 1.12
+++ test/html-webhacc/cc.cgi 2008/07/21 08:39:12 1.56
@@ -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-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{
- 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;
}
-
- binmode STDOUT, ':utf8';
-
- require Message::DOM::DOMImplementation;
- my $dom = Message::DOM::DOMImplementation->new;
-
- my $input = get_input_document ($http, $dom);
- my $inner_html_element = $http->parameter ('e');
-
+
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,437 +39,129 @@
-Web Document Conformance Checker (beta)
+
+]);
-
-
-- Request URI
- <@{[htescape $input->{request_uri}]}>
-- Document URI
- <@{[htescape $input->{uri}]}>
-]; # no
yet
- push @nav, ['#document-info' => 'Information'];
-
-if (defined $input->{s}) {
-
- print STDOUT qq[
-
Base URI
-
<@{[htescape $input->{base_uri}]}>
-
Internet Media Type
-
@{[htescape $input->{media_type}]}
- @{[$input->{media_type_overridden} ? '(overridden)' : '']}
-
Character Encoding
-
@{[defined $input->{charset} ? ''.htescape ($input->{charset}).'
' : '(none)']}
- @{[$input->{charset_overridden} ? '(overridden)' : '']}
-
-
-];
-
- print_http_header_section ($input);
-
- my $doc;
- my $el;
-
- if ($input->{media_type} eq 'text/html') {
- require Encode;
- require Whatpm::HTML;
-
- $input->{charset} ||= 'ISO-8859-1'; ## TODO: for now.
-
- my $t = Encode::decode ($input->{charset}, $input->{s});
-
- print STDOUT qq[
-
-
Parse Errors
-
-
];
- push @nav, ['#parse-errors' => 'Parse Error'];
-
- my $onerror = sub {
- my (%opt) = @_;
- my ($type, $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];
- }
- $type =~ tr/ /-/;
- $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, $t, $onerror);
- } else {
- Whatpm::HTML->parse_string ($t => $doc, $onerror);
- }
-
- print STDOUT qq[
-
-];
-
- print_source_string_section (\($input->{s}), $input->{charset});
- } elsif ({
- 'text/xml' => 1,
- 'application/xhtml+xml' => 1,
- 'application/xml' => 1,
- }->{$input->{media_type}}) {
- require Message::DOM::XMLParserTemp;
-
- 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, '<', \($input->{s});
- $doc = Message::DOM::XMLParserTemp->parse_byte_stream
- ($fh => $dom, $onerror, charset => $input->{charset});
-
- print STDOUT qq[
-
+ my $input = get_input_document ($http, $dom);
-];
- print_source_string_section (\($input->{s}), $doc->input_encoding);
- } else {
- ## TODO: Change HTTP status code??
- print STDOUT qq[
-
-
Media type @{[htescape $input->{media_type}]}
is not supported!
-
-];
- push @nav, ['#result-summary' => 'Result'];
- }
+ $out->input ($input);
+ $out->unset_flush;
+ my $result = WebHACC::Result->new;
+ $result->output ($out);
+ $result->{conforming_min} = 1;
+ $result->{conforming_max} = 1;
- 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 ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});
- $type =~ tr/ /-/;
- $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);
- }
+ $out->html ('');
- 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};
- $_->{is_header} = $_->{is_header} ? 1 : 0;
- }
- }
- }
-
- print STDOUT '];
- }
-
- print STDOUT qq[
];
- }
-
- 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[
];
- }
- }
+ check_and_print ($input => $result => $out);
+
+ $result->generate_result_section;
- ## TODO: Show result
-} else {
- print STDOUT qq[
-
-
-
-
-
Input Error: @{[htescape ($input->{error_status_text})]}
-
-];
- push @nav, ['#result-summary' => 'Result'];
+ $out->nav_list;
+ exit;
}
- print STDOUT qq[
-
-];
- for (@nav) {
- print STDOUT qq[- $_->[1]
];
- }
- print STDOUT qq[
-
-
-