--- test/html-webhacc/cc.cgi 2007/07/01 10:02:24 1.8 +++ test/html-webhacc/cc.cgi 2007/07/15 16:39:10 1.9 @@ -28,15 +28,11 @@ exit; } - my $input_format = $http->parameter ('i') || 'text/html'; - my $inner_html_element = $http->parameter ('e'); - my $input_uri = 'thismessage:/'; + require Message::DOM::DOMImplementation; + my $dom = Message::DOM::DOMImplementation->new; - my $s = $http->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; - } + my $input = get_input_document ($http, $dom); + my $inner_html_element = $http->parameter ('e'); load_text_catalog ('en'); ## TODO: conneg @@ -54,38 +50,40 @@
+
Request URI
+
<@{[htescape $input->{request_uri}]}>
Document URI
-
<@{[htescape $input_uri]}>
-
Internet Media Type
-
@{[htescape $input_format]}
+
<@{[htescape $input->{uri}]}>
]; # no
yet push @nav, ['#document-info' => 'Information']; - require Message::DOM::DOMImplementation; - my $dom = Message::DOM::DOMImplementation->____new; +if (defined $input->{s}) { + + print STDOUT qq[ +
Base URI
+
<@{[htescape $input->{base_uri}]}>
+
Internet Media Type
+
@{[htescape $input->{media_type}]} + @{[$input->{media_type_overridden} ? '(overridden)' : '']}
+
Character Encoding
+
@{[defined $input->{charset} ? ''.htescape ($input->{charset}).'' : '(none)']} + @{[$input->{charset_overridden} ? '(overridden)' : '']}
+ +
+]; + + print_http_header_section ($input); + my $doc; my $el; - if ($input_format eq 'text/html') { + if ($input->{media_type} eq 'text/html') { require Encode; require Whatpm::HTML; - $s = Encode::decode ('utf-8', $s); + my $t = Encode::decode ($input->{charset}, $input->{s}); print STDOUT qq[ -
Character Encoding
-
(none)
- - - -
-

Document Source

-]; - push @nav, ['#source-string' => 'Source']; - print_source_string (\$s); - print STDOUT qq[ -
-

Parse Errors

@@ -112,35 +110,25 @@ if (defined $inner_html_element and length $inner_html_element) { $el = $doc->create_element_ns ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); - Whatpm::HTML->set_inner_html ($el, $s, $onerror); + Whatpm::HTML->set_inner_html ($el, $t, $onerror); } else { - Whatpm::HTML->parse_string ($s => $doc, $onerror); + Whatpm::HTML->parse_string ($t => $doc, $onerror); } print STDOUT qq[
]; - } elsif ($input_format eq 'application/xhtml+xml') { - require Message::DOM::XMLParserTemp; - require Encode; - - my $t = Encode::decode ('utf-8', $s); - print STDOUT qq[ -
Character Encoding
-
(none)
- - + print_source_string_section (\($input->{s}), $input->{charset}); + } elsif ({ + 'text/xml' => 1, + 'application/xhtml+xml' => 1, + 'application/xml' => 1, + }->{$input->{media_type}}) { + require Message::DOM::XMLParserTemp; -
-

Document Source

-]; - push @nav, ['#source-string' => 'Source']; - print_source_string (\$t); print STDOUT qq[ -
-

Parse Errors

@@ -156,20 +144,20 @@ return 1; }; - open my $fh, '<', \$s; + open my $fh, '<', \($input->{s}); $doc = Message::DOM::XMLParserTemp->parse_byte_stream - ($fh => $dom, $onerror, charset => 'utf-8'); + ($fh => $dom, $onerror, charset => $input->{charset}); print STDOUT qq[
+ ]; + print_source_string_section (\($input->{s}), $doc->input_encoding); } else { + ## TODO: Change HTTP status code?? print STDOUT qq[ - - -
-

Media type @{[htescape $input_format]} is not supported!

+

Media type @{[htescape $input->{media_type}]} is not supported!

]; push @nav, ['#result-summary' => 'Result']; @@ -288,6 +276,18 @@ } ## TODO: Show result +} else { + print STDOUT qq[ + + + +
+

Input Error: @{[htescape ($input->{error_status_text})]}

+
+]; + push @nav, ['#result-summary' => 'Result']; + +} print STDOUT qq[