--- test/html-whatpm/parser-manakai.cgi 2007/06/21 14:54:14 1.1
+++ test/html-whatpm/parser-manakai.cgi 2008/07/18 14:44:17 1.8
@@ -2,21 +2,20 @@
use strict;
use lib qw[/home/httpd/html/www/markup/html/whatpm
- /home/wakaba/work/manakai/lib
- /home/wakaba/public_html/-temp/wiki/lib];
+ /home/wakaba/work/manakai2/lib];
use CGI::Carp qw[fatalsToBrowser];
use Time::HiRes qw/time/;
-use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module
-
-my $http = SuikaWiki::Input::HTTP->new;
+use Message::CGI::HTTP;
+my $http = Message::CGI::HTTP->new;
## TODO: _charset_
-my $mode = $http->meta_variable ('PATH_INFO');
+my @mode = split m#/#, scalar $http->get_meta_variable ('PATH_INFO'), -1;
+shift @mode if @mode and $mode[0] == '';
## TODO: decode unreserved characters
- my $s = $http->parameter ('s');
+ my $s = $http->get_parameter ('s');
if (length $s > 1000_000) {
print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long";
exit;
@@ -27,11 +26,14 @@
my $time2;
require Message::DOM::DOMImplementation;
- my $dom = Message::DOM::DOMImplementation->____new;
- $| = 1;
+ my $dom = Message::DOM::DOMImplementation->new;
+# $| = 1;
my $doc;
+ my $el;
+
-if ($mode eq '/html/html' or $mode eq '/html/test') {
+if (@mode == 3 and $mode[0] eq 'html' and
+ ($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) {
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
require Encode;
@@ -47,28 +49,47 @@
my $onerror = sub {
my (%opt) = @_;
- print STDOUT "$opt{line},$opt{column},$opt{type}\n";
+ print STDOUT "$opt{line},$opt{column},$opt{type};$opt{level};$opt{value}\n";
};
+ $doc = $dom->create_document;
+ $doc->manakai_is_html (1);
$time1 = time;
- $doc = Whatpm::HTML->parse_string ($s => $dom->create_document, $onerror);
+ if (length $mode[1]) {
+ $el = $doc->create_element_ns
+ ('http://www.w3.org/1999/xhtml', [undef, $mode[1]]);
+ Whatpm::HTML->set_inner_html ($el, $s, $onerror);
+ } else {
+ Whatpm::HTML->parse_string ($s => $doc, $onerror);
+ }
$time2 = time;
$time{parse} = $time2 - $time1;
print "#document\n";
my $out;
- $time1 = time;
- if ($mode eq '/html/html') {
- $out = Whatpm::HTML->get_inner_html ($doc);
+ if ($mode[2] eq 'html') {
+ $time1 = time;
+ $out = \( ($el or $doc)->inner_html );
+ $time2 = time;
+ $time{serialize_html} = $time2 - $time1;
+ } elsif ($mode[2] eq 'xml') {
+ $doc->manakai_is_html (0);
+ $time1 = time;
+ $out = \( ($el or $doc)->inner_html );
+ $time2 = time;
+ $time{serialize_xml} = $time2 - $time1;
+ $doc->manakai_is_html (1);
} else { # test
- $out = test_serialize ($doc);
+ $time1 = time;
+ $out = test_serialize ($el || $doc);
+ $time2 = time;
+ $time{serialize_test} = $time2 - $time1;
}
- $time2 = time;
- $time{serialize} = $time2 - $time1;
print STDOUT Encode::encode ('utf-8', $$out);
print STDOUT "\n";
-} elsif ($mode eq '/xhtml/html' or $mode eq '/xhtml/test') {
+} elsif (@mode == 3 and $mode[0] eq 'xhtml' and
+ ($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) {
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
require Message::DOM::XMLParserTemp;
@@ -77,7 +98,7 @@
my $onerror = sub {
my $err = shift;
print STDOUT $err->location->line_number, ",";
- print STDOUT $err->location->column_number, " ";
+ print STDOUT $err->location->column_number, ",";
print STDOUT $err->text, "\n";
return 1;
};
@@ -92,9 +113,55 @@
print "#document\n";
my $out;
- if ($mode eq '/xhtml/html') {
- ## TODO: Use XHTML serializer
- #$out = Whatpm::HTML->get_inner_html ($doc);
+ if ($mode[2] eq 'html') {
+ $doc->manakai_is_html (0);
+ $time1 = time;
+ $out = \( $doc->inner_html ); ## TODO: $el case
+ $time2 = time;
+ $time{serialize_html} = $time2 - $time1;
+ $doc->manakai_is_html (1);
+ } elsif ($mode[2] eq 'xml') {
+ $time1 = time;
+ $out = \( $doc->inner_html ); ## TODO: $el case
+ $time2 = time;
+ $time{serialize_xml} = $time2 - $time1;
+ } else { # test
+ $time1 = time;
+ $out = test_serialize ($doc);
+ $time2 = time;
+ $time{serialize_test} = $time2 - $time1;
+ }
+ print STDOUT Encode::encode ('utf-8', $$out);
+ print STDOUT "\n";
+} elsif (@mode == 3 and $mode[0] eq 'h2h' and $mode[1] eq '' and
+ ($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) {
+ print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
+
+ require Encode;
+ $time1 = time;
+ $s = Encode::decode ('utf-8', $s);
+ $time2 = time;
+ $time{decode} = $time2 - $time1;
+
+ require Whatpm::H2H;
+ $doc = $dom->create_document;
+ Whatpm::H2H->parse_string ($s => $doc);
+
+ print "#document\n";
+
+ my $out;
+ if ($mode[2] eq 'html') {
+ $doc->manakai_is_html (0);
+ $time1 = time;
+ $out = \( $doc->inner_html );
+ $time2 = time;
+ $time{serialize_html} = $time2 - $time1;
+ $doc->manakai_is_html (1);
+ } elsif ($mode[2] eq 'xml') {
+ $time1 = time;
+ $out = \( $doc->inner_html );
+ $time2 = time;
+ $time{serialize_xml} = $time2 - $time1;
} else { # test
$time1 = time;
$out = test_serialize ($doc);
@@ -108,14 +175,19 @@
exit;
}
- if ($http->parameter ('dom5')) {
+ if ($http->get_parameter ('dom5')) {
require Whatpm::ContentChecker;
- print STDOUT "#domerrors\n";
- $time1 = time;
- Whatpm::ContentChecker->check_document ($doc, sub {
+ my $onerror = sub {
my %opt = @_;
print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n";
- });
+ };
+ print STDOUT "#domerrors\n";
+ $time1 = time;
+ if ($el) {
+ Whatpm::ContentChecker->check_element ($el, $onerror);
+ } else {
+ Whatpm::ContentChecker->check_document ($doc, $onerror);
+ }
$time2 = time;
$time{check} = $time2 - $time1;
}
@@ -128,9 +200,9 @@
decode => 'bytes->chars',
parse => 'html5(chars)->dom5',
parse_xml => 'xml1(chars)->dom5',
- serialize_html => 'dom5->html5',
- serialize_xml => 'dom5->xml',
- serialize_test => 'dom5->test',
+ serialize_html => 'dom5->html5(char)',
+ serialize_xml => 'dom5->xml1(char)',
+ serialize_test => 'dom5->test(char)',
check => 'dom5 check',
}->{$_};
print STDOUT "\t", $time{$_}, "s\n";
@@ -217,4 +289,4 @@
=cut
-## $Date: 2007/06/21 14:54:14 $
+## $Date: 2008/07/18 14:44:17 $