/[suikacvs]/test/html-whatpm/parser-manakai.cgi
Suika

Diff of /test/html-whatpm/parser-manakai.cgi

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

revision 1.1 by wakaba, Thu Jun 21 14:54:14 2007 UTC revision 1.6 by wakaba, Sat Aug 11 13:54:55 2007 UTC
# Line 2  Line 2 
2  use strict;  use strict;
3    
4  use lib qw[/home/httpd/html/www/markup/html/whatpm  use lib qw[/home/httpd/html/www/markup/html/whatpm
5             /home/wakaba/work/manakai/lib             /home/wakaba/work/manakai2/lib];
            /home/wakaba/public_html/-temp/wiki/lib];  
6  use CGI::Carp qw[fatalsToBrowser];  use CGI::Carp qw[fatalsToBrowser];
7  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
8    
9  use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module  use Message::CGI::HTTP;
10    my $http = Message::CGI::HTTP->new;
 my $http = SuikaWiki::Input::HTTP->new;  
11    
12  ## TODO: _charset_  ## TODO: _charset_
13    
14  my $mode = $http->meta_variable ('PATH_INFO');  my @mode = split m#/#, scalar $http->get_meta_variable ('PATH_INFO'), -1;
15    shift @mode if @mode and $mode[0] == '';
16  ## TODO: decode unreserved characters  ## TODO: decode unreserved characters
17    
18    my $s = $http->parameter ('s');    my $s = $http->get_parameter ('s');
19    if (length $s > 1000_000) {    if (length $s > 1000_000) {
20      print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long";      print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long";
21      exit;      exit;
# Line 27  my $mode = $http->meta_variable ('PATH_I Line 26  my $mode = $http->meta_variable ('PATH_I
26    my $time2;    my $time2;
27    
28    require Message::DOM::DOMImplementation;    require Message::DOM::DOMImplementation;
29    my $dom = Message::DOM::DOMImplementation->____new;    my $dom = Message::DOM::DOMImplementation->new;
30    $| = 1;  #  $| = 1;
31    my $doc;    my $doc;
32      my $el;
33    
34  if ($mode eq '/html/html' or $mode eq '/html/test') {  if (@mode == 3 and $mode[0] eq 'html' and
35        ($mode[2] eq 'html' or $mode[2] eq 'test')) {
36    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
37    
38    require Encode;    require Encode;
# Line 50  if ($mode eq '/html/html' or $mode eq '/ Line 51  if ($mode eq '/html/html' or $mode eq '/
51      print STDOUT "$opt{line},$opt{column},$opt{type}\n";      print STDOUT "$opt{line},$opt{column},$opt{type}\n";
52    };    };
53    
54      $doc = $dom->create_document;
55      $doc->manakai_is_html (1);
56    $time1 = time;    $time1 = time;
57    $doc = Whatpm::HTML->parse_string ($s => $dom->create_document, $onerror);    if (length $mode[1]) {
58        $el = $doc->create_element_ns
59            ('http://www.w3.org/1999/xhtml', [undef, $mode[1]]);
60        Whatpm::HTML->set_inner_html ($el, $s, $onerror);
61      } else {
62        Whatpm::HTML->parse_string ($s => $doc, $onerror);
63      }
64    $time2 = time;    $time2 = time;
65    $time{parse} = $time2 - $time1;    $time{parse} = $time2 - $time1;
66    
67    print "#document\n";    print "#document\n";
68    
69    my $out;    my $out;
70    $time1 = time;    if ($mode[2] eq 'html') {
71    if ($mode eq '/html/html') {      $time1 = time;
72      $out = Whatpm::HTML->get_inner_html ($doc);      $out = \( ($el or $doc)->inner_html );
73        $time2 = time;
74        $time{serialize_html} = $time2 - $time1;
75    } else { # test    } else { # test
76      $out = test_serialize ($doc);      $time1 = time;
77        $out = test_serialize ($el || $doc);
78        $time2 = time;
79        $time{serialize_test} = $time2 - $time1;
80    }    }
   $time2 = time;  
   $time{serialize} = $time2 - $time1;  
81    print STDOUT Encode::encode ('utf-8', $$out);    print STDOUT Encode::encode ('utf-8', $$out);
82    print STDOUT "\n";    print STDOUT "\n";
83  } elsif ($mode eq '/xhtml/html' or $mode eq '/xhtml/test') {  } elsif (@mode == 3 and $mode[0] eq 'xhtml' and
84             ($mode[2] eq 'html' or $mode[2] eq 'test')) {
85    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
86    
87    require Message::DOM::XMLParserTemp;    require Message::DOM::XMLParserTemp;
# Line 77  if ($mode eq '/html/html' or $mode eq '/ Line 90  if ($mode eq '/html/html' or $mode eq '/
90    my $onerror = sub {    my $onerror = sub {
91      my $err = shift;      my $err = shift;
92      print STDOUT $err->location->line_number, ",";      print STDOUT $err->location->line_number, ",";
93      print STDOUT $err->location->column_number, " ";      print STDOUT $err->location->column_number, ",";
94      print STDOUT $err->text, "\n";      print STDOUT $err->text, "\n";
95      return 1;      return 1;
96    };    };
# Line 92  if ($mode eq '/html/html' or $mode eq '/ Line 105  if ($mode eq '/html/html' or $mode eq '/
105    print "#document\n";    print "#document\n";
106    
107    my $out;    my $out;
108    if ($mode eq '/xhtml/html') {    if ($mode[2] eq 'html') {
109      ## TODO: Use XHTML serializer      $time1 = time;
110      #$out = Whatpm::HTML->get_inner_html ($doc);      $out = \( $doc->inner_html ); ## TODO: $el case
111        $time2 = time;
112        $time{serialize_xml} = $time2 - $time1;
113      } else { # test
114        $time1 = time;
115        $out = test_serialize ($doc);
116        $time2 = time;
117        $time{serialize_test} = $time2 - $time1;
118      }
119      print STDOUT Encode::encode ('utf-8', $$out);
120      print STDOUT "\n";
121    } elsif (@mode == 3 and $mode[0] eq 'h2h' and $mode[1] eq '' and
122             ($mode[2] eq 'html' or $mode[2] eq 'test')) {
123      print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
124    
125      require Encode;
126      $time1 = time;
127      $s = Encode::decode ('utf-8', $s);
128      $time2 = time;
129      $time{decode} = $time2 - $time1;
130    
131      require Whatpm::H2H;
132      $doc = $dom->create_document;
133      Whatpm::H2H->parse_string ($s => $doc);
134    
135      print "#document\n";
136    
137      my $out;
138      if ($mode[2] eq 'html') {
139        $time1 = time;
140        $out = \( $doc->inner_html );
141        $time2 = time;
142        $time{serialize_xml} = $time2 - $time1;
143    } else { # test    } else { # test
144      $time1 = time;      $time1 = time;
145      $out = test_serialize ($doc);      $out = test_serialize ($doc);
# Line 108  if ($mode eq '/html/html' or $mode eq '/ Line 153  if ($mode eq '/html/html' or $mode eq '/
153    exit;    exit;
154  }  }
155    
156    if ($http->parameter ('dom5')) {    if ($http->get_parameter ('dom5')) {
157      require Whatpm::ContentChecker;      require Whatpm::ContentChecker;
158      print STDOUT "#domerrors\n";      my $onerror = sub {
     $time1 = time;  
     Whatpm::ContentChecker->check_document ($doc, sub {  
159        my %opt = @_;        my %opt = @_;
160        print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n";        print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n";
161      });      };
162        print STDOUT "#domerrors\n";
163        $time1 = time;
164        if ($el) {
165          Whatpm::ContentChecker->check_element ($el, $onerror);
166        } else {
167          Whatpm::ContentChecker->check_document ($doc, $onerror);
168        }
169      $time2 = time;      $time2 = time;
170      $time{check} = $time2 - $time1;      $time{check} = $time2 - $time1;
171    }    }
# Line 128  if ($mode eq '/html/html' or $mode eq '/ Line 178  if ($mode eq '/html/html' or $mode eq '/
178        decode => 'bytes->chars',        decode => 'bytes->chars',
179        parse => 'html5(chars)->dom5',        parse => 'html5(chars)->dom5',
180        parse_xml => 'xml1(chars)->dom5',        parse_xml => 'xml1(chars)->dom5',
181        serialize_html => 'dom5->html5',        serialize_html => 'dom5->html5(char)',
182        serialize_xml => 'dom5->xml',        serialize_xml => 'dom5->xml1(char)',
183        serialize_test => 'dom5->test',        serialize_test => 'dom5->test(char)',
184        check => 'dom5 check',        check => 'dom5 check',
185      }->{$_};      }->{$_};
186      print STDOUT "\t", $time{$_}, "s\n";      print STDOUT "\t", $time{$_}, "s\n";

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24