/[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.7 by wakaba, Sat Apr 12 15:57:56 2008 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    
35  if ($mode eq '/html/html' or $mode eq '/html/test') {  if (@mode == 3 and $mode[0] eq 'html' and
36        ($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) {
37    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
38    
39    require Encode;    require Encode;
# Line 50  if ($mode eq '/html/html' or $mode eq '/ Line 52  if ($mode eq '/html/html' or $mode eq '/
52      print STDOUT "$opt{line},$opt{column},$opt{type}\n";      print STDOUT "$opt{line},$opt{column},$opt{type}\n";
53    };    };
54    
55      $doc = $dom->create_document;
56      $doc->manakai_is_html (1);
57    $time1 = time;    $time1 = time;
58    $doc = Whatpm::HTML->parse_string ($s => $dom->create_document, $onerror);    if (length $mode[1]) {
59        $el = $doc->create_element_ns
60            ('http://www.w3.org/1999/xhtml', [undef, $mode[1]]);
61        Whatpm::HTML->set_inner_html ($el, $s, $onerror);
62      } else {
63        Whatpm::HTML->parse_string ($s => $doc, $onerror);
64      }
65    $time2 = time;    $time2 = time;
66    $time{parse} = $time2 - $time1;    $time{parse} = $time2 - $time1;
67    
68    print "#document\n";    print "#document\n";
69    
70    my $out;    my $out;
71    $time1 = time;    if ($mode[2] eq 'html') {
72    if ($mode eq '/html/html') {      $time1 = time;
73      $out = Whatpm::HTML->get_inner_html ($doc);      $out = \( ($el or $doc)->inner_html );
74        $time2 = time;
75        $time{serialize_html} = $time2 - $time1;
76      } elsif ($mode[2] eq 'xml') {
77        $doc->manakai_is_html (0);
78        $time1 = time;
79        $out = \( ($el or $doc)->inner_html );
80        $time2 = time;
81        $time{serialize_xml} = $time2 - $time1;
82        $doc->manakai_is_html (1);
83    } else { # test    } else { # test
84      $out = test_serialize ($doc);      $time1 = time;
85        $out = test_serialize ($el || $doc);
86        $time2 = time;
87        $time{serialize_test} = $time2 - $time1;
88    }    }
   $time2 = time;  
   $time{serialize} = $time2 - $time1;  
89    print STDOUT Encode::encode ('utf-8', $$out);    print STDOUT Encode::encode ('utf-8', $$out);
90    print STDOUT "\n";    print STDOUT "\n";
91  } elsif ($mode eq '/xhtml/html' or $mode eq '/xhtml/test') {  } elsif (@mode == 3 and $mode[0] eq 'xhtml' and
92             ($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) {
93    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";    print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
94    
95    require Message::DOM::XMLParserTemp;    require Message::DOM::XMLParserTemp;
# Line 77  if ($mode eq '/html/html' or $mode eq '/ Line 98  if ($mode eq '/html/html' or $mode eq '/
98    my $onerror = sub {    my $onerror = sub {
99      my $err = shift;      my $err = shift;
100      print STDOUT $err->location->line_number, ",";      print STDOUT $err->location->line_number, ",";
101      print STDOUT $err->location->column_number, " ";      print STDOUT $err->location->column_number, ",";
102      print STDOUT $err->text, "\n";      print STDOUT $err->text, "\n";
103      return 1;      return 1;
104    };    };
# Line 92  if ($mode eq '/html/html' or $mode eq '/ Line 113  if ($mode eq '/html/html' or $mode eq '/
113    print "#document\n";    print "#document\n";
114    
115    my $out;    my $out;
116    if ($mode eq '/xhtml/html') {    if ($mode[2] eq 'html') {
117      ## TODO: Use XHTML serializer      $doc->manakai_is_html (0);
118      #$out = Whatpm::HTML->get_inner_html ($doc);      $time1 = time;
119        $out = \( $doc->inner_html ); ## TODO: $el case
120        $time2 = time;
121        $time{serialize_html} = $time2 - $time1;
122        $doc->manakai_is_html (1);
123      } elsif ($mode[2] eq 'xml') {
124        $time1 = time;
125        $out = \( $doc->inner_html ); ## TODO: $el case
126        $time2 = time;
127        $time{serialize_xml} = $time2 - $time1;
128      } else { # test
129        $time1 = time;
130        $out = test_serialize ($doc);
131        $time2 = time;
132        $time{serialize_test} = $time2 - $time1;
133      }
134      print STDOUT Encode::encode ('utf-8', $$out);
135      print STDOUT "\n";
136    } elsif (@mode == 3 and $mode[0] eq 'h2h' and $mode[1] eq '' and
137             ($mode[2] eq 'html' or $mode[2] eq 'test' or $mode[2] eq 'xml')) {
138      print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
139    
140      require Encode;
141      $time1 = time;
142      $s = Encode::decode ('utf-8', $s);
143      $time2 = time;
144      $time{decode} = $time2 - $time1;
145    
146      require Whatpm::H2H;
147      $doc = $dom->create_document;
148      Whatpm::H2H->parse_string ($s => $doc);
149    
150      print "#document\n";
151    
152      my $out;
153      if ($mode[2] eq 'html') {
154        $doc->manakai_is_html (0);
155        $time1 = time;
156        $out = \( $doc->inner_html );
157        $time2 = time;
158        $time{serialize_html} = $time2 - $time1;
159        $doc->manakai_is_html (1);
160      } elsif ($mode[2] eq 'xml') {
161        $time1 = time;
162        $out = \( $doc->inner_html );
163        $time2 = time;
164        $time{serialize_xml} = $time2 - $time1;
165    } else { # test    } else { # test
166      $time1 = time;      $time1 = time;
167      $out = test_serialize ($doc);      $out = test_serialize ($doc);
# Line 108  if ($mode eq '/html/html' or $mode eq '/ Line 175  if ($mode eq '/html/html' or $mode eq '/
175    exit;    exit;
176  }  }
177    
178    if ($http->parameter ('dom5')) {    if ($http->get_parameter ('dom5')) {
179      require Whatpm::ContentChecker;      require Whatpm::ContentChecker;
180      print STDOUT "#domerrors\n";      my $onerror = sub {
     $time1 = time;  
     Whatpm::ContentChecker->check_document ($doc, sub {  
181        my %opt = @_;        my %opt = @_;
182        print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n";        print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n";
183      });      };
184        print STDOUT "#domerrors\n";
185        $time1 = time;
186        if ($el) {
187          Whatpm::ContentChecker->check_element ($el, $onerror);
188        } else {
189          Whatpm::ContentChecker->check_document ($doc, $onerror);
190        }
191      $time2 = time;      $time2 = time;
192      $time{check} = $time2 - $time1;      $time{check} = $time2 - $time1;
193    }    }
# Line 128  if ($mode eq '/html/html' or $mode eq '/ Line 200  if ($mode eq '/html/html' or $mode eq '/
200        decode => 'bytes->chars',        decode => 'bytes->chars',
201        parse => 'html5(chars)->dom5',        parse => 'html5(chars)->dom5',
202        parse_xml => 'xml1(chars)->dom5',        parse_xml => 'xml1(chars)->dom5',
203        serialize_html => 'dom5->html5',        serialize_html => 'dom5->html5(char)',
204        serialize_xml => 'dom5->xml',        serialize_xml => 'dom5->xml1(char)',
205        serialize_test => 'dom5->test',        serialize_test => 'dom5->test(char)',
206        check => 'dom5 check',        check => 'dom5 check',
207      }->{$_};      }->{$_};
208      print STDOUT "\t", $time{$_}, "s\n";      print STDOUT "\t", $time{$_}, "s\n";

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24