16 |
return $s; |
return $s; |
17 |
}; |
}; |
18 |
|
|
19 |
|
my $htescape_value = sub ($) { |
20 |
|
my $s = $_[0]; |
21 |
|
$s =~ s/&/&/g; |
22 |
|
$s =~ s/</</g; |
23 |
|
$s =~ s/>/>/g; |
24 |
|
$s =~ s/"/"/g; |
25 |
|
return $s; |
26 |
|
}; |
27 |
|
|
28 |
sub new ($) { |
sub new ($) { |
29 |
return bless {nav => [], section_rank => 1}, shift; |
require WebHACC::Input; |
30 |
|
return bless {nav => [], section_rank => 1, |
31 |
|
input => WebHACC::Input->new}, shift; |
32 |
} # new |
} # new |
33 |
|
|
34 |
sub input ($;$) { |
sub input ($;$) { |
36 |
if (defined $_[1]) { |
if (defined $_[1]) { |
37 |
$_[0]->{input} = $_[1]; |
$_[0]->{input} = $_[1]; |
38 |
} else { |
} else { |
39 |
delete $_[0]->{input}; |
$_[0]->{input} = WebHACC::Input->new; |
40 |
} |
} |
41 |
} |
} |
42 |
|
|
84 |
|
|
85 |
sub start_tag ($$%) { |
sub start_tag ($$%) { |
86 |
my ($self, $tag_name, %opt) = @_; |
my ($self, $tag_name, %opt) = @_; |
87 |
$self->html ('<' . $htescape->($tag_name)); # escape for safety |
$self->html ('<' . $htescape_value->($tag_name)); # escape for safety |
88 |
if (exists $opt{id}) { |
if (exists $opt{id}) { |
89 |
my $id = $self->input->id_prefix . $opt{id}; |
my $id = $self->input->id_prefix . $opt{id}; |
90 |
$self->html (' id="' . $htescape->($id) . '"'); |
$self->html (' id="' . $htescape_value->($id) . '"'); |
91 |
delete $opt{id}; |
delete $opt{id}; |
92 |
} |
} |
93 |
for (keys %opt) { # for safety |
for (keys %opt) { # for safety |
94 |
$self->html (' ' . $htescape->($_) . '="' . $htescape->($opt{$_}) . '"'); |
$self->html (' ' . $htescape_value->($_) . '="' . |
95 |
|
$htescape_value->($opt{$_}) . '"'); |
96 |
} |
} |
97 |
$self->html ('>'); |
$self->html ('>'); |
98 |
} # start_tag |
} # start_tag |
99 |
|
|
100 |
sub end_tag ($$) { |
sub end_tag ($$) { |
101 |
shift->html ('</' . $htescape->(shift) . '>'); |
shift->html ('</' . $htescape_value->(shift) . '>'); |
102 |
} # end_tag |
} # end_tag |
103 |
|
|
104 |
sub start_section ($%) { |
sub start_section ($%) { |
199 |
my $self = shift; |
my $self = shift; |
200 |
|
|
201 |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
202 |
q[', '] . shift . q[')]); |
q[', '] . shift () . q[')]); |
203 |
} # add_source_to_parse_error_list |
} # add_source_to_parse_error_list |
204 |
|
|
205 |
sub start_code_block ($) { |
sub start_code_block ($) { |
230 |
$self->nl_text ($content, text => $opt{text}); |
$self->nl_text ($content, text => $opt{text}); |
231 |
} # dt |
} # dt |
232 |
|
|
233 |
|
sub select ($$%) { |
234 |
|
my ($self, $options, %opt) = @_; |
235 |
|
|
236 |
|
my $selected = $opt{selected}; |
237 |
|
delete $opt{selected}; |
238 |
|
|
239 |
|
$self->start_tag ('select', %opt); |
240 |
|
|
241 |
|
my @options = @$options; |
242 |
|
while (@options) { |
243 |
|
my $opt = shift @options; |
244 |
|
if ($opt->{options}) { |
245 |
|
$self->html ('<optgroup label="'); |
246 |
|
$self->nl_text ($opt->{label}); |
247 |
|
$self->html ('">'); |
248 |
|
unshift @options, @{$opt->{options}}, {end_options => 1}; |
249 |
|
} elsif ($opt->{end_options}) { |
250 |
|
$self->end_tag ('optgroup'); |
251 |
|
} else { |
252 |
|
$self->start_tag ('option', value => $opt->{value}, |
253 |
|
((defined $selected and $opt->{value} eq $selected) |
254 |
|
? (selected => '') : ())); |
255 |
|
$self->nl_text (defined $opt->{label} ? $opt->{label} : $opt->{value}); |
256 |
|
} |
257 |
|
} |
258 |
|
|
259 |
|
$self->end_tag ('select'); |
260 |
|
} # select |
261 |
|
|
262 |
sub link ($$%) { |
sub link ($$%) { |
263 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
264 |
$self->start_tag ('a', %opt, href => $opt{url}); |
$self->start_tag ('a', %opt, href => $opt{url}); |
306 |
return join '/', @r; |
return join '/', @r; |
307 |
}; # $get_node_path |
}; # $get_node_path |
308 |
|
|
309 |
|
my $get_object_path = sub ($) { |
310 |
|
my $node = shift; |
311 |
|
my @r; |
312 |
|
while (defined $node) { |
313 |
|
my $ref = ref $node; |
314 |
|
$ref =~ /([^:]+)$/; |
315 |
|
my $rs = $1; |
316 |
|
my $node_name = $node->node_name; |
317 |
|
if (defined $node_name) { |
318 |
|
$rs .= ' <code>' . $htescape->($node_name) . '</code>'; |
319 |
|
} |
320 |
|
$node = undef; |
321 |
|
unshift @r, $rs; |
322 |
|
} |
323 |
|
return join '/', @r; |
324 |
|
}; # $get_object_path |
325 |
|
|
326 |
sub node_link ($$) { |
sub node_link ($$) { |
327 |
my ($self, $node) = @_; |
my ($self, $node) = @_; |
328 |
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
if ($node->isa ('Message::IF::Node')) { |
329 |
|
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
330 |
|
} else { |
331 |
|
$self->html ($get_object_path->($node)); |
332 |
|
} |
333 |
} # node_link |
} # node_link |
334 |
|
|
335 |
{ |
{ |
437 |
$self->html ('</h1>'); |
$self->html ('</h1>'); |
438 |
} # html_header |
} # html_header |
439 |
|
|
440 |
|
sub generate_input_section ($$) { |
441 |
|
my ($out, $cgi) = @_; |
442 |
|
|
443 |
|
my $options = sub ($) { |
444 |
|
my $context = shift; |
445 |
|
|
446 |
|
$out->html (q[<div class=details><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'none' ? 'block' : 'none'">]); |
447 |
|
$out->nl_text (q[Options]); |
448 |
|
$out->start_tag ('div'); |
449 |
|
|
450 |
|
if ($context eq 'url') { |
451 |
|
$out->start_tag ('p'); |
452 |
|
$out->start_tag ('label'); |
453 |
|
$out->start_tag ('input', type => 'checkbox', name => 'error-page', |
454 |
|
value => 1, |
455 |
|
($cgi->get_parameter ('error-page') |
456 |
|
? (checked => '') : ())); |
457 |
|
$out->nl_text ('Check error page'); |
458 |
|
$out->end_tag ('label'); |
459 |
|
} |
460 |
|
|
461 |
|
$out->start_tag ('p'); |
462 |
|
$out->start_tag ('label'); |
463 |
|
$out->nl_text (q[Content type]); |
464 |
|
$out->text (': '); |
465 |
|
$out->select ([ |
466 |
|
{value => '', label => 'As specified'}, |
467 |
|
{value => 'application/atom+xml'}, |
468 |
|
{value => 'application/xhtml+xml'}, |
469 |
|
{value => 'application/xml'}, |
470 |
|
{value => 'text/html'}, |
471 |
|
{value => 'text/xml'}, |
472 |
|
{value => 'text/css'}, |
473 |
|
{value => 'text/cache-manifest'}, |
474 |
|
{value => 'text/x-webidl'}, |
475 |
|
], name => 'i', selected => scalar $cgi->get_parameter ('i')); |
476 |
|
$out->end_tag ('label'); |
477 |
|
|
478 |
|
if ($context ne 'text') { |
479 |
|
$out->start_tag ('p'); |
480 |
|
$out->start_tag ('label'); |
481 |
|
$out->nl_text (q[Charset]); |
482 |
|
$out->text (q[: ]); |
483 |
|
$out->select ([ |
484 |
|
{value => '', label => 'As specified'}, |
485 |
|
{label => 'Japanese charsets', options => [ |
486 |
|
{value => 'Windows-31J'}, |
487 |
|
{value => 'Shift_JIS'}, |
488 |
|
{value => 'EUC-JP'}, |
489 |
|
{value => 'ISO-2022-JP'}, |
490 |
|
]}, |
491 |
|
{label => 'European charsets', options => [ |
492 |
|
{value => 'Windows-1252'}, |
493 |
|
{value => 'ISO-8859-1'}, |
494 |
|
{value => 'US-ASCII'}, |
495 |
|
]}, |
496 |
|
{label => 'Asian charsets', options => [ |
497 |
|
{value => 'Windows-874'}, |
498 |
|
{value => 'ISO-8859-11'}, |
499 |
|
{value => 'TIS-620'}, |
500 |
|
]}, |
501 |
|
{label => 'Unicode charsets', options => [ |
502 |
|
{value => 'UTF-8'}, |
503 |
|
{value => 'UTF-8n'}, |
504 |
|
]}, |
505 |
|
], name => 'charset', |
506 |
|
selected => scalar $cgi->get_parameter ('charset')); |
507 |
|
$out->end_tag ('label'); |
508 |
|
} |
509 |
|
|
510 |
|
if ($context eq 'text') { |
511 |
|
$out->start_tag ('p'); |
512 |
|
$out->start_tag ('label'); |
513 |
|
$out->nl_text ('Setting innerHTML'); |
514 |
|
$out->text (': '); |
515 |
|
$out->start_tag ('input', name => 'e', |
516 |
|
value => scalar $cgi->get_parameter ('e')); |
517 |
|
$out->end_tag ('label'); |
518 |
|
} |
519 |
|
|
520 |
|
$out->html (q[</div></div>]); |
521 |
|
}; # $options |
522 |
|
|
523 |
|
$out->start_section (id => 'input', title => 'Input'); |
524 |
|
|
525 |
|
$out->start_section (id => 'input-url', title => 'By URL'); |
526 |
|
$out->start_tag ('form', action => './#result-summary', |
527 |
|
'accept-charset' => 'utf-8', |
528 |
|
method => 'get'); |
529 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
530 |
|
|
531 |
|
$out->start_tag ('p'); |
532 |
|
$out->start_tag ('label'); |
533 |
|
$out->nl_text ('URL'); |
534 |
|
$out->text (': '); |
535 |
|
$out->start_tag ('input', |
536 |
|
name => 'uri', |
537 |
|
type => 'url', |
538 |
|
value => $cgi->get_parameter ('uri')); |
539 |
|
$out->end_tag ('label'); |
540 |
|
|
541 |
|
$options->('url'); |
542 |
|
|
543 |
|
$out->start_tag ('p'); |
544 |
|
$out->start_tag ('button', type => 'submit'); |
545 |
|
$out->nl_text ('Check'); |
546 |
|
|
547 |
|
$out->end_tag ('form'); |
548 |
|
$out->end_section; |
549 |
|
|
550 |
|
$out->end_tag ('fieldset'); |
551 |
|
|
552 |
|
## TODO: File upload |
553 |
|
|
554 |
|
$out->start_section (id => 'input-text', title => 'By direct input'); |
555 |
|
$out->start_tag ('form', action => './#result-summary', |
556 |
|
'accept-charset' => 'utf-8', |
557 |
|
method => 'post'); |
558 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
559 |
|
|
560 |
|
$out->start_tag ('p'); |
561 |
|
$out->start_tag ('label'); |
562 |
|
$out->nl_text ('Document source to check'); |
563 |
|
$out->text (': '); |
564 |
|
$out->start_tag ('br'); |
565 |
|
$out->start_tag ('textarea', |
566 |
|
name => 's'); |
567 |
|
my $s = $cgi->get_parameter ('s'); |
568 |
|
$out->html ($htescape_value->($s)) if defined $s; |
569 |
|
$out->end_tag ('textarea'); |
570 |
|
$out->end_tag ('label'); |
571 |
|
|
572 |
|
$options->('text'); |
573 |
|
|
574 |
|
$out->start_tag ('p'); |
575 |
|
$out->start_tag ('button', type => 'submit', |
576 |
|
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
577 |
|
$out->nl_text ('Check'); |
578 |
|
$out->end_tag ('button'); |
579 |
|
|
580 |
|
$out->end_tag ('form'); |
581 |
|
$out->end_section; |
582 |
|
|
583 |
|
$out->end_section; |
584 |
|
} # generate_input_section |
585 |
|
|
586 |
sub encode_url_component ($$) { |
sub encode_url_component ($$) { |
587 |
shift; |
shift; |
588 |
require Encode; |
require Encode; |