/[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.3 by wakaba, Wed Jun 27 11:08:03 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 = split m#/#, scalar $http->meta_variable ('PATH_INFO'), -1;  my @mode = split m#/#, scalar $http->get_meta_variable ('PATH_INFO'), -1;
15  shift @mode if @mode and $mode[0] == '';  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 28  shift @mode if @mode and $mode[0] == ''; Line 26  shift @mode if @mode and $mode[0] == '';
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;    my $el;
# Line 54  if (@mode == 3 and $mode[0] eq 'html' an Line 52  if (@mode == 3 and $mode[0] eq 'html' an
52    };    };
53    
54    $doc = $dom->create_document;    $doc = $dom->create_document;
55      $doc->manakai_is_html (1);
56    $time1 = time;    $time1 = time;
57    if (length $mode[1]) {    if (length $mode[1]) {
58      $el = $doc->create_element_ns      $el = $doc->create_element_ns
# Line 70  if (@mode == 3 and $mode[0] eq 'html' an Line 69  if (@mode == 3 and $mode[0] eq 'html' an
69    my $out;    my $out;
70    if ($mode[2] eq 'html') {    if ($mode[2] eq 'html') {
71      $time1 = time;      $time1 = time;
72      $out = Whatpm::HTML->get_inner_html ($el || $doc);      $out = \( ($el or $doc)->inner_html );
73      $time2 = time;      $time2 = time;
74      $time{serialize_html} = $time2 - $time1;      $time{serialize_html} = $time2 - $time1;
75    } else { # test    } else { # test
# Line 107  if (@mode == 3 and $mode[0] eq 'html' an Line 106  if (@mode == 3 and $mode[0] eq 'html' an
106    
107    my $out;    my $out;
108    if ($mode[2] eq '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 122  if (@mode == 3 and $mode[0] eq 'html' an Line 153  if (@mode == 3 and $mode[0] eq 'html' an
153    exit;    exit;
154  }  }
155    
156    if ($http->parameter ('dom5')) {    if ($http->get_parameter ('dom5')) {
157      require Whatpm::ContentChecker;      require Whatpm::ContentChecker;
158      my $onerror = sub {      my $onerror = sub {
159        my %opt = @_;        my %opt = @_;

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24