/[suikacvs]/test/html-webhacc/cc.cgi
Suika

Diff of /test/html-webhacc/cc.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.41 by wakaba, Sun Mar 16 11:38:47 2008 UTC revision 1.51 by wakaba, Sun May 18 03:47:56 2008 UTC
# Line 173  sub check_and_print ($$) { Line 173  sub check_and_print ($$) {
173              'text/xml' => 1,              'text/xml' => 1,
174              'application/atom+xml' => 1,              'application/atom+xml' => 1,
175              'application/rss+xml' => 1,              'application/rss+xml' => 1,
176              'application/svg+xml' => 1,              'image/svg+xml' => 1,
177              'application/xhtml+xml' => 1,              'application/xhtml+xml' => 1,
178              'application/xml' => 1,              'application/xml' => 1,
179                ## TODO: Should we make all XML MIME Types fall
180                ## into this category?
181    
182                'application/rdf+xml' => 1, ## NOTE: This type has different model.
183             }->{$input->{media_type}}) {             }->{$input->{media_type}}) {
184      ($doc, $el) = print_syntax_error_xml_section ($input, $result);      ($doc, $el) = print_syntax_error_xml_section ($input, $result);
185      print_source_string_section ($input,      print_source_string_section ($input,
# Line 214  sub check_and_print ($$) { Line 218  sub check_and_print ($$) {
218      print_listing_section ({      print_listing_section ({
219        id => 'classes', label => 'Classes', heading => 'Classes',        id => 'classes', label => 'Classes', heading => 'Classes',
220      }, $input, $elements->{class}) if keys %{$elements->{class}};      }, $input, $elements->{class}) if keys %{$elements->{class}};
221        print_uri_section ($input, $elements->{uri}) if keys %{$elements->{uri}};
222        print_rdf_section ($input, $elements->{rdf}) if @{$elements->{rdf}};
223    } elsif (defined $cssom) {    } elsif (defined $cssom) {
224      print_structure_dump_cssom_section ($input, $cssom);      print_structure_dump_cssom_section ($input, $cssom);
225      ## TODO: CSSOM validation      ## TODO: CSSOM validation
# Line 317  sub print_syntax_error_html_section ($$) Line 323  sub print_syntax_error_html_section ($$)
323    if (defined $inner_html_element and length $inner_html_element) {    if (defined $inner_html_element and length $inner_html_element) {
324      $input->{charset} ||= 'windows-1252'; ## TODO: for now.      $input->{charset} ||= 'windows-1252'; ## TODO: for now.
325      my $time1 = time;      my $time1 = time;
326      my $t = Encode::decode ($input->{charset}, $input->{s});      my $t = \($input->{s});
327        unless ($input->{is_char_string}) {
328          $t = \(Encode::decode ($input->{charset}, $$t));
329        }
330      $time{decode} = time - $time1;      $time{decode} = time - $time1;
331            
332      $el = $doc->create_element_ns      $el = $doc->create_element_ns
333          ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]);          ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]);
334      $time1 = time;      $time1 = time;
335      Whatpm::HTML->set_inner_html ($el, $t, $onerror);      Whatpm::HTML->set_inner_html ($el, $$t, $onerror);
336      $time{parse} = time - $time1;      $time{parse} = time - $time1;
337    } else {    } else {
338      my $time1 = time;      my $time1 = time;
339      Whatpm::HTML->parse_byte_string      if ($input->{is_char_string}) {
340          ($input->{charset}, $input->{s} => $doc, $onerror);        Whatpm::HTML->parse_char_string ($input->{s} => $doc, $onerror);
341        } else {
342          Whatpm::HTML->parse_byte_string
343              ($input->{charset}, $input->{s} => $doc, $onerror);
344        }
345      $time{parse_html} = time - $time1;      $time{parse_html} = time - $time1;
346    }    }
347    $doc->manakai_charset ($input->{official_charset})    $doc->manakai_charset ($input->{official_charset})
# Line 368  sub print_syntax_error_xml_section ($$) Line 381  sub print_syntax_error_xml_section ($$)
381      return 1;      return 1;
382    };    };
383    
384      my $t = \($input->{s});
385      if ($input->{is_char_string}) {
386        require Encode;
387        $t = \(Encode::encode ('utf8', $$t));
388        $input->{charset} = 'utf-8';
389      }
390    
391    my $time1 = time;    my $time1 = time;
392    open my $fh, '<', \($input->{s});    open my $fh, '<', $t;
393    my $doc = Message::DOM::XMLParserTemp->parse_byte_stream    my $doc = Message::DOM::XMLParserTemp->parse_byte_stream
394        ($fh => $dom, $onerror, charset => $input->{charset});        ($fh => $dom, $onerror, charset => $input->{charset});
395    $time{parse_xml} = time - $time1;    $time{parse_xml} = time - $time1;
# Line 642  sub print_syntax_error_manifest_section Line 662  sub print_syntax_error_manifest_section
662      add_error ('syntax', \%opt => $result);      add_error ('syntax', \%opt => $result);
663    };    };
664    
665      my $m = $input->{is_char_string} ? 'parse_char_string' : 'parse_byte_string';
666    my $time1 = time;    my $time1 = time;
667    my $manifest = Whatpm::CacheManifest->parse_byte_string    my $manifest = Whatpm::CacheManifest->$m
668        ($input->{s}, $input->{uri}, $input->{base_uri}, $onerror);        ($input->{s}, $input->{uri}, $input->{base_uri}, $onerror);
669    $time{parse_manifest} = time - $time1;    $time{parse_manifest} = time - $time1;
670    
# Line 656  sub print_source_string_section ($$$) { Line 677  sub print_source_string_section ($$$) {
677    my $input = shift;    my $input = shift;
678    my $s;    my $s;
679    unless ($input->{is_char_string}) {    unless ($input->{is_char_string}) {
680      require Encode;      open my $byte_stream, '<', $_[0];
681      my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name      require Message::Charset::Info;
682      return unless $enc;      my $charset = Message::Charset::Info->get_by_iana_name ($_[1]);
683        my ($char_stream, $e_status) = $charset->get_decode_handle
684            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1);
685        return unless $char_stream;
686    
687        $char_stream->onerror (sub {
688          my (undef, $type, %opt) = @_;
689          if ($opt{octets}) {
690            ${$opt{octets}} = "\x{FFFD}";
691          }
692        });
693    
694      $s = \($enc->decode (${$_[0]}));      my $t = '';
695        while (1) {
696          my $c = $char_stream->getc;
697          last unless defined $c;
698          $t .= $c;
699        }
700        $s = \$t;
701        ## TODO: Output for each line, don't concat all of lines.
702    } else {    } else {
703      $s = $_[0];      $s = $_[0];
704    }    }
# Line 684  sub print_source_string_section ($$$) { Line 722  sub print_source_string_section ($$$) {
722      print STDOUT q[<li id="$input->{id_prefix}line-1"></li>];      print STDOUT q[<li id="$input->{id_prefix}line-1"></li>];
723    }    }
724    print STDOUT "</ol></div>    print STDOUT "</ol></div>
725  <script> addSourceToParseErrorList ('$input->{id_prefix}'); </script>";  <script>
726      addSourceToParseErrorList ('$input->{id_prefix}', 'parse-errors-list');
727    </script>";
728  } # print_input_string_section  } # print_input_string_section
729    
730  sub print_document_tree ($$) {  sub print_document_tree ($$) {
# Line 853  sub print_structure_error_dom_section ($ Line 893  sub print_structure_error_dom_section ($
893    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">
894  <h2>Document Errors</h2>  <h2>Document Errors</h2>
895    
896  <dl>];  <dl id=document-errors-list>];
897    push @nav, [qq[#$input->{id_prefix}document-errors] => 'Document Error']    push @nav, [qq[#$input->{id_prefix}document-errors] => 'Document Error']
898        unless $input->{nested};        unless $input->{nested};
899    
# Line 881  sub print_structure_error_dom_section ($ Line 921  sub print_structure_error_dom_section ($
921    }    }
922    $time{check} = time - $time1;    $time{check} = time - $time1;
923    
924    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl>
925    <script>
926      addSourceToParseErrorList ('$input->{id_prefix}', 'document-errors-list');
927    </script></div>];
928    
929    return $elements;    return $elements;
930  } # print_structure_error_dom_section  } # print_structure_error_dom_section
# Line 930  sub print_table_section ($$) { Line 973  sub print_table_section ($$) {
973    require JSON;    require JSON;
974        
975    my $i = 0;    my $i = 0;
976    for my $table_el (@$tables) {    for my $table (@$tables) {
977      $i++;      $i++;
978      print STDOUT qq[<div class="section" id="$input->{id_prefix}table-$i"><h3>] .      print STDOUT qq[<div class="section" id="$input->{id_prefix}table-$i"><h3>] .
979          get_node_link ($input, $table_el) . q[</h3>];          get_node_link ($input, $table->{element}) . q[</h3>];
980    
981      ## TODO: Make |ContentChecker| return |form_table| result      delete $table->{element};
982      ## so that this script don't have to run the algorithm twice.  
983      my $table = Whatpm::HTMLTable->form_table ($table_el);      for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption},
984                 @{$table->{row}}) {
     for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) {  
985        next unless $_;        next unless $_;
986        delete $_->{element};        delete $_->{element};
987      }      }
# Line 992  sub print_listing_section ($$$) { Line 1034  sub print_listing_section ($$$) {
1034    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl></div>];
1035  } # print_listing_section  } # print_listing_section
1036    
1037    sub print_uri_section ($$$) {
1038      my ($input, $uris) = @_;
1039    
1040      ## NOTE: URIs contained in the DOM (i.e. in HTML or XML documents),
1041      ## except for those in RDF triples.
1042      ## TODO: URIs in CSS
1043      
1044      push @nav, ['#' . $input->{id_prefix} . 'uris' => 'URIs']
1045          unless $input->{nested};
1046      print STDOUT qq[
1047    <div id="$input->{id_prefix}uris" class="section">
1048    <h2>URIs</h2>
1049    
1050    <dl>];
1051      for my $uri (sort {$a cmp $b} keys %$uris) {
1052        my $euri = htescape ($uri);
1053        print STDOUT qq[<dt><code class=uri>&lt;<a href="$euri">$euri</a>></code>];
1054        my $eccuri = htescape (get_cc_uri ($uri));
1055        print STDOUT qq[<dd><a href="$eccuri">Check conformance of this document</a>];
1056        print STDOUT qq[<dd>Found at: <ul>];
1057        for my $entry (@{$uris->{$uri}}) {
1058          print STDOUT qq[<li>], get_node_link ($input, $entry->{node});
1059          if (keys %{$entry->{type} or {}}) {
1060            print STDOUT ' (';
1061            print STDOUT join ', ', map {
1062              {
1063                hyperlink => 'Hyperlink',
1064                resource => 'Link to an external resource',
1065                namespace => 'Namespace URI',
1066                cite => 'Citation or link to a long description',
1067                embedded => 'Link to an embedded content',
1068                base => 'Base URI',
1069                action => 'Submission URI',
1070              }->{$_}
1071                or
1072              htescape ($_)
1073            } keys %{$entry->{type}};
1074            print STDOUT ')';
1075          }
1076        }
1077        print STDOUT qq[</ul>];
1078      }
1079      print STDOUT qq[</dl></div>];
1080    } # print_uri_section
1081    
1082    sub print_rdf_section ($$$) {
1083      my ($input, $rdfs) = @_;
1084      
1085      push @nav, ['#' . $input->{id_prefix} . 'rdf' => 'RDF']
1086          unless $input->{nested};
1087      print STDOUT qq[
1088    <div id="$input->{id_prefix}rdf" class="section">
1089    <h2>RDF Triples</h2>
1090    
1091    <dl>];
1092      my $i = 0;
1093      for my $rdf (@$rdfs) {
1094        print STDOUT qq[<dt id="$input->{id_prefix}rdf-@{[$i++]}">];
1095        print STDOUT get_node_link ($input, $rdf->[0]);
1096        print STDOUT qq[<dd><dl>];
1097        for my $triple (@{$rdf->[1]}) {
1098          print STDOUT '<dt>' . get_node_link ($input, $triple->[0]) . '<dd>';
1099          print STDOUT get_rdf_resource_html ($triple->[1]);
1100          print STDOUT ' ';
1101          print STDOUT get_rdf_resource_html ($triple->[2]);
1102          print STDOUT ' ';
1103          print STDOUT get_rdf_resource_html ($triple->[3]);
1104        }
1105        print STDOUT qq[</dl>];
1106      }
1107      print STDOUT qq[</dl></div>];
1108    } # print_rdf_section
1109    
1110    sub get_rdf_resource_html ($) {
1111      my $resource = shift;
1112      if (defined $resource->{uri}) {
1113        my $euri = htescape ($resource->{uri});
1114        return '<code class=uri>&lt;<a href="' . $euri . '">' . $euri .
1115            '</a>></code>';
1116      } elsif (defined $resource->{bnodeid}) {
1117        return htescape ('_:' . $resource->{bnodeid});
1118      } elsif ($resource->{nodes}) {
1119        return '(rdf:XMLLiteral)';
1120      } elsif (defined $resource->{value}) {
1121        my $elang = htescape (defined $resource->{language}
1122                                  ? $resource->{language} : '');
1123        my $r = qq[<q lang="$elang">] . htescape ($resource->{value}) . '</q>';
1124        if (defined $resource->{datatype}) {
1125          my $euri = htescape ($resource->{datatype});
1126          $r .= '^^<code class=uri>&lt;<a href="' . $euri . '">' . $euri .
1127              '</a>></code>';
1128        } elsif (length $resource->{language}) {
1129          $r .= '@' . htescape ($resource->{language});
1130        }
1131        return $r;
1132      } else {
1133        return '??';
1134      }
1135    } # get_rdf_resource_html
1136    
1137  sub print_result_section ($) {  sub print_result_section ($) {
1138    my $result = shift;    my $result = shift;
1139    
# Line 1057  Errors</a></th> Line 1199  Errors</a></th>
1199    
1200      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>];      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>];
1201      if ($uncertain) {      if ($uncertain) {
1202        print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">&#x2212;&#x221E;..$result->{$_->[1]}->{score_max}</td>];        print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">&#x2212;&#x221E;..$result->{$_->[1]}->{score_max}];
1203      } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) {      } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) {
1204        print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}</td></tr>];        print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}];
1205      } else {      } else {
1206        print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}</td></tr>];        print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}];
1207      }      }
1208        print qq[ / 20];
1209    }    }
1210    
1211    $score_max += $score_base;    $score_max += $score_base;
1212    
1213    print STDOUT qq[    print STDOUT qq[
1214  <tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>&#x2212;&#x221E;..$score_base</td></tr>  <tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>&#x2212;&#x221E;..$score_base / 20
1215  </tbody>  </tbody>
1216  <tfoot><tr class=uncertain><th scope=row>Total</th>  <tfoot><tr class=uncertain><th scope=row>Total</th>
1217  <td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td>  <td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td>
1218  <td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td>  <td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td>
1219  <td>$warning?</td>  <td>$warning?</td>
1220  <td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>&#x2212;&#x221E;..$score_max</strong></td></tr></tfoot>  <td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>&#x2212;&#x221E;..$score_max</strong> / 100
1221  </table>  </table>
1222    
1223  <p><strong>Important</strong>: This conformance checking service  <p><strong>Important</strong>: This conformance checking service
# Line 1121  sub get_error_label ($$) { Line 1264  sub get_error_label ($$) {
1264    
1265    my $r = '';    my $r = '';
1266    
1267    if (defined $err->{token} and defined $err->{token}->{line}) {    my $line;
1268      if ($err->{token}->{column} > 0) {    my $column;
1269        $r = qq[<a href="#$input->{id_prefix}line-$err->{token}->{line}">Line $err->{token}->{line}</a> column $err->{token}->{column}];      
1270      if (defined $err->{node}) {
1271        $line = $err->{node}->get_user_data ('manakai_source_line');
1272        if (defined $line) {
1273          $column = $err->{node}->get_user_data ('manakai_source_column');
1274      } else {      } else {
1275        $err->{token}->{line} = $err->{token}->{line} - 1 || 1;        if ($err->{node}->node_type == $err->{node}->ATTRIBUTE_NODE) {
1276        $r = qq[<a href="#$input->{id_prefix}line-$err->{token}->{line}">Line $err->{token}->{line}</a>];          my $owner = $err->{node}->owner_element;
1277            $line = $owner->get_user_data ('manakai_source_line');
1278            $column = $owner->get_user_data ('manakai_source_column');
1279          } else {
1280            my $parent = $err->{node}->parent_node;
1281            if ($parent) {
1282              $line = $parent->get_user_data ('manakai_source_line');
1283              $column = $parent->get_user_data ('manakai_source_column');
1284            }
1285          }
1286        }
1287      }
1288      unless (defined $line) {
1289        if (defined $err->{token} and defined $err->{token}->{line}) {
1290          $line = $err->{token}->{line};
1291          $column = $err->{token}->{column};
1292        } elsif (defined $err->{line}) {
1293          $line = $err->{line};
1294          $column = $err->{column};
1295      }      }
1296    } elsif (defined $err->{line}) {    }
1297      if ($err->{column} > 0) {  
1298        $r = qq[<a href="#$input->{id_prefix}line-$err->{line}">Line $err->{line}</a> column $err->{column}];    if (defined $line) {
1299        if (defined $column and $column > 0) {
1300          $r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a> column $column];
1301      } else {      } else {
1302        $err->{line} = $err->{line} - 1 || 1;        $line = $line - 1 || 1;
1303        $r = qq[<a href="#$input->{id_prefix}line-$err->{line}">Line $err->{line}</a>];        $r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a>];
1304      }      }
1305    }    }
1306    
1307    if (defined $err->{node}) {    if (defined $err->{node}) {
1308      $r .= ' ' if length $r;      $r .= ' ' if length $r;
1309      $r = get_node_link ($input, $err->{node});      $r .= get_node_link ($input, $err->{node});
1310    }    }
1311    
1312    if (defined $err->{index}) {    if (defined $err->{index}) {
# Line 1193  sub get_node_path ($) { Line 1360  sub get_node_path ($) {
1360    while (defined $node) {    while (defined $node) {
1361      my $rs;      my $rs;
1362      if ($node->node_type == 1) {      if ($node->node_type == 1) {
1363        $rs = $node->manakai_local_name;        $rs = $node->node_name;
1364        $node = $node->parent_node;        $node = $node->parent_node;
1365      } elsif ($node->node_type == 2) {      } elsif ($node->node_type == 2) {
1366        $rs = '@' . $node->manakai_local_name;        $rs = '@' . $node->node_name;
1367        $node = $node->owner_element;        $node = $node->owner_element;
1368      } elsif ($node->node_type == 3) {      } elsif ($node->node_type == 3) {
1369        $rs = '"' . $node->data . '"';        $rs = '"' . $node->data . '"';
# Line 1274  sub get_text ($) { Line 1441  sub get_text ($) {
1441    
1442  }  }
1443    
1444    sub encode_uri_component ($) {
1445      require Encode;
1446      my $s = Encode::encode ('utf8', shift);
1447      $s =~ s/([^0-9A-Za-z_.~-])/sprintf '%%%02X', ord $1/ge;
1448      return $s;
1449    } # encode_uri_component
1450    
1451    sub get_cc_uri ($) {
1452      return './?uri=' . encode_uri_component ($_[0]);
1453    } # get_cc_uri
1454    
1455  sub get_input_document ($$) {  sub get_input_document ($$) {
1456    my ($http, $dom) = @_;    my ($http, $dom) = @_;
1457    

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.51

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24