--- test/html-webhacc/cc.cgi 2008/07/20 14:58:24 1.53 +++ test/html-webhacc/cc.cgi 2008/07/21 09:40:59 1.58 @@ -1,164 +1,66 @@ #!/usr/bin/perl use strict; -use utf8; use lib qw[/home/httpd/html/www/markup/html/whatpm /home/wakaba/work/manakai2/lib]; use CGI::Carp qw[fatalsToBrowser]; -use Scalar::Util qw[refaddr]; require WebHACC::Input; - require WebHACC::Result; - require WebHACC::Output; - -my $out; - require Message::DOM::DOMImplementation; - my $dom = Message::DOM::DOMImplementation->new; { - use Message::CGI::HTTP; + require Message::CGI::HTTP; my $http = Message::CGI::HTTP->new; + require WebHACC::Output; + my $out = WebHACC::Output->new; + $out->handle (*STDOUT); + $out->set_utf8; + if ($http->get_meta_variable ('PATH_INFO') ne '/') { - print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; + $out->http_error (404); exit; } load_text_catalog ('en'); ## TODO: conneg - $out = WebHACC::Output->new; - $out->handle (*STDOUT); - $out->set_utf8; $out->set_flush; - $out->html (qq[Content-Type: text/html; charset=utf-8 - - - -
-]);
- $out->text ($input->{media_type});
- $out->html (qq[
]);
- if ($input->{media_type_overridden}) {
- $out->html ('(overridden)');
- } elsif (defined $input->{official_type}) {
- if ($input->{media_type} eq $input->{official_type}) {
- #
- } else {
- $out->html ('(sniffed; official type is: ');
- $out->text ($input->{official_type});
- $out->html ('
)');
- }
- } else {
- $out->html ('(sniffed)');
- }
- $out->html (q[');
- $out->text ($input->{charset});
- $out->html ('
');
- } else {
- $out->text ('(none)');
- }
- $out->html (' overridden') if $input->{charset_overridden};
- $out->html (qq[
-@{[htescape $subinput->{media_type}]}
- <$ebaseuri>
Note: Due to the limitation of the -network library in use, the content of this section might -not be the real header.
- -Status code | ]; - print STDOUT qq[]; - $out->code ($input->{header_status_code}); - } - if (defined $input->{header_status_text}) { - print STDOUT qq[ |
---|---|
Status text | ]; - print STDOUT qq[]; - $out->code ($input->{header_status_text}); - } - - for (@{$input->{header_field}}) { - print STDOUT qq[ |
]; - $out->code ($_->[0]); - print STDOUT qq[ | ]; - $out->code ($_->[1]); - } - - print STDOUT qq[ |
@{[htescape $id]}
<' . $euri .
- '>
';
- } elsif (defined $resource->{bnodeid}) {
- return htescape ('_:' . $resource->{bnodeid});
- } elsif ($resource->{nodes}) {
- return '(rdf:XMLLiteral)';
- } elsif (defined $resource->{value}) {
- my $elang = htescape (defined $resource->{language}
- ? $resource->{language} : '');
- my $r = qq[] . htescape ($resource->{value}) . '
';
- if (defined $resource->{datatype}) {
- my $euri = htescape ($resource->{datatype});
- $r .= '^^<' . $euri .
- '>
';
- } elsif (length $resource->{language}) {
- $r .= '@' . htescape ($resource->{language});
- }
- return $r;
- } else {
- return '??';
- }
-} # get_rdf_resource_html
-
-sub print_result_section ($) {
- my $result = shift;
-
- $out->start_section (id => 'result-summary',
- title => 'Result');
-
- if ($result->{unsupported} and $result->{conforming_max}) {
- print STDOUT qq[The conformance - checker cannot decide whether the document is conforming or - not, since the document contains one or more unsupported - features. The document might or might not be conforming.
]; - } 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[- | MUST‐level -Errors | -SHOULD‐level -Errors | -Warnings | -Score | ||
---|---|---|---|---|---|---|
$label | $result->{$_->[1]}->{must}$uncertain | $result->{$_->[1]}->{should}$uncertain | $result->{$_->[1]}->{warning}$uncertain | ]; - if ($uncertain) { - print qq[−∞..$result->{$_->[1]}->{score_max}]; - } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { - print qq[ | $result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}]; - } else { - print qq[ | $result->{$_->[1]}->{score_min}]; - } - print qq[ / 20]; - } - - $score_max += $score_base; - - print STDOUT qq[ - |
Semantics | 0? | 0? | 0? | −∞..$score_base / 20 - | ||
Total | -$must_error? | -$should_error? | -$warning? | -−∞..$score_max / 100 - |
Important: This conformance checking service -is under development. The result above might be wrong.
]; - $out->end_section; -} # print_result_section - -sub print_result_input_error_section ($) { - my $input = shift; - $out->start_section (id => 'result-summary', title => 'Result'); - print STDOUT qq[ -Input Error: @{[htescape ($input->{error_status_text})]}
]; - $out->end_section; -} # print_result_input_error_section { my $Msg = {}; @@ -578,18 +177,24 @@ } -sub get_input_document ($$) { - my ($http, $dom) = @_; +sub get_input_document ($) { + my $http = shift; - my $request_uri = $http->get_parameter ('uri'); + require Message::DOM::DOMImplementation; + my $dom = Message::DOM::DOMImplementation->new; + + require Encode; + my $request_uri = Encode::decode ('utf-8', $http->get_parameter ('uri')); my $r = WebHACC::Input->new; if (defined $request_uri and length $request_uri) { my $uri = $dom->create_uri_reference ($request_uri); unless ({ http => 1, }->{lc $uri->uri_scheme}) { - return {uri => $request_uri, request_uri => $request_uri, - error_status_text => 'URI scheme not allowed'}; + $r = WebHACC::Input::Error->new; + $r->{uri} = $request_uri; + $r->{request_uri} = $request_uri; + $r->{error_status_text} = 'URL scheme not allowed'; } require Message::Util::HostPermit; @@ -616,8 +221,11 @@ Allow host=* EOH unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) { - return {uri => $request_uri, request_uri => $request_uri, - error_status_text => 'Connection to the host is forbidden'}; + my $r = WebHACC::Input::Error->new; + $r->{uri} = $request_uri; + $r->{request_uri} = $request_uri; + $r->{error_status_text} = 'Connection to the host is forbidden'; + return $r; } require LWP::UserAgent; @@ -767,4 +375,4 @@ =cut -## $Date: 2008/07/20 14:58:24 $ +## $Date: 2008/07/21 09:40:59 $