/[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.24 by wakaba, Sun Nov 11 06:57:16 2007 UTC revision 1.26 by wakaba, Sun Nov 18 11:05:12 2007 UTC
# Line 52  sub htescape ($) { Line 52  sub htescape ($) {
52    
53    $| = 0;    $| = 0;
54    my $input = get_input_document ($http, $dom);    my $input = get_input_document ($http, $dom);
   my $inner_html_element = $http->get_parameter ('e');  
55    my $char_length = 0;    my $char_length = 0;
56    my %time;    my %time;
57    
# Line 62  sub htescape ($) { Line 61  sub htescape ($) {
61  <dt>Request URI</dt>  <dt>Request URI</dt>
62      <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>&gt;</code></dd>      <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>&gt;</code></dd>
63  <dt>Document URI</dt>  <dt>Document URI</dt>
64      <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{uri}]}">@{[htescape $input->{uri}]}</a>&gt;</code></dd>      <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{uri}]}" id=anchor-document-uri>@{[htescape $input->{uri}]}</a>&gt;</code>
65        <script>
66          document.title = '<'
67              + document.getElementById ('anchor-document-uri').href + '> \\u2014 '
68              + document.title;
69        </script></dd>
70  ]; # no </dl> yet  ]; # no </dl> yet
71    push @nav, ['#document-info' => 'Information'];    push @nav, ['#document-info' => 'Information'];
72    
# Line 74  if (defined $input->{s}) { Line 78  if (defined $input->{s}) {
78      <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>&gt;</code></dd>      <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>&gt;</code></dd>
79  <dt>Internet Media Type</dt>  <dt>Internet Media Type</dt>
80      <dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code>      <dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code>
81      @{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : '']}</dd>      @{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : defined $input->{official_type} ? $input->{media_type} eq $input->{official_type} ? '' : '<em>(sniffed; official type is: <code class=MIME lang=en>'.htescape ($input->{official_type}).'</code>)' : '<em>(sniffed)</em>']}</dd>
82  <dt>Character Encoding</dt>  <dt>Character Encoding</dt>
83      <dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']}      <dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']}
84      @{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd>      @{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd>
# Line 93  if (defined $input->{s}) { Line 97  if (defined $input->{s}) {
97    
98    if ($input->{media_type} eq 'text/html') {    if ($input->{media_type} eq 'text/html') {
99      ($doc, $el) = print_syntax_error_html_section ($input, $result);      ($doc, $el) = print_syntax_error_html_section ($input, $result);
100      print_source_string_section (\($input->{s}), $input->{charset});      print_source_string_section
101            (\($input->{s}), $input->{charset} || $doc->input_encoding);
102    } elsif ({    } elsif ({
103              'text/xml' => 1,              'text/xml' => 1,
104              'application/atom+xml' => 1,              'application/atom+xml' => 1,
# Line 247  sub print_syntax_error_html_section ($$) Line 252  sub print_syntax_error_html_section ($$)
252    
253    my $doc = $dom->create_document;    my $doc = $dom->create_document;
254    my $el;    my $el;
255      my $inner_html_element = $http->get_parameter ('e');
256    if (defined $inner_html_element and length $inner_html_element) {    if (defined $inner_html_element and length $inner_html_element) {
257      $input->{charset} ||= 'ISO-8859-1'; ## TODO: for now.      $input->{charset} ||= 'windows-1252'; ## TODO: for now.
258      my $time1 = time;      my $time1 = time;
259      my $t = Encode::decode ($input->{charset}, $input->{s});      my $t = Encode::decode ($input->{charset}, $input->{s});
260      $time{decode} = time - $time1;      $time{decode} = time - $time1;
# Line 264  sub print_syntax_error_html_section ($$) Line 270  sub print_syntax_error_html_section ($$)
270          ($input->{charset}, $input->{s} => $doc, $onerror);          ($input->{charset}, $input->{s} => $doc, $onerror);
271      $time{parse_html} = time - $time1;      $time{parse_html} = time - $time1;
272    }    }
273      $doc->manakai_charset ($input->{official_charset})
274          if defined $input->{official_charset};
275        
276    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl></div>];
277    
# Line 304  sub print_syntax_error_xml_section ($$) Line 312  sub print_syntax_error_xml_section ($$)
312    my $doc = Message::DOM::XMLParserTemp->parse_byte_stream    my $doc = Message::DOM::XMLParserTemp->parse_byte_stream
313        ($fh => $dom, $onerror, charset => $input->{charset});        ($fh => $dom, $onerror, charset => $input->{charset});
314    $time{parse_xml} = time - $time1;    $time{parse_xml} = time - $time1;
315      $doc->manakai_charset ($input->{official_charset})
316          if defined $input->{official_charset};
317    
318    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl></div>];
319    
# Line 889  sub get_node_link ($) { Line 899  sub get_node_link ($) {
899    
900  sub load_text_catalog ($) {  sub load_text_catalog ($) {
901    my $lang = shift; # MUST be a canonical lang name    my $lang = shift; # MUST be a canonical lang name
902    open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!";    open my $file, '<:utf8', "cc-msg.$lang.txt"
903          or die "$0: cc-msg.$lang.txt: $!";
904    while (<$file>) {    while (<$file>) {
905      if (s/^([^;]+);([^;]*);//) {      if (s/^([^;]+);([^;]*);//) {
906        my ($type, $cls, $msg) = ($1, $2, $_);        my ($type, $cls, $msg) = ($1, $2, $_);
# Line 997  EOH Line 1008  EOH
1008    
1009        ## TODO: More strict parsing...        ## TODO: More strict parsing...
1010        my $ct = $res->header ('Content-Type');        my $ct = $res->header ('Content-Type');
       if (defined $ct and $ct =~ m#^([0-9A-Za-z._+-]+/[0-9A-Za-z._+-]+)#) {  
         $r->{media_type} = lc $1;  
       }  
1011        if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) {        if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) {
1012          $r->{charset} = lc $1;          $r->{charset} = lc $1;
1013          $r->{charset} =~ tr/\\//d;          $r->{charset} =~ tr/\\//d;
1014            $r->{official_charset} = $r->{charset};
1015        }        }
1016    
1017        my $input_charset = $http->get_parameter ('charset');        my $input_charset = $http->get_parameter ('charset');
# Line 1010  EOH Line 1019  EOH
1019          $r->{charset_overridden}          $r->{charset_overridden}
1020              = (not defined $r->{charset} or $r->{charset} ne $input_charset);              = (not defined $r->{charset} or $r->{charset} ne $input_charset);
1021          $r->{charset} = $input_charset;          $r->{charset} = $input_charset;
1022        }        }
1023    
1024          ## TODO: Support for HTTP Content-Encoding
1025    
1026        $r->{s} = ''.$res->content;        $r->{s} = ''.$res->content;
1027    
1028          require Whatpm::ContentType;
1029          ($r->{official_type}, $r->{media_type})
1030              = Whatpm::ContentType->get_sniffed_type
1031                  (get_file_head => sub {
1032                     return substr $r->{s}, 0, shift;
1033                   },
1034                   http_content_type_byte => $ct,
1035                   has_http_content_encoding =>
1036                       defined $res->header ('Content-Encoding'),
1037                   supported_image_types => {});
1038      } else {      } else {
1039        $r->{uri} = $res->request->uri;        $r->{uri} = $res->request->uri;
1040        $r->{request_uri} = $request_uri;        $r->{request_uri} = $request_uri;
# Line 1033  EOH Line 1055  EOH
1055      $r->{charset} = ''.$http->get_parameter ('_charset_');      $r->{charset} = ''.$http->get_parameter ('_charset_');
1056      $r->{charset} =~ s/\s+//g;      $r->{charset} =~ s/\s+//g;
1057      $r->{charset} = 'utf-8' if $r->{charset} eq '';      $r->{charset} = 'utf-8' if $r->{charset} eq '';
1058        $r->{official_charset} = $r->{charset};
1059      $r->{header_field} = [];      $r->{header_field} = [];
1060    
1061        require Whatpm::ContentType;
1062        ($r->{official_type}, $r->{media_type})
1063            = Whatpm::ContentType->get_sniffed_type
1064                (get_file_head => sub {
1065                   return substr $r->{s}, 0, shift;
1066                 },
1067                 http_content_type_byte => undef,
1068                 has_http_content_encoding => 0,
1069                 supported_image_types => {});
1070    }    }
1071    
1072    my $input_format = $http->get_parameter ('i');    my $input_format = $http->get_parameter ('i');
# Line 1050  EOH Line 1083  EOH
1083    if ($r->{media_type} eq 'text/xml') {    if ($r->{media_type} eq 'text/xml') {
1084      unless (defined $r->{charset}) {      unless (defined $r->{charset}) {
1085        $r->{charset} = 'us-ascii';        $r->{charset} = 'us-ascii';
1086          $r->{official_charset} = $r->{charset};
1087      } elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') {      } elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') {
1088        $r->{charset_overridden} = 0;        $r->{charset_overridden} = 0;
1089      }      }

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.26

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24