| 6 |
/home/wakaba/work/manakai2/lib]; |
/home/wakaba/work/manakai2/lib]; |
| 7 |
use CGI::Carp qw[fatalsToBrowser]; |
use CGI::Carp qw[fatalsToBrowser]; |
| 8 |
use Scalar::Util qw[refaddr]; |
use Scalar::Util qw[refaddr]; |
|
use Time::HiRes qw/time/; |
|
| 9 |
|
|
| 10 |
sub htescape ($) { |
require WebHACC::Input; |
| 11 |
my $s = $_[0]; |
require WebHACC::Result; |
| 12 |
$s =~ s/&/&/g; |
require WebHACC::Output; |
|
$s =~ s/</</g; |
|
|
$s =~ s/>/>/g; |
|
|
$s =~ s/"/"/g; |
|
|
$s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{ |
|
|
sprintf '<var>U+%04X</var>', ord $1; |
|
|
}ge; |
|
|
return $s; |
|
|
} # htescape |
|
| 13 |
|
|
| 14 |
|
my $out; |
| 15 |
|
|
| 16 |
|
require Message::DOM::DOMImplementation; |
| 17 |
|
my $dom = Message::DOM::DOMImplementation->new; |
| 18 |
|
{ |
| 19 |
use Message::CGI::HTTP; |
use Message::CGI::HTTP; |
| 20 |
my $http = Message::CGI::HTTP->new; |
my $http = Message::CGI::HTTP->new; |
| 21 |
|
|
| 23 |
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; |
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; |
| 24 |
exit; |
exit; |
| 25 |
} |
} |
| 26 |
|
|
|
binmode STDOUT, ':utf8'; |
|
|
$| = 1; |
|
|
|
|
|
require Message::DOM::DOMImplementation; |
|
|
my $dom = Message::DOM::DOMImplementation->new; |
|
|
|
|
| 27 |
load_text_catalog ('en'); ## TODO: conneg |
load_text_catalog ('en'); ## TODO: conneg |
| 28 |
|
|
| 29 |
my @nav; |
$out = WebHACC::Output->new; |
| 30 |
print STDOUT qq[Content-Type: text/html; charset=utf-8 |
$out->handle (*STDOUT); |
| 31 |
|
$out->set_utf8; |
| 32 |
|
$out->set_flush; |
| 33 |
|
$out->html (qq[Content-Type: text/html; charset=utf-8 |
| 34 |
|
|
| 35 |
<!DOCTYPE html> |
<!DOCTYPE html> |
| 36 |
<html lang="en"> |
<html lang="en"> |
| 41 |
<body> |
<body> |
| 42 |
<h1><a href="../cc-interface">Web Document Conformance Checker</a> |
<h1><a href="../cc-interface">Web Document Conformance Checker</a> |
| 43 |
(<em>beta</em>)</h1> |
(<em>beta</em>)</h1> |
| 44 |
]; |
]); |
| 45 |
|
|
|
$| = 0; |
|
| 46 |
my $input = get_input_document ($http, $dom); |
my $input = get_input_document ($http, $dom); |
| 47 |
|
$out->input ($input); |
| 48 |
|
$out->unset_flush; |
| 49 |
|
|
| 50 |
my $char_length = 0; |
my $char_length = 0; |
|
my %time; |
|
| 51 |
|
|
| 52 |
print qq[ |
$out->start_section (id => 'document-info', title => 'Information'); |
| 53 |
<div id="document-info" class="section"> |
$out->html (qq[<dl> |
| 54 |
<dl> |
<dt>Request URL</dt> |
| 55 |
<dt>Request URI</dt> |
<dd>]); |
| 56 |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>></code></dd> |
$out->url ($input->{request_uri}); |
| 57 |
<dt>Document URI</dt> |
$out->html (q[<dt>Document URL<!-- HTML5 document's address? --> |
| 58 |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{uri}]}" id=anchor-document-uri>@{[htescape $input->{uri}]}</a>></code> |
<dd>]); |
| 59 |
|
$out->url ($input->{uri}, id => 'anchor-document-url'); |
| 60 |
|
$out->html (q[ |
| 61 |
<script> |
<script> |
| 62 |
document.title = '<' |
document.title = '<' |
| 63 |
+ document.getElementById ('anchor-document-uri').href + '> \\u2014 ' |
+ document.getElementById ('anchor-document-url').href + '> \\u2014 ' |
| 64 |
+ document.title; |
+ document.title; |
| 65 |
</script></dd> |
</script>]); |
| 66 |
]; # no </dl> yet |
## NOTE: no </dl> yet |
|
push @nav, ['#document-info' => 'Information']; |
|
|
|
|
|
if (defined $input->{s}) { |
|
|
$char_length = length $input->{s}; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<dt>Base URI</dt> |
|
|
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>></code></dd> |
|
|
<dt>Internet Media Type</dt> |
|
|
<dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> |
|
|
@{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : defined $input->{official_type} ? $input->{media_type} eq $input->{official_type} ? '' : '<em>(sniffed; official type is: <code class=MIME lang=en>'.htescape ($input->{official_type}).'</code>)' : '<em>(sniffed)</em>']}</dd> |
|
|
<dt>Character Encoding</dt> |
|
|
<dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']} |
|
|
@{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
|
|
<dt>Length</dt> |
|
|
<dd>$char_length byte@{[$char_length == 1 ? '' : 's']}</dd> |
|
|
</dl> |
|
|
</div> |
|
|
]; |
|
|
|
|
|
my $result = {conforming_min => 1, conforming_max => 1}; |
|
|
print_http_header_section ($input, $result); |
|
|
|
|
|
my $doc; |
|
|
my $el; |
|
|
my $manifest; |
|
|
|
|
|
if ($input->{media_type} eq 'text/html') { |
|
|
($doc, $el) = print_syntax_error_html_section ($input, $result); |
|
|
print_source_string_section |
|
|
(\($input->{s}), $input->{charset} || $doc->input_encoding); |
|
|
} elsif ({ |
|
|
'text/xml' => 1, |
|
|
'application/atom+xml' => 1, |
|
|
'application/rss+xml' => 1, |
|
|
'application/svg+xml' => 1, |
|
|
'application/xhtml+xml' => 1, |
|
|
'application/xml' => 1, |
|
|
}->{$input->{media_type}}) { |
|
|
($doc, $el) = print_syntax_error_xml_section ($input, $result); |
|
|
print_source_string_section (\($input->{s}), $doc->input_encoding); |
|
|
} elsif ($input->{media_type} eq 'text/cache-manifest') { |
|
|
## TODO: MUST be text/cache-manifest |
|
|
$manifest = print_syntax_error_manifest_section ($input, $result); |
|
|
print_source_string_section (\($input->{s}), 'utf-8'); |
|
|
} else { |
|
|
## TODO: Change HTTP status code?? |
|
|
print_result_unknown_type_section ($input, $result); |
|
|
} |
|
|
|
|
|
if (defined $doc or defined $el) { |
|
|
print_structure_dump_dom_section ($doc, $el); |
|
|
my $elements = print_structure_error_dom_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}}; |
|
|
} elsif (defined $manifest) { |
|
|
print_structure_dump_manifest_section ($manifest); |
|
|
print_structure_error_manifest_section ($manifest, $result); |
|
|
} |
|
| 67 |
|
|
| 68 |
print_result_section ($result); |
if (defined $input->{s}) { |
| 69 |
} else { |
$char_length = length $input->{s}; |
|
print STDOUT qq[</dl></div>]; |
|
|
print_result_input_error_section ($input); |
|
|
} |
|
| 70 |
|
|
| 71 |
print STDOUT qq[ |
$out->html (qq[<dt>Base URI<dd>]); |
| 72 |
<ul class="navigation" id="nav-items"> |
$out->url ($input->{base_uri}); |
| 73 |
]; |
$out->html (qq[<dt>Internet Media Type</dt> |
| 74 |
for (@nav) { |
<dd><code class="MIME" lang="en">]); |
| 75 |
print STDOUT qq[<li><a href="$_->[0]">$_->[1]</a></li>]; |
$out->text ($input->{media_type}); |
| 76 |
} |
$out->html (qq[</code> ]); |
| 77 |
print STDOUT qq[ |
if ($input->{media_type_overridden}) { |
| 78 |
</ul> |
$out->html ('<em>(overridden)</em>'); |
| 79 |
</body> |
} elsif (defined $input->{official_type}) { |
| 80 |
</html> |
if ($input->{media_type} eq $input->{official_type}) { |
| 81 |
]; |
# |
| 82 |
|
} else { |
| 83 |
for (qw/decode parse parse_html parse_xml parse_manifest |
$out->html ('<em>(sniffed; official type is: <code class=MIME lang=en>'); |
| 84 |
check check_manifest/) { |
$out->text ($input->{official_type}); |
| 85 |
next unless defined $time{$_}; |
$out->html ('</code>)'); |
| 86 |
open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; |
} |
|
print $file $char_length, "\t", $time{$_}, "\n"; |
|
|
} |
|
|
|
|
|
exit; |
|
|
|
|
|
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; |
|
| 87 |
} else { |
} else { |
| 88 |
$result->{$layer}->{must}++; |
$out->html ('<em>(sniffed)</em>'); |
|
$result->{$layer}->{score_max} -= 2; |
|
|
$result->{$layer}->{score_min} -= 2; |
|
|
$result->{conforming_min} = 0; |
|
|
$result->{conforming_max} = 0; |
|
| 89 |
} |
} |
| 90 |
} else { |
$out->html (q[<dt>Character Encoding<dd>]); |
| 91 |
$result->{$layer}->{must}++; |
if (defined $input->{charset}) { |
| 92 |
$result->{$layer}->{score_max} -= 2; |
$out->html ('<code class="charset" lang="en">'); |
| 93 |
$result->{$layer}->{score_min} -= 2; |
$out->text ($input->{charset}); |
| 94 |
$result->{conforming_min} = 0; |
$out->html ('</code>'); |
|
$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}}; |
|
|
|
|
|
push @nav, ['#source-header' => 'HTTP Header']; |
|
|
print STDOUT qq[<div id="source-header" class="section"> |
|
|
<h2>HTTP Header</h2> |
|
|
|
|
|
<p><strong>Note</strong>: Due to the limitation of the |
|
|
network library in use, the content of this section might |
|
|
not be the real header.</p> |
|
|
|
|
|
<table><tbody> |
|
|
]; |
|
|
|
|
|
if (defined $input->{header_status_code}) { |
|
|
print STDOUT qq[<tr><th scope="row">Status code</th>]; |
|
|
print STDOUT qq[<td><code>@{[htescape ($input->{header_status_code})]}</code></td></tr>]; |
|
|
} |
|
|
if (defined $input->{header_status_text}) { |
|
|
print STDOUT qq[<tr><th scope="row">Status text</th>]; |
|
|
print STDOUT qq[<td><code>@{[htescape ($input->{header_status_text})]}</code></td></tr>]; |
|
|
} |
|
|
|
|
|
for (@{$input->{header_field}}) { |
|
|
print STDOUT qq[<tr><th scope="row"><code>@{[htescape ($_->[0])]}</code></th>]; |
|
|
print STDOUT qq[<td><code>@{[htescape ($_->[1])]}</code></td></tr>]; |
|
|
} |
|
|
|
|
|
print STDOUT qq[</tbody></table></div>]; |
|
|
} # print_http_header_section |
|
|
|
|
|
sub print_syntax_error_html_section ($$) { |
|
|
my ($input, $result) = @_; |
|
|
|
|
|
require Encode; |
|
|
require Whatpm::HTML; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Parse Errors</h2> |
|
|
|
|
|
<dl>]; |
|
|
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[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n]; |
|
| 95 |
} else { |
} else { |
| 96 |
$opt{line} = $opt{line} - 1 || 1; |
$out->text ('(none)'); |
|
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n]; |
|
| 97 |
} |
} |
| 98 |
$type =~ tr/ /-/; |
$out->html (' <em>overridden</em>') if $input->{charset_overridden}; |
| 99 |
$type =~ s/\|/%7C/g; |
$out->html (qq[ |
| 100 |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
<dt>Length</dt> |
| 101 |
print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt); |
<dd>$char_length byte@{[$char_length == 1 ? '' : 's']}</dd> |
| 102 |
print STDOUT qq[$msg</dd>\n]; |
</dl> |
|
|
|
|
add_error ('syntax', \%opt => $result); |
|
|
}; |
|
|
|
|
|
my $doc = $dom->create_document; |
|
|
my $el; |
|
|
my $inner_html_element = $http->get_parameter ('e'); |
|
|
if (defined $inner_html_element and length $inner_html_element) { |
|
|
$input->{charset} ||= 'windows-1252'; ## TODO: for now. |
|
|
my $time1 = time; |
|
|
my $t = Encode::decode ($input->{charset}, $input->{s}); |
|
|
$time{decode} = time - $time1; |
|
|
|
|
|
$el = $doc->create_element_ns |
|
|
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
|
|
$time1 = time; |
|
|
Whatpm::HTML->set_inner_html ($el, $t, $onerror); |
|
|
$time{parse} = time - $time1; |
|
|
} else { |
|
|
my $time1 = time; |
|
|
Whatpm::HTML->parse_byte_string |
|
|
($input->{charset}, $input->{s} => $doc, $onerror); |
|
|
$time{parse_html} = time - $time1; |
|
|
} |
|
|
$doc->manakai_charset ($input->{official_charset}) |
|
|
if defined $input->{official_charset}; |
|
|
|
|
|
print STDOUT qq[</dl></div>]; |
|
|
|
|
|
return ($doc, $el); |
|
|
} # print_syntax_error_html_section |
|
|
|
|
|
sub print_syntax_error_xml_section ($$) { |
|
|
my ($input, $result) = @_; |
|
|
|
|
|
require Message::DOM::XMLParserTemp; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Parse Errors</h2> |
|
|
|
|
|
<dl>]; |
|
|
push @nav, ['#parse-errors' => 'Parse Error']; |
|
|
|
|
|
my $onerror = sub { |
|
|
my $err = shift; |
|
|
my $line = $err->location->line_number; |
|
|
print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ]; |
|
|
print STDOUT $err->location->column_number, "</dt><dd>"; |
|
|
print STDOUT htescape $err->text, "</dd>\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; |
|
|
}; |
|
|
|
|
|
my $time1 = time; |
|
|
open my $fh, '<', \($input->{s}); |
|
|
my $doc = Message::DOM::XMLParserTemp->parse_byte_stream |
|
|
($fh => $dom, $onerror, charset => $input->{charset}); |
|
|
$time{parse_xml} = time - $time1; |
|
|
$doc->manakai_charset ($input->{official_charset}) |
|
|
if defined $input->{official_charset}; |
|
|
|
|
|
print STDOUT qq[</dl></div>]; |
|
|
|
|
|
return ($doc, undef); |
|
|
} # print_syntax_error_xml_section |
|
|
|
|
|
sub print_syntax_error_manifest_section ($$) { |
|
|
my ($input, $result) = @_; |
|
|
|
|
|
require Whatpm::CacheManifest; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Parse Errors</h2> |
|
|
|
|
|
<dl>]; |
|
|
push @nav, ['#parse-errors' => 'Parse Error']; |
|
|
|
|
|
my $onerror = sub { |
|
|
my (%opt) = @_; |
|
|
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); |
|
|
print STDOUT qq[<dt class="$cls">], get_error_label (\%opt), qq[</dt>]; |
|
|
$type =~ tr/ /-/; |
|
|
$type =~ s/\|/%7C/g; |
|
|
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
|
|
print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt); |
|
|
print STDOUT qq[$msg</dd>\n]; |
|
|
|
|
|
add_error ('syntax', \%opt => $result); |
|
|
}; |
|
|
|
|
|
my $time1 = time; |
|
|
my $manifest = Whatpm::CacheManifest->parse_byte_string |
|
|
($input->{s}, $input->{uri}, $input->{base_uri}, $onerror); |
|
|
$time{parse_manifest} = time - $time1; |
|
|
|
|
|
print STDOUT qq[</dl></div>]; |
|
|
|
|
|
return $manifest; |
|
|
} # print_syntax_error_manifest_section |
|
|
|
|
|
sub print_source_string_section ($$) { |
|
|
require Encode; |
|
|
my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name |
|
|
return unless $enc; |
|
| 103 |
|
|
| 104 |
my $s = \($enc->decode (${$_[0]})); |
<script src="../cc-script.js"></script> |
| 105 |
my $i = 1; |
]); |
| 106 |
push @nav, ['#source-string' => 'Source']; |
$out->end_section; |
| 107 |
print STDOUT qq[<div id="source-string" class="section"> |
|
| 108 |
<h2>Document Source</h2> |
my $result = WebHACC::Result->new; |
| 109 |
<ol lang="">\n]; |
$result->output ($out); |
| 110 |
if (length $$s) { |
$result->{conforming_min} = 1; |
| 111 |
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
$result->{conforming_max} = 1; |
| 112 |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
check_and_print ($input => $result => $out); |
| 113 |
$i++; |
$result->generate_result_section; |
|
} |
|
|
if ($$s =~ /\G([^\x0A]+)/gc) { |
|
|
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
|
|
} |
|
| 114 |
} else { |
} else { |
| 115 |
print STDOUT q[<li id="line-1"></li>]; |
$out->html ('</dl>'); |
| 116 |
} |
$out->end_section; |
|
print STDOUT "</ol></div>"; |
|
|
} # print_input_string_section |
|
|
|
|
|
sub print_document_tree ($) { |
|
|
my $node = shift; |
|
|
my $r = '<ol class="xoxo">'; |
|
|
|
|
|
my @node = ($node); |
|
|
while (@node) { |
|
|
my $child = shift @node; |
|
|
unless (ref $child) { |
|
|
$r .= $child; |
|
|
next; |
|
|
} |
|
| 117 |
|
|
| 118 |
my $node_id = 'node-'.refaddr $child; |
my $result = WebHACC::Result->new; |
| 119 |
my $nt = $child->node_type; |
$result->output ($out); |
| 120 |
if ($nt == $child->ELEMENT_NODE) { |
$result->{conforming_min} = 0; |
| 121 |
my $child_nsuri = $child->namespace_uri; |
$result->{conforming_max} = 1; |
|
$r .= qq[<li id="$node_id" class="tree-element"><code title="@{[defined $child_nsuri ? $child_nsuri : '']}">] . htescape ($child->tag_name) . |
|
|
'</code>'; ## ISSUE: case |
|
|
|
|
|
if ($child->has_attributes) { |
|
|
$r .= '<ul class="attributes">'; |
|
|
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
|
|
@{$child->attributes}) { |
|
|
$r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $attr->[2] ? htescape ($attr->[2]) : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
|
|
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
|
|
} |
|
|
$r .= '</ul>'; |
|
|
} |
|
|
|
|
|
if ($child->has_child_nodes) { |
|
|
$r .= '<ol class="children">'; |
|
|
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
|
|
} else { |
|
|
$r .= '</li>'; |
|
|
} |
|
|
} elsif ($nt == $child->TEXT_NODE) { |
|
|
$r .= qq'<li id="$node_id" class="tree-text"><q lang="">' . htescape ($child->data) . '</q></li>'; |
|
|
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
|
|
$r .= qq'<li id="$node_id" class="tree-cdata"><code><[CDATA[</code><q lang="">' . htescape ($child->data) . '</q><code>]]></code></li>'; |
|
|
} elsif ($nt == $child->COMMENT_NODE) { |
|
|
$r .= qq'<li id="$node_id" class="tree-comment"><code><!--</code><q lang="">' . htescape ($child->data) . '</q><code>--></code></li>'; |
|
|
} elsif ($nt == $child->DOCUMENT_NODE) { |
|
|
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
|
|
$r .= qq[<ul class="attributes">]; |
|
|
my $cp = $child->manakai_charset; |
|
|
if (defined $cp) { |
|
|
$r .= qq[<li><code>charset</code> parameter = <code>]; |
|
|
$r .= htescape ($cp) . qq[</code></li>]; |
|
|
} |
|
|
$r .= qq[<li><code>inputEncoding</code> = ]; |
|
|
my $ie = $child->input_encoding; |
|
|
if (defined $ie) { |
|
|
$r .= qq[<code>@{[htescape ($ie)]}</code>]; |
|
|
if ($child->manakai_has_bom) { |
|
|
$r .= qq[ (with <code class=charname><abbr>BOM</abbr></code>)]; |
|
|
} |
|
|
} else { |
|
|
$r .= qq[(<code>null</code>)]; |
|
|
} |
|
|
$r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>]; |
|
|
$r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>]; |
|
|
unless ($child->manakai_is_html) { |
|
|
$r .= qq[<li>XML version = <code>@{[htescape ($child->xml_version)]}</code></li>]; |
|
|
if (defined $child->xml_encoding) { |
|
|
$r .= qq[<li>XML encoding = <code>@{[htescape ($child->xml_encoding)]}</code></li>]; |
|
|
} else { |
|
|
$r .= qq[<li>XML encoding = (null)</li>]; |
|
|
} |
|
|
$r .= qq[<li>XML standalone = @{[$child->xml_standalone ? 'true' : 'false']}</li>]; |
|
|
} |
|
|
$r .= qq[</ul>]; |
|
|
if ($child->has_child_nodes) { |
|
|
$r .= '<ol class="children">'; |
|
|
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
|
|
} |
|
|
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
|
|
$r .= qq'<li id="$node_id" class="tree-doctype"><code><!DOCTYPE></code><ul class="attributes">'; |
|
|
$r .= qq[<li class="tree-doctype-name">Name = <q>@{[htescape ($child->name)]}</q></li>]; |
|
|
$r .= qq[<li class="tree-doctype-publicid">Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>]; |
|
|
$r .= qq[<li class="tree-doctype-systemid">System identifier = <q>@{[htescape ($child->system_id)]}</q></li>]; |
|
|
$r .= '</ul></li>'; |
|
|
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
|
|
$r .= qq'<li id="$node_id" class="tree-id"><code><?@{[htescape ($child->target)]}</code> <q>@{[htescape ($child->data)]}</q><code>?></code></li>'; |
|
|
} else { |
|
|
$r .= qq'<li id="$node_id" class="tree-unknown">@{[$child->node_type]} @{[htescape ($child->node_name)]}</li>'; # error |
|
|
} |
|
|
} |
|
|
|
|
|
$r .= '</ol>'; |
|
|
print STDOUT $r; |
|
|
} # print_document_tree |
|
|
|
|
|
sub print_structure_dump_dom_section ($$) { |
|
|
my ($doc, $el) = @_; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="document-tree" class="section"> |
|
|
<h2>Document Tree</h2> |
|
|
]; |
|
|
push @nav, ['#document-tree' => 'Tree']; |
|
|
|
|
|
print_document_tree ($el || $doc); |
|
|
|
|
|
print STDOUT qq[</div>]; |
|
|
} # print_structure_dump_dom_section |
|
|
|
|
|
sub print_structure_dump_manifest_section ($) { |
|
|
my $manifest = shift; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="dump-manifest" class="section"> |
|
|
<h2>Cache Manifest</h2> |
|
|
]; |
|
|
push @nav, ['#dump-manifest' => 'Caceh Manifest']; |
|
|
|
|
|
print STDOUT qq[<dl><dt>Explicit entries</dt>]; |
|
|
for my $uri (@{$manifest->[0]}) { |
|
|
my $euri = htescape ($uri); |
|
|
print STDOUT qq[<dd><code class=uri><<a href="$euri">$euri</a>></code></dd>]; |
|
|
} |
|
| 122 |
|
|
| 123 |
print STDOUT qq[<dt>Fallback entries</dt><dd> |
$input->generate_transfer_sections ($result); |
| 124 |
<table><thead><tr><th scope=row>Oppotunistic Caching Namespace</th> |
$result->generate_result_section; |
|
<th scope=row>Fallback Entry</tr><tbody>]; |
|
|
for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) { |
|
|
my $euri = htescape ($uri); |
|
|
my $euri2 = htescape ($manifest->[1]->{$uri}); |
|
|
print STDOUT qq[<tr><td><code class=uri><<a href="$euri">$euri</a>></code></td> |
|
|
<td><code class=uri><<a href="$euri2">$euri2</a>></code></td>]; |
|
| 125 |
} |
} |
| 126 |
|
|
| 127 |
print STDOUT qq[</table><dt>Online whitelist</dt>]; |
$out->nav_list; |
|
for my $uri (@{$manifest->[2]}) { |
|
|
my $euri = htescape ($uri); |
|
|
print STDOUT qq[<dd><code class=uri><<a href="$euri">$euri</a>></code></dd>]; |
|
|
} |
|
| 128 |
|
|
| 129 |
print STDOUT qq[</dl></div>]; |
exit; |
| 130 |
} # print_structure_dump_manifest_section |
} |
|
|
|
|
sub print_structure_error_dom_section ($$$) { |
|
|
my ($doc, $el, $result) = @_; |
|
| 131 |
|
|
| 132 |
print STDOUT qq[<div id="document-errors" class="section"> |
sub check_and_print ($$$) { |
| 133 |
<h2>Document Errors</h2> |
my ($input, $result, $out) = @_; |
| 134 |
|
my $original_input = $out->input; |
| 135 |
|
$out->input ($input); |
| 136 |
|
|
| 137 |
|
$input->generate_transfer_sections ($result); |
| 138 |
|
|
| 139 |
|
my @subdoc; |
| 140 |
|
|
| 141 |
|
my $checker_class = { |
| 142 |
|
'text/cache-manifest' => 'WebHACC::Language::CacheManifest', |
| 143 |
|
'text/css' => 'WebHACC::Language::CSS', |
| 144 |
|
'text/html' => 'WebHACC::Language::HTML', |
| 145 |
|
'text/x-webidl' => 'WebHACC::Language::WebIDL', |
| 146 |
|
|
| 147 |
|
'text/xml' => 'WebHACC::Language::XML', |
| 148 |
|
'application/atom+xml' => 'WebHACC::Language::XML', |
| 149 |
|
'application/rss+xml' => 'WebHACC::Language::XML', |
| 150 |
|
'image/svg+xml' => 'WebHACC::Language::XML', |
| 151 |
|
'application/xhtml+xml' => 'WebHACC::Language::XML', |
| 152 |
|
'application/xml' => 'WebHACC::Language::XML', |
| 153 |
|
## TODO: Should we make all XML MIME Types fall |
| 154 |
|
## into this category? |
| 155 |
|
|
| 156 |
|
## NOTE: This type has different model from normal XML types. |
| 157 |
|
'application/rdf+xml' => 'WebHACC::Language::XML', |
| 158 |
|
}->{$input->{media_type}} || 'WebHACC::Language::Default'; |
| 159 |
|
|
| 160 |
|
eval qq{ require $checker_class } or die "$0: Loading $checker_class: $@"; |
| 161 |
|
my $checker = $checker_class->new; |
| 162 |
|
$checker->input ($input); |
| 163 |
|
$checker->output ($out); |
| 164 |
|
$checker->result ($result); |
| 165 |
|
|
| 166 |
<dl>]; |
## TODO: A cache manifest MUST be text/cache-manifest |
| 167 |
push @nav, ['#document-errors' => 'Document Error']; |
## TODO: WebIDL media type "text/x-webidl" |
| 168 |
|
|
| 169 |
require Whatpm::ContentChecker; |
$checker->generate_syntax_error_section; |
| 170 |
my $onerror = sub { |
$checker->generate_source_string_section; |
|
my %opt = @_; |
|
|
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}, $opt{node}); |
|
|
$type =~ tr/ /-/; |
|
|
$type =~ s/\|/%7C/g; |
|
|
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
|
|
print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) . |
|
|
qq[</dt>\n<dd class="$cls">], get_error_level_label (\%opt); |
|
|
print STDOUT $msg, "</dd>\n"; |
|
|
add_error ('structure', \%opt => $result); |
|
|
}; |
|
|
|
|
|
my $elements; |
|
|
my $time1 = time; |
|
|
if ($el) { |
|
|
$elements = Whatpm::ContentChecker->check_element ($el, $onerror); |
|
|
} else { |
|
|
$elements = Whatpm::ContentChecker->check_document ($doc, $onerror); |
|
|
} |
|
|
$time{check} = time - $time1; |
|
|
|
|
|
print STDOUT qq[</dl></div>]; |
|
| 171 |
|
|
| 172 |
return $elements; |
$checker->onsubdoc (sub { |
| 173 |
} # print_structure_error_dom_section |
push @subdoc, shift; |
| 174 |
|
}); |
|
sub print_structure_error_manifest_section ($$$) { |
|
|
my ($manifest, $result) = @_; |
|
| 175 |
|
|
| 176 |
print STDOUT qq[<div id="document-errors" class="section"> |
$checker->generate_structure_dump_section; |
| 177 |
<h2>Document Errors</h2> |
$checker->generate_structure_error_section; |
| 178 |
|
$checker->generate_additional_sections; |
| 179 |
|
|
| 180 |
<dl>]; |
=pod |
|
push @nav, ['#document-errors' => 'Document Error']; |
|
| 181 |
|
|
| 182 |
require Whatpm::CacheManifest; |
if (defined $doc or defined $el) { |
|
Whatpm::CacheManifest->check_manifest ($manifest, sub { |
|
|
my %opt = @_; |
|
|
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}, $opt{node}); |
|
|
$type =~ tr/ /-/; |
|
|
$type =~ s/\|/%7C/g; |
|
|
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
|
|
print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) . |
|
|
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
|
|
add_error ('structure', \%opt => $result); |
|
|
}); |
|
| 183 |
|
|
| 184 |
print STDOUT qq[</div>]; |
print_table_section ($input, $elements->{table}) if @{$elements->{table}}; |
| 185 |
} # print_structure_error_manifest_section |
print_listing_section ({ |
| 186 |
|
id => 'identifiers', label => 'IDs', heading => 'Identifiers', |
| 187 |
|
}, $input, $elements->{id}) if keys %{$elements->{id}}; |
| 188 |
|
print_listing_section ({ |
| 189 |
|
id => 'terms', label => 'Terms', heading => 'Terms', |
| 190 |
|
}, $input, $elements->{term}) if keys %{$elements->{term}}; |
| 191 |
|
print_listing_section ({ |
| 192 |
|
id => 'classes', label => 'Classes', heading => 'Classes', |
| 193 |
|
}, $input, $elements->{class}) if keys %{$elements->{class}}; |
| 194 |
|
|
| 195 |
|
print_rdf_section ($input, $elements->{rdf}) if @{$elements->{rdf}}; |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
=cut |
| 199 |
|
|
| 200 |
|
my $id_prefix = 0; |
| 201 |
|
for my $_subinput (@subdoc) { |
| 202 |
|
my $subinput = WebHACC::Input->new; |
| 203 |
|
$subinput->{$_} = $_subinput->{$_} for keys %$_subinput; |
| 204 |
|
$subinput->id_prefix ('subdoc-' . ++$id_prefix); |
| 205 |
|
$subinput->nested (1); |
| 206 |
|
$subinput->{base_uri} = $subinput->{container_node}->base_uri |
| 207 |
|
unless defined $subinput->{base_uri}; |
| 208 |
|
my $ebaseuri = htescape ($subinput->{base_uri}); |
| 209 |
|
$out->start_section (id => $subinput->id_prefix, |
| 210 |
|
title => qq[Subdocument #$id_prefix]); |
| 211 |
|
print STDOUT qq[ |
| 212 |
|
<dl> |
| 213 |
|
<dt>Internet Media Type</dt> |
| 214 |
|
<dd><code class="MIME" lang="en">@{[htescape $subinput->{media_type}]}</code> |
| 215 |
|
<dt>Container Node</dt> |
| 216 |
|
<dd>@{[get_node_link ($input, $subinput->{container_node})]}</dd> |
| 217 |
|
<dt>Base <abbr title="Uniform Resource Identifiers">URI</abbr></dt> |
| 218 |
|
<dd><code class=URI><<a href="$ebaseuri">$ebaseuri</a>></code></dd> |
| 219 |
|
</dl>]; |
| 220 |
|
|
| 221 |
|
$subinput->{id_prefix} .= '-'; |
| 222 |
|
check_and_print ($subinput => $result => $out); |
| 223 |
|
|
| 224 |
|
$out->end_section; |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
$out->input ($original_input); |
| 228 |
|
} # check_and_print |
| 229 |
|
|
| 230 |
sub print_table_section ($) { |
sub print_table_section ($$) { |
| 231 |
my $tables = shift; |
my ($input, $tables) = @_; |
| 232 |
|
|
| 233 |
push @nav, ['#tables' => 'Tables']; |
# push @nav, [qq[#$input->{id_prefix}tables] => 'Tables'] |
| 234 |
|
# unless $input->{nested}; |
| 235 |
print STDOUT qq[ |
print STDOUT qq[ |
| 236 |
<div id="tables" class="section"> |
<div id="$input->{id_prefix}tables" class="section"> |
| 237 |
<h2>Tables</h2> |
<h2>Tables</h2> |
| 238 |
|
|
| 239 |
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]--> |
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]--> |
| 246 |
require JSON; |
require JSON; |
| 247 |
|
|
| 248 |
my $i = 0; |
my $i = 0; |
| 249 |
for my $table_el (@$tables) { |
for my $table (@$tables) { |
| 250 |
$i++; |
$i++; |
| 251 |
print STDOUT qq[<div class="section" id="table-$i"><h3>] . |
print STDOUT qq[<div class="section" id="$input->{id_prefix}table-$i"><h3>] . |
| 252 |
get_node_link ($table_el) . q[</h3>]; |
get_node_link ($input, $table->{element}) . q[</h3>]; |
| 253 |
|
|
| 254 |
## TODO: Make |ContentChecker| return |form_table| result |
delete $table->{element}; |
| 255 |
## so that this script don't have to run the algorithm twice. |
|
| 256 |
my $table = Whatpm::HTMLTable->form_table ($table_el); |
for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}, |
| 257 |
|
@{$table->{row}}) { |
|
for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) { |
|
| 258 |
next unless $_; |
next unless $_; |
| 259 |
delete $_->{element}; |
delete $_->{element}; |
| 260 |
} |
} |
| 280 |
|
|
| 281 |
print STDOUT '</div><script type="text/javascript">tableToCanvas ('; |
print STDOUT '</div><script type="text/javascript">tableToCanvas ('; |
| 282 |
print STDOUT JSON::objToJson ($table); |
print STDOUT JSON::objToJson ($table); |
| 283 |
print STDOUT qq[, document.getElementById ('table-$i'));</script>]; |
print STDOUT qq[, document.getElementById ('$input->{id_prefix}table-$i')]; |
| 284 |
|
print STDOUT qq[, '$input->{id_prefix}');</script>]; |
| 285 |
} |
} |
| 286 |
|
|
| 287 |
print STDOUT qq[</div>]; |
print STDOUT qq[</div>]; |
| 288 |
} # print_table_section |
} # print_table_section |
| 289 |
|
|
| 290 |
sub print_id_section ($) { |
sub print_listing_section ($$$) { |
| 291 |
my $ids = shift; |
my ($opt, $input, $ids) = @_; |
| 292 |
|
|
| 293 |
push @nav, ['#identifiers' => 'IDs']; |
# push @nav, ['#' . $input->{id_prefix} . $opt->{id} => $opt->{label}] |
| 294 |
|
# unless $input->{nested}; |
| 295 |
print STDOUT qq[ |
print STDOUT qq[ |
| 296 |
<div id="identifiers" class="section"> |
<div id="$input->{id_prefix}$opt->{id}" class="section"> |
| 297 |
<h2>Identifiers</h2> |
<h2>$opt->{heading}</h2> |
| 298 |
|
|
| 299 |
<dl> |
<dl> |
| 300 |
]; |
]; |
| 301 |
for my $id (sort {$a cmp $b} keys %$ids) { |
for my $id (sort {$a cmp $b} keys %$ids) { |
| 302 |
print STDOUT qq[<dt><code>@{[htescape $id]}</code></dt>]; |
print STDOUT qq[<dt><code>@{[htescape $id]}</code></dt>]; |
| 303 |
for (@{$ids->{$id}}) { |
for (@{$ids->{$id}}) { |
| 304 |
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
print STDOUT qq[<dd>].get_node_link ($input, $_).qq[</dd>]; |
| 305 |
} |
} |
| 306 |
} |
} |
| 307 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
| 308 |
} # print_id_section |
} # print_listing_section |
|
|
|
|
sub print_term_section ($) { |
|
|
my $terms = shift; |
|
|
|
|
|
push @nav, ['#terms' => 'Terms']; |
|
|
print STDOUT qq[ |
|
|
<div id="terms" class="section"> |
|
|
<h2>Terms</h2> |
|
| 309 |
|
|
|
<dl> |
|
|
]; |
|
|
for my $term (sort {$a cmp $b} keys %$terms) { |
|
|
print STDOUT qq[<dt>@{[htescape $term]}</dt>]; |
|
|
for (@{$terms->{$term}}) { |
|
|
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
|
|
} |
|
|
} |
|
|
print STDOUT qq[</dl></div>]; |
|
|
} # print_term_section |
|
| 310 |
|
|
| 311 |
sub print_class_section ($) { |
sub print_rdf_section ($$$) { |
| 312 |
my $classes = shift; |
my ($input, $rdfs) = @_; |
| 313 |
|
|
| 314 |
push @nav, ['#classes' => 'Classes']; |
# push @nav, ['#' . $input->{id_prefix} . 'rdf' => 'RDF'] |
| 315 |
|
# unless $input->{nested}; |
| 316 |
print STDOUT qq[ |
print STDOUT qq[ |
| 317 |
<div id="classes" class="section"> |
<div id="$input->{id_prefix}rdf" class="section"> |
| 318 |
<h2>Classes</h2> |
<h2>RDF Triples</h2> |
| 319 |
|
|
| 320 |
<dl> |
<dl>]; |
| 321 |
]; |
my $i = 0; |
| 322 |
for my $class (sort {$a cmp $b} keys %$classes) { |
for my $rdf (@$rdfs) { |
| 323 |
print STDOUT qq[<dt><code>@{[htescape $class]}</code></dt>]; |
print STDOUT qq[<dt id="$input->{id_prefix}rdf-@{[$i++]}">]; |
| 324 |
for (@{$classes->{$class}}) { |
print STDOUT get_node_link ($input, $rdf->[0]); |
| 325 |
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
print STDOUT qq[<dd><dl>]; |
| 326 |
|
for my $triple (@{$rdf->[1]}) { |
| 327 |
|
print STDOUT '<dt>' . get_node_link ($input, $triple->[0]) . '<dd>'; |
| 328 |
|
print STDOUT get_rdf_resource_html ($triple->[1]); |
| 329 |
|
print STDOUT ' '; |
| 330 |
|
print STDOUT get_rdf_resource_html ($triple->[2]); |
| 331 |
|
print STDOUT ' '; |
| 332 |
|
print STDOUT get_rdf_resource_html ($triple->[3]); |
| 333 |
} |
} |
| 334 |
|
print STDOUT qq[</dl>]; |
| 335 |
} |
} |
| 336 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
| 337 |
} # print_class_section |
} # print_rdf_section |
|
|
|
|
sub print_result_section ($) { |
|
|
my $result = shift; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="result-summary" class="section"> |
|
|
<h2>Result</h2>]; |
|
|
|
|
|
if ($result->{unsupported} and $result->{conforming_max}) { |
|
|
print STDOUT qq[<p class=uncertain id=result-para>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.</p>]; |
|
|
} elsif ($result->{conforming_min}) { |
|
|
print STDOUT qq[<p class=PASS id=result-para>No conformance-error is |
|
|
found in this document.</p>]; |
|
|
} elsif ($result->{conforming_max}) { |
|
|
print STDOUT qq[<p class=SEE-RESULT id=result-para>This document |
|
|
is <strong>likely <em>non</em>-conforming</strong>, but in rare case |
|
|
it might be conforming.</p>]; |
|
|
} else { |
|
|
print STDOUT qq[<p class=FAIL id=result-para>This document is |
|
|
<strong><em>non</em>-conforming</strong>.</p>]; |
|
|
} |
|
|
|
|
|
print STDOUT qq[<table> |
|
|
<colgroup><col><colgroup><col><col><col><colgroup><col> |
|
|
<thead> |
|
|
<tr><th scope=col></th> |
|
|
<th scope=col><a href="../error-description#level-m"><em class=rfc2119>MUST</em>‐level |
|
|
Errors</a></th> |
|
|
<th scope=col><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>‐level |
|
|
Errors</a></th> |
|
|
<th scope=col><a href="../error-description#level-w">Warnings</a></th> |
|
|
<th scope=col>Score</th></tr></thead><tbody>]; |
|
|
|
|
|
my $must_error = 0; |
|
|
my $should_error = 0; |
|
|
my $warning = 0; |
|
|
my $score_min = 0; |
|
|
my $score_max = 0; |
|
|
my $score_base = 20; |
|
|
my $score_unit = $score_base / 100; |
|
|
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_unit) += $score_base); |
|
|
$score_max += (($result->{$_->[1]}->{score_max} *= $score_unit) += $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[<a href="$_->[2]">$label</a>]; |
|
|
} |
|
|
|
|
|
print STDOUT qq[<tr class="@{[$uncertain ? 'uncertain' : '']}"><th scope=row>$label</th><td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{must}$uncertain</td><td class="@{[$result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">$result->{$_->[1]}->{should}$uncertain</td><td>$result->{$_->[1]}->{warning}$uncertain</td>]; |
|
|
if ($uncertain) { |
|
|
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">−∞..$result->{$_->[1]}->{score_max}</td>]; |
|
|
} elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { |
|
|
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}</td></tr>]; |
|
|
} else { |
|
|
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}</td></tr>]; |
|
|
} |
|
|
} |
|
|
|
|
|
$score_max += $score_base; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>−∞..$score_base</td></tr> |
|
|
</tbody> |
|
|
<tfoot><tr class=uncertain><th scope=row>Total</th> |
|
|
<td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td> |
|
|
<td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td> |
|
|
<td>$warning?</td> |
|
|
<td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>−∞..$score_max</strong></td></tr></tfoot> |
|
|
</table> |
|
|
|
|
|
<p><strong>Important</strong>: This conformance checking service |
|
|
is <em>under development</em>. The result above might be <em>wrong</em>.</p> |
|
|
</div>]; |
|
|
push @nav, ['#result-summary' => 'Result']; |
|
|
} # print_result_section |
|
|
|
|
|
sub print_result_unknown_type_section ($$) { |
|
|
my ($input, $result) = @_; |
|
|
|
|
|
my $euri = htescape ($input->{uri}); |
|
|
print STDOUT qq[ |
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Errors</h2> |
|
| 338 |
|
|
| 339 |
<dl> |
sub get_rdf_resource_html ($) { |
| 340 |
<dt class=unsupported><code><<a href="$euri">$euri</a>></code></dt> |
my $resource = shift; |
| 341 |
<dd class=unsupported><strong><a href="../error-description#level-u">Not |
if (defined $resource->{uri}) { |
| 342 |
supported</a></strong>: |
my $euri = htescape ($resource->{uri}); |
| 343 |
Media type |
return '<code class=uri><<a href="' . $euri . '">' . $euri . |
| 344 |
<code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> |
'</a>></code>'; |
| 345 |
is not supported.</dd> |
} elsif (defined $resource->{bnodeid}) { |
| 346 |
</dl> |
return htescape ('_:' . $resource->{bnodeid}); |
| 347 |
</div> |
} elsif ($resource->{nodes}) { |
| 348 |
]; |
return '(rdf:XMLLiteral)'; |
| 349 |
push @nav, ['#parse-errors' => 'Errors']; |
} elsif (defined $resource->{value}) { |
| 350 |
add_error (char => {level => 'unsupported'} => $result); |
my $elang = htescape (defined $resource->{language} |
| 351 |
add_error (syntax => {level => 'unsupported'} => $result); |
? $resource->{language} : ''); |
| 352 |
add_error (structure => {level => 'unsupported'} => $result); |
my $r = qq[<q lang="$elang">] . htescape ($resource->{value}) . '</q>'; |
| 353 |
} # print_result_unknown_type_section |
if (defined $resource->{datatype}) { |
| 354 |
|
my $euri = htescape ($resource->{datatype}); |
| 355 |
sub print_result_input_error_section ($) { |
$r .= '^^<code class=uri><<a href="' . $euri . '">' . $euri . |
| 356 |
my $input = shift; |
'</a>></code>'; |
| 357 |
print STDOUT qq[<div class="section" id="result-summary"> |
} elsif (length $resource->{language}) { |
| 358 |
<p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p> |
$r .= '@' . htescape ($resource->{language}); |
|
</div>]; |
|
|
push @nav, ['#result-summary' => 'Result']; |
|
|
} # print_Result_input_error_section |
|
|
|
|
|
sub get_error_label ($) { |
|
|
my $err = shift; |
|
|
|
|
|
my $r = ''; |
|
|
|
|
|
if (defined $err->{line}) { |
|
|
if ($err->{column} > 0) { |
|
|
$r = qq[<a href="#line-$err->{line}">Line $err->{line}</a> column $err->{column}]; |
|
|
} else { |
|
|
$err->{line} = $err->{line} - 1 || 1; |
|
|
$r = qq[<a href="#line-$err->{line}">Line $err->{line}</a>]; |
|
| 359 |
} |
} |
| 360 |
} |
return $r; |
|
|
|
|
if (defined $err->{node}) { |
|
|
$r .= ' ' if length $r; |
|
|
$r = get_node_link ($err->{node}); |
|
|
} |
|
|
|
|
|
if (defined $err->{index}) { |
|
|
$r .= ' ' if length $r; |
|
|
$r .= 'Index ' . (0+$err->{index}); |
|
|
} |
|
|
|
|
|
if (defined $err->{value}) { |
|
|
$r .= ' ' if length $r; |
|
|
$r .= '<q><code>' . htescape ($err->{value}) . '</code></q>'; |
|
|
} |
|
|
|
|
|
return $r; |
|
|
} # get_error_label |
|
|
|
|
|
sub get_error_level_label ($) { |
|
|
my $err = shift; |
|
|
|
|
|
my $r = ''; |
|
|
|
|
|
if (not defined $err->{level} or $err->{level} eq 'm') { |
|
|
$r = qq[<strong><a href="../error-description#level-m"><em class=rfc2119>MUST</em>‐level |
|
|
error</a></strong>: ]; |
|
|
} elsif ($err->{level} eq 's') { |
|
|
$r = qq[<strong><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>‐level |
|
|
error</a></strong>: ]; |
|
|
} elsif ($err->{level} eq 'w') { |
|
|
$r = qq[<strong><a href="../error-description#level-w">Warning</a></strong>: |
|
|
]; |
|
|
} elsif ($err->{level} eq 'unsupported') { |
|
|
$r = qq[<strong><a href="../error-description#level-u">Not |
|
|
supported</a></strong>: ]; |
|
| 361 |
} else { |
} else { |
| 362 |
my $elevel = htescape ($err->{level}); |
return '??'; |
|
$r = qq[<strong><a href="../error-description#level-$elevel">$elevel</a></strong>: |
|
|
]; |
|
| 363 |
} |
} |
| 364 |
|
} # get_rdf_resource_html |
|
return $r; |
|
|
} # get_error_level_label |
|
|
|
|
|
sub get_node_path ($) { |
|
|
my $node = shift; |
|
|
my @r; |
|
|
while (defined $node) { |
|
|
my $rs; |
|
|
if ($node->node_type == 1) { |
|
|
$rs = $node->manakai_local_name; |
|
|
$node = $node->parent_node; |
|
|
} elsif ($node->node_type == 2) { |
|
|
$rs = '@' . $node->manakai_local_name; |
|
|
$node = $node->owner_element; |
|
|
} elsif ($node->node_type == 3) { |
|
|
$rs = '"' . $node->data . '"'; |
|
|
$node = $node->parent_node; |
|
|
} elsif ($node->node_type == 9) { |
|
|
@r = ('') unless @r; |
|
|
$rs = ''; |
|
|
$node = $node->parent_node; |
|
|
} else { |
|
|
$rs = '#' . $node->node_type; |
|
|
$node = $node->parent_node; |
|
|
} |
|
|
unshift @r, $rs; |
|
|
} |
|
|
return join '/', @r; |
|
|
} # get_node_path |
|
|
|
|
|
sub get_node_link ($) { |
|
|
return qq[<a href="#node-@{[refaddr $_[0]]}">] . |
|
|
htescape (get_node_path ($_[0])) . qq[</a>]; |
|
|
} # get_node_link |
|
| 365 |
|
|
| 366 |
{ |
{ |
| 367 |
my $Msg = {}; |
my $Msg = {}; |
| 368 |
|
|
| 369 |
sub load_text_catalog ($) { |
sub load_text_catalog ($) { |
| 370 |
|
# my $self = shift; |
| 371 |
my $lang = shift; # MUST be a canonical lang name |
my $lang = shift; # MUST be a canonical lang name |
| 372 |
open my $file, '<:utf8', "cc-msg.$lang.txt" |
open my $file, '<:utf8', "cc-msg.$lang.txt" |
| 373 |
or die "$0: cc-msg.$lang.txt: $!"; |
or die "$0: cc-msg.$lang.txt: $!"; |
| 380 |
} |
} |
| 381 |
} # load_text_catalog |
} # load_text_catalog |
| 382 |
|
|
| 383 |
sub get_text ($) { |
sub get_text ($;$$) { |
| 384 |
|
# my $self = shift; |
| 385 |
my ($type, $level, $node) = @_; |
my ($type, $level, $node) = @_; |
| 386 |
$type = $level . ':' . $type if defined $level; |
$type = $level . ':' . $type if defined $level; |
| 387 |
$level = 'm' unless defined $level; |
$level = 'm' unless defined $level; |
| 390 |
if (defined $Msg->{$type}) { |
if (defined $Msg->{$type}) { |
| 391 |
my $msg = $Msg->{$type}->[1]; |
my $msg = $Msg->{$type}->[1]; |
| 392 |
$msg =~ s{<var>\$([0-9]+)</var>}{ |
$msg =~ s{<var>\$([0-9]+)</var>}{ |
| 393 |
defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'; |
defined $arg[$1] ? ($arg[$1]) : '(undef)'; |
| 394 |
}ge; |
}ge; ##BUG: ^ must be escaped |
| 395 |
$msg =~ s{<var>{\@([A-Za-z0-9:_.-]+)}</var>}{ |
$msg =~ s{<var>{\@([A-Za-z0-9:_.-]+)}</var>}{ |
| 396 |
UNIVERSAL::can ($node, 'get_attribute_ns') |
UNIVERSAL::can ($node, 'get_attribute_ns') |
| 397 |
? htescape ($node->get_attribute_ns (undef, $1)) : '' |
? ($node->get_attribute_ns (undef, $1)) : '' |
| 398 |
}ge; |
}ge; ## BUG: ^ must be escaped |
| 399 |
$msg =~ s{<var>{\@}</var>}{ |
$msg =~ s{<var>{\@}</var>}{ ## BUG: v must be escaped |
| 400 |
UNIVERSAL::can ($node, 'value') ? htescape ($node->value) : '' |
UNIVERSAL::can ($node, 'value') ? ($node->value) : '' |
| 401 |
}ge; |
}ge; |
| 402 |
$msg =~ s{<var>{local-name}</var>}{ |
$msg =~ s{<var>{local-name}</var>}{ |
| 403 |
UNIVERSAL::can ($node, 'manakai_local_name') |
UNIVERSAL::can ($node, 'manakai_local_name') |
| 404 |
? htescape ($node->manakai_local_name) : '' |
? ($node->manakai_local_name) : '' |
| 405 |
}ge; |
}ge; ## BUG: ^ must be escaped |
| 406 |
$msg =~ s{<var>{element-local-name}</var>}{ |
$msg =~ s{<var>{element-local-name}</var>}{ |
| 407 |
(UNIVERSAL::can ($node, 'owner_element') and |
(UNIVERSAL::can ($node, 'owner_element') and |
| 408 |
$node->owner_element) |
$node->owner_element) |
| 409 |
? htescape ($node->owner_element->manakai_local_name) |
? ($node->owner_element->manakai_local_name) |
| 410 |
: '' |
: '' ## BUG: ^ must be escaped |
| 411 |
}ge; |
}ge; |
| 412 |
return ($type, 'level-' . $level . ' ' . $Msg->{$type}->[0], $msg); |
return ($type, 'level-' . $level . ' ' . $Msg->{$type}->[0], $msg); |
| 413 |
} elsif ($type =~ s/:([^:]*)$//) { |
} elsif ($type =~ s/:([^:]*)$//) { |
| 415 |
redo; |
redo; |
| 416 |
} |
} |
| 417 |
} |
} |
| 418 |
return ($type, 'level-'.$level, htescape ($_[0])); |
return ($type, 'level-'.$level, ($_[0])); |
| 419 |
|
## BUG: ^ must be escaped |
| 420 |
} # get_text |
} # get_text |
| 421 |
|
|
| 422 |
} |
} |
| 424 |
sub get_input_document ($$) { |
sub get_input_document ($$) { |
| 425 |
my ($http, $dom) = @_; |
my ($http, $dom) = @_; |
| 426 |
|
|
| 427 |
my $request_uri = $http->get_parameter ('uri'); |
require Encode; |
| 428 |
my $r = {}; |
my $request_uri = Encode::decode ('utf-8', $http->get_parameter ('uri')); |
| 429 |
|
my $r = WebHACC::Input->new; |
| 430 |
if (defined $request_uri and length $request_uri) { |
if (defined $request_uri and length $request_uri) { |
| 431 |
my $uri = $dom->create_uri_reference ($request_uri); |
my $uri = $dom->create_uri_reference ($request_uri); |
| 432 |
unless ({ |
unless ({ |
| 433 |
http => 1, |
http => 1, |
| 434 |
}->{lc $uri->uri_scheme}) { |
}->{lc $uri->uri_scheme}) { |
| 435 |
return {uri => $request_uri, request_uri => $request_uri, |
$r = WebHACC::Input::Error->new; |
| 436 |
error_status_text => 'URI scheme not allowed'}; |
$r->{uri} = $request_uri; |
| 437 |
|
$r->{request_uri} = $request_uri; |
| 438 |
|
$r->{error_status_text} = 'URL scheme not allowed'; |
| 439 |
} |
} |
| 440 |
|
|
| 441 |
require Message::Util::HostPermit; |
require Message::Util::HostPermit; |
| 462 |
Allow host=* |
Allow host=* |
| 463 |
EOH |
EOH |
| 464 |
unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) { |
unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) { |
| 465 |
return {uri => $request_uri, request_uri => $request_uri, |
my $r = WebHACC::Input::Error->new; |
| 466 |
error_status_text => 'Connection to the host is forbidden'}; |
$r->{uri} = $request_uri; |
| 467 |
|
$r->{request_uri} = $request_uri; |
| 468 |
|
$r->{error_status_text} = 'Connection to the host is forbidden'; |
| 469 |
|
return $r; |
| 470 |
} |
} |
| 471 |
|
|
| 472 |
require LWP::UserAgent; |
require LWP::UserAgent; |
| 575 |
return $r; |
return $r; |
| 576 |
} |
} |
| 577 |
|
|
| 578 |
|
$r->{inner_html_element} = $http->get_parameter ('e'); |
| 579 |
|
|
| 580 |
return $r; |
return $r; |
| 581 |
} # get_input_document |
} # get_input_document |
| 582 |
|
|
| 609 |
|
|
| 610 |
=head1 LICENSE |
=head1 LICENSE |
| 611 |
|
|
| 612 |
Copyright 2007 Wakaba <w@suika.fam.cx> |
Copyright 2007-2008 Wakaba <w@suika.fam.cx> |
| 613 |
|
|
| 614 |
This library is free software; you can redistribute it |
This library is free software; you can redistribute it |
| 615 |
and/or modify it under the same terms as Perl itself. |
and/or modify it under the same terms as Perl itself. |