/[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.40 by wakaba, Sun Mar 16 07:08:34 2008 UTC revision 1.50 by wakaba, Tue May 6 08:47:09 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 671  sub print_source_string_section ($$$) { Line 692  sub print_source_string_section ($$$) {
692  <h2>Document Source</h2>  <h2>Document Source</h2>
693  <ol lang="">\n];  <ol lang="">\n];
694    if (length $$s) {    if (length $$s) {
695      while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {      while ($$s =~ /\G([^\x0D\x0A]*?)(?>\x0D\x0A?|\x0A)/gc) {
696        print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1,        print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1,
697            "</li>\n";            "</li>\n";
698        $i++;        $i++;
699      }      }
700      if ($$s =~ /\G([^\x0A]+)/gc) {      if ($$s =~ /\G([^\x0D\x0A]+)/gc) {
701        print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1,        print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1,
702            "</li>\n";            "</li>\n";
703      }      }
# Line 684  sub print_source_string_section ($$$) { Line 705  sub print_source_string_section ($$$) {
705      print STDOUT q[<li id="$input->{id_prefix}line-1"></li>];      print STDOUT q[<li id="$input->{id_prefix}line-1"></li>];
706    }    }
707    print STDOUT "</ol></div>    print STDOUT "</ol></div>
708  <script> addSourceToParseErrorList ('$input->{id_prefix}'); </script>";  <script>
709      addSourceToParseErrorList ('$input->{id_prefix}', 'parse-errors-list');
710    </script>";
711  } # print_input_string_section  } # print_input_string_section
712    
713  sub print_document_tree ($$) {  sub print_document_tree ($$) {
# Line 853  sub print_structure_error_dom_section ($ Line 876  sub print_structure_error_dom_section ($
876    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">
877  <h2>Document Errors</h2>  <h2>Document Errors</h2>
878    
879  <dl>];  <dl id=document-errors-list>];
880    push @nav, [qq[#$input->{id_prefix}document-errors] => 'Document Error']    push @nav, [qq[#$input->{id_prefix}document-errors] => 'Document Error']
881        unless $input->{nested};        unless $input->{nested};
882    
# Line 881  sub print_structure_error_dom_section ($ Line 904  sub print_structure_error_dom_section ($
904    }    }
905    $time{check} = time - $time1;    $time{check} = time - $time1;
906    
907    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl>
908    <script>
909      addSourceToParseErrorList ('$input->{id_prefix}', 'document-errors-list');
910    </script></div>];
911    
912    return $elements;    return $elements;
913  } # print_structure_error_dom_section  } # print_structure_error_dom_section
# Line 930  sub print_table_section ($$) { Line 956  sub print_table_section ($$) {
956    require JSON;    require JSON;
957        
958    my $i = 0;    my $i = 0;
959    for my $table_el (@$tables) {    for my $table (@$tables) {
960      $i++;      $i++;
961      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>] .
962          get_node_link ($input, $table_el) . q[</h3>];          get_node_link ($input, $table->{element}) . q[</h3>];
963    
964      ## TODO: Make |ContentChecker| return |form_table| result      delete $table->{element};
965      ## so that this script don't have to run the algorithm twice.  
966      my $table = Whatpm::HTMLTable->form_table ($table_el);      for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption},
967                 @{$table->{row}}) {
     for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) {  
968        next unless $_;        next unless $_;
969        delete $_->{element};        delete $_->{element};
970      }      }
# Line 992  sub print_listing_section ($$$) { Line 1017  sub print_listing_section ($$$) {
1017    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl></div>];
1018  } # print_listing_section  } # print_listing_section
1019    
1020    sub print_uri_section ($$$) {
1021      my ($input, $uris) = @_;
1022    
1023      ## NOTE: URIs contained in the DOM (i.e. in HTML or XML documents),
1024      ## except for those in RDF triples.
1025      ## TODO: URIs in CSS
1026      
1027      push @nav, ['#' . $input->{id_prefix} . 'uris' => 'URIs']
1028          unless $input->{nested};
1029      print STDOUT qq[
1030    <div id="$input->{id_prefix}uris" class="section">
1031    <h2>URIs</h2>
1032    
1033    <dl>];
1034      for my $uri (sort {$a cmp $b} keys %$uris) {
1035        my $euri = htescape ($uri);
1036        print STDOUT qq[<dt><code class=uri>&lt;<a href="$euri">$euri</a>></code>];
1037        my $eccuri = htescape (get_cc_uri ($uri));
1038        print STDOUT qq[<dd><a href="$eccuri">Check conformance of this document</a>];
1039        print STDOUT qq[<dd>Found at: <ul>];
1040        for my $entry (@{$uris->{$uri}}) {
1041          print STDOUT qq[<li>], get_node_link ($input, $entry->{node});
1042          if (keys %{$entry->{type} or {}}) {
1043            print STDOUT ' (';
1044            print STDOUT join ', ', map {
1045              {
1046                hyperlink => 'Hyperlink',
1047                resource => 'Link to an external resource',
1048                namespace => 'Namespace URI',
1049                cite => 'Citation or link to a long description',
1050                embedded => 'Link to an embedded content',
1051                base => 'Base URI',
1052                action => 'Submission URI',
1053              }->{$_}
1054                or
1055              htescape ($_)
1056            } keys %{$entry->{type}};
1057            print STDOUT ')';
1058          }
1059        }
1060        print STDOUT qq[</ul>];
1061      }
1062      print STDOUT qq[</dl></div>];
1063    } # print_uri_section
1064    
1065    sub print_rdf_section ($$$) {
1066      my ($input, $rdfs) = @_;
1067      
1068      push @nav, ['#' . $input->{id_prefix} . 'rdf' => 'RDF']
1069          unless $input->{nested};
1070      print STDOUT qq[
1071    <div id="$input->{id_prefix}rdf" class="section">
1072    <h2>RDF Triples</h2>
1073    
1074    <dl>];
1075      my $i = 0;
1076      for my $rdf (@$rdfs) {
1077        print STDOUT qq[<dt id="$input->{id_prefix}rdf-@{[$i++]}">];
1078        print STDOUT get_node_link ($input, $rdf->[0]);
1079        print STDOUT qq[<dd><dl>];
1080        for my $triple (@{$rdf->[1]}) {
1081          print STDOUT '<dt>' . get_node_link ($input, $triple->[0]) . '<dd>';
1082          print STDOUT get_rdf_resource_html ($triple->[1]);
1083          print STDOUT ' ';
1084          print STDOUT get_rdf_resource_html ($triple->[2]);
1085          print STDOUT ' ';
1086          print STDOUT get_rdf_resource_html ($triple->[3]);
1087        }
1088        print STDOUT qq[</dl>];
1089      }
1090      print STDOUT qq[</dl></div>];
1091    } # print_rdf_section
1092    
1093    sub get_rdf_resource_html ($) {
1094      my $resource = shift;
1095      if (defined $resource->{uri}) {
1096        my $euri = htescape ($resource->{uri});
1097        return '<code class=uri>&lt;<a href="' . $euri . '">' . $euri .
1098            '</a>></code>';
1099      } elsif (defined $resource->{bnodeid}) {
1100        return htescape ('_:' . $resource->{bnodeid});
1101      } elsif ($resource->{nodes}) {
1102        return '(rdf:XMLLiteral)';
1103      } elsif (defined $resource->{value}) {
1104        my $elang = htescape (defined $resource->{language}
1105                                  ? $resource->{language} : '');
1106        my $r = qq[<q lang="$elang">] . htescape ($resource->{value}) . '</q>';
1107        if (defined $resource->{datatype}) {
1108          my $euri = htescape ($resource->{datatype});
1109          $r .= '^^<code class=uri>&lt;<a href="' . $euri . '">' . $euri .
1110              '</a>></code>';
1111        } elsif (length $resource->{language}) {
1112          $r .= '@' . htescape ($resource->{language});
1113        }
1114        return $r;
1115      } else {
1116        return '??';
1117      }
1118    } # get_rdf_resource_html
1119    
1120  sub print_result_section ($) {  sub print_result_section ($) {
1121    my $result = shift;    my $result = shift;
1122    
# Line 1121  sub get_error_label ($$) { Line 1246  sub get_error_label ($$) {
1246    
1247    my $r = '';    my $r = '';
1248    
1249    if (defined $err->{token} and defined $err->{token}->{line}) {    my $line;
1250      if ($err->{token}->{column} > 0) {    my $column;
1251        $r = qq[<a href="#$input->{id_prefix}line-$err->{token}->{line}">Line $err->{token}->{line}</a> column $err->{token}->{column}];      
1252      if (defined $err->{node}) {
1253        $line = $err->{node}->get_user_data ('manakai_source_line');
1254        if (defined $line) {
1255          $column = $err->{node}->get_user_data ('manakai_source_column');
1256      } else {      } else {
1257        $err->{token}->{line} = $err->{token}->{line} - 1 || 1;        if ($err->{node}->node_type == $err->{node}->ATTRIBUTE_NODE) {
1258        $r = qq[<a href="#$input->{id_prefix}line-$err->{token}->{line}">Line $err->{token}->{line}</a>];          my $owner = $err->{node}->owner_element;
1259            $line = $owner->get_user_data ('manakai_source_line');
1260            $column = $owner->get_user_data ('manakai_source_column');
1261          } else {
1262            my $parent = $err->{node}->parent_node;
1263            if ($parent) {
1264              $line = $parent->get_user_data ('manakai_source_line');
1265              $column = $parent->get_user_data ('manakai_source_column');
1266            }
1267          }
1268      }      }
1269    } elsif (defined $err->{line}) {    }
1270      if ($err->{column} > 0) {    unless (defined $line) {
1271        $r = qq[<a href="#$input->{id_prefix}line-$err->{line}">Line $err->{line}</a> column $err->{column}];      if (defined $err->{token} and defined $err->{token}->{line}) {
1272          $line = $err->{token}->{line};
1273          $column = $err->{token}->{column};
1274        } elsif (defined $err->{line}) {
1275          $line = $err->{line};
1276          $column = $err->{column};
1277        }
1278      }
1279    
1280      if (defined $line) {
1281        if (defined $column and $column > 0) {
1282          $r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a> column $column];
1283      } else {      } else {
1284        $err->{line} = $err->{line} - 1 || 1;        $line = $line - 1 || 1;
1285        $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>];
1286      }      }
1287    }    }
1288    
1289    if (defined $err->{node}) {    if (defined $err->{node}) {
1290      $r .= ' ' if length $r;      $r .= ' ' if length $r;
1291      $r = get_node_link ($input, $err->{node});      $r .= get_node_link ($input, $err->{node});
1292    }    }
1293    
1294    if (defined $err->{index}) {    if (defined $err->{index}) {
# Line 1193  sub get_node_path ($) { Line 1342  sub get_node_path ($) {
1342    while (defined $node) {    while (defined $node) {
1343      my $rs;      my $rs;
1344      if ($node->node_type == 1) {      if ($node->node_type == 1) {
1345        $rs = $node->manakai_local_name;        $rs = $node->node_name;
1346        $node = $node->parent_node;        $node = $node->parent_node;
1347      } elsif ($node->node_type == 2) {      } elsif ($node->node_type == 2) {
1348        $rs = '@' . $node->manakai_local_name;        $rs = '@' . $node->node_name;
1349        $node = $node->owner_element;        $node = $node->owner_element;
1350      } elsif ($node->node_type == 3) {      } elsif ($node->node_type == 3) {
1351        $rs = '"' . $node->data . '"';        $rs = '"' . $node->data . '"';
# Line 1274  sub get_text ($) { Line 1423  sub get_text ($) {
1423    
1424  }  }
1425    
1426    sub encode_uri_component ($) {
1427      require Encode;
1428      my $s = Encode::encode ('utf8', shift);
1429      $s =~ s/([^0-9A-Za-z_.~-])/sprintf '%%%02X', ord $1/ge;
1430      return $s;
1431    } # encode_uri_component
1432    
1433    sub get_cc_uri ($) {
1434      return './?uri=' . encode_uri_component ($_[0]);
1435    } # get_cc_uri
1436    
1437  sub get_input_document ($$) {  sub get_input_document ($$) {
1438    my ($http, $dom) = @_;    my ($http, $dom) = @_;
1439    

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.50

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24