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 ($%) { |
137 |
$self->html ('<div class=section'); |
$self->html ('<div class=section'); |
138 |
if (defined $opt{id}) { |
if (defined $opt{id}) { |
139 |
my $id = $self->input->id_prefix . $opt{id}; |
my $id = $self->input->id_prefix . $opt{id}; |
140 |
$self->html (' id="' . $htescape->($id) . '"'); |
$self->html (' id="' . $htescape->($id) . '">'); |
141 |
push @{$self->{nav}}, |
if ($self->{section_rank} == 2) { |
142 |
[$id => $opt{short_title} || $opt{title} => $opt{text}] |
my $st = $opt{short_title} || $opt{title}; |
143 |
if $self->{section_rank} == 2; |
push @{$self->{nav}}, |
144 |
|
[$id => $st => $opt{text}]; |
145 |
|
|
146 |
|
$self->start_tag ('script'); |
147 |
|
$self->html (qq[ addSectionLink ('] . $self->input->id_prefix . |
148 |
|
qq[$id', ']); |
149 |
|
$self->nl_text ($st, text => $opt{text}); |
150 |
|
$self->html (q[') ]); |
151 |
|
$self->end_tag ('script'); |
152 |
|
} |
153 |
|
} else { |
154 |
|
$self->html ('>'); |
155 |
} |
} |
156 |
my $section_rank = $self->{section_rank}; |
my $section_rank = $self->{section_rank}; |
157 |
$section_rank = 6 if $section_rank > 6; |
$section_rank = 6 if $section_rank > 6; |
158 |
$self->html ('><h' . $section_rank . '>'); |
$self->html ('<h' . $section_rank . '>'); |
159 |
$self->nl_text ($opt{title}, text => $opt{text}); |
$self->nl_text ($opt{title}, text => $opt{text}); |
160 |
$self->html ('</h' . $section_rank . '>'); |
$self->html ('</h' . $section_rank . '>'); |
161 |
} # start_section |
} # start_section |
210 |
my $self = shift; |
my $self = shift; |
211 |
|
|
212 |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
213 |
q[', '] . shift . q[')]); |
q[', '] . shift () . q[')]); |
214 |
} # add_source_to_parse_error_list |
} # add_source_to_parse_error_list |
215 |
|
|
216 |
sub start_code_block ($) { |
sub start_code_block ($) { |
241 |
$self->nl_text ($content, text => $opt{text}); |
$self->nl_text ($content, text => $opt{text}); |
242 |
} # dt |
} # dt |
243 |
|
|
244 |
|
sub select ($$%) { |
245 |
|
my ($self, $options, %opt) = @_; |
246 |
|
|
247 |
|
my $selected = $opt{selected}; |
248 |
|
delete $opt{selected}; |
249 |
|
|
250 |
|
$self->start_tag ('select', %opt); |
251 |
|
|
252 |
|
my @options = @$options; |
253 |
|
while (@options) { |
254 |
|
my $opt = shift @options; |
255 |
|
if ($opt->{options}) { |
256 |
|
$self->html ('<optgroup label="'); |
257 |
|
$self->nl_text ($opt->{label}); |
258 |
|
$self->html ('">'); |
259 |
|
unshift @options, @{$opt->{options}}, {end_options => 1}; |
260 |
|
} elsif ($opt->{end_options}) { |
261 |
|
$self->end_tag ('optgroup'); |
262 |
|
} else { |
263 |
|
$self->start_tag ('option', value => $opt->{value}, |
264 |
|
((defined $selected and $opt->{value} eq $selected) |
265 |
|
? (selected => '') : ())); |
266 |
|
$self->nl_text (defined $opt->{label} ? $opt->{label} : $opt->{value}); |
267 |
|
} |
268 |
|
} |
269 |
|
|
270 |
|
$self->end_tag ('select'); |
271 |
|
} # select |
272 |
|
|
273 |
sub link ($$%) { |
sub link ($$%) { |
274 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
275 |
$self->start_tag ('a', %opt, href => $opt{url}); |
$self->start_tag ('a', %opt, href => $opt{url}); |
317 |
return join '/', @r; |
return join '/', @r; |
318 |
}; # $get_node_path |
}; # $get_node_path |
319 |
|
|
320 |
|
my $get_object_path = sub ($) { |
321 |
|
my $node = shift; |
322 |
|
my @r; |
323 |
|
while (defined $node) { |
324 |
|
my $ref = ref $node; |
325 |
|
$ref =~ /([^:]+)$/; |
326 |
|
my $rs = $1; |
327 |
|
my $node_name = $node->node_name; |
328 |
|
if (defined $node_name) { |
329 |
|
$rs .= ' <code>' . $htescape->($node_name) . '</code>'; |
330 |
|
} |
331 |
|
$node = undef; |
332 |
|
unshift @r, $rs; |
333 |
|
} |
334 |
|
return join '/', @r; |
335 |
|
}; # $get_object_path |
336 |
|
|
337 |
sub node_link ($$) { |
sub node_link ($$) { |
338 |
my ($self, $node) = @_; |
my ($self, $node) = @_; |
339 |
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
if ($node->isa ('Message::IF::Node')) { |
340 |
|
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
341 |
|
} else { |
342 |
|
$self->html ($get_object_path->($node)); |
343 |
|
} |
344 |
} # node_link |
} # node_link |
345 |
|
|
346 |
{ |
{ |
442 |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
443 |
<script src="../cc-script.js"></script> |
<script src="../cc-script.js"></script> |
444 |
</head> |
</head> |
445 |
<body> |
<body onclick=" return onbodyclick (event) " onload=" onbodyload () "> |
446 |
<h1>]); |
<h1>]); |
447 |
$self->nl_text (q[WebHACC:Heading]); |
$self->nl_text (q[WebHACC:Heading]); |
448 |
$self->html ('</h1>'); |
$self->html (q[</h1><script> insertNavSections () </script>]); |
449 |
} # html_header |
} # html_header |
450 |
|
|
451 |
|
sub generate_input_section ($$) { |
452 |
|
my ($out, $cgi) = @_; |
453 |
|
|
454 |
|
my $options = sub ($) { |
455 |
|
my $context = shift; |
456 |
|
|
457 |
|
$out->html (q[<div class=details><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'none' ? 'block' : 'none'">]); |
458 |
|
$out->nl_text (q[Options]); |
459 |
|
$out->start_tag ('div'); |
460 |
|
|
461 |
|
if ($context eq 'url') { |
462 |
|
$out->start_tag ('p'); |
463 |
|
$out->start_tag ('label'); |
464 |
|
$out->start_tag ('input', type => 'checkbox', name => 'error-page', |
465 |
|
value => 1, |
466 |
|
($cgi->get_parameter ('error-page') |
467 |
|
? (checked => '') : ())); |
468 |
|
$out->nl_text ('Check error page'); |
469 |
|
$out->end_tag ('label'); |
470 |
|
} |
471 |
|
|
472 |
|
$out->start_tag ('p'); |
473 |
|
$out->start_tag ('label'); |
474 |
|
$out->nl_text (q[Content type]); |
475 |
|
$out->text (': '); |
476 |
|
$out->select ([ |
477 |
|
{value => '', label => 'As specified'}, |
478 |
|
{value => 'application/atom+xml'}, |
479 |
|
{value => 'application/xhtml+xml'}, |
480 |
|
{value => 'application/xml'}, |
481 |
|
{value => 'text/html'}, |
482 |
|
{value => 'text/xml'}, |
483 |
|
{value => 'text/css'}, |
484 |
|
{value => 'text/cache-manifest'}, |
485 |
|
{value => 'text/x-webidl'}, |
486 |
|
], name => 'i', selected => scalar $cgi->get_parameter ('i')); |
487 |
|
$out->end_tag ('label'); |
488 |
|
|
489 |
|
if ($context ne 'text') { |
490 |
|
$out->start_tag ('p'); |
491 |
|
$out->start_tag ('label'); |
492 |
|
$out->nl_text (q[Charset]); |
493 |
|
$out->text (q[: ]); |
494 |
|
$out->select ([ |
495 |
|
{value => '', label => 'As specified'}, |
496 |
|
{label => 'Japanese charsets', options => [ |
497 |
|
{value => 'Windows-31J'}, |
498 |
|
{value => 'Shift_JIS'}, |
499 |
|
{value => 'EUC-JP'}, |
500 |
|
{value => 'ISO-2022-JP'}, |
501 |
|
]}, |
502 |
|
{label => 'European charsets', options => [ |
503 |
|
{value => 'Windows-1252'}, |
504 |
|
{value => 'ISO-8859-1'}, |
505 |
|
{value => 'US-ASCII'}, |
506 |
|
]}, |
507 |
|
{label => 'Asian charsets', options => [ |
508 |
|
{value => 'Windows-874'}, |
509 |
|
{value => 'ISO-8859-11'}, |
510 |
|
{value => 'TIS-620'}, |
511 |
|
]}, |
512 |
|
{label => 'Unicode charsets', options => [ |
513 |
|
{value => 'UTF-8'}, |
514 |
|
{value => 'UTF-8n'}, |
515 |
|
]}, |
516 |
|
], name => 'charset', |
517 |
|
selected => scalar $cgi->get_parameter ('charset')); |
518 |
|
$out->end_tag ('label'); |
519 |
|
} |
520 |
|
|
521 |
|
if ($context eq 'text') { |
522 |
|
$out->start_tag ('p'); |
523 |
|
$out->start_tag ('label'); |
524 |
|
$out->nl_text ('Setting innerHTML'); |
525 |
|
$out->text (': '); |
526 |
|
$out->start_tag ('input', name => 'e', |
527 |
|
value => scalar $cgi->get_parameter ('e')); |
528 |
|
$out->end_tag ('label'); |
529 |
|
} |
530 |
|
|
531 |
|
$out->html (q[</div></div>]); |
532 |
|
}; # $options |
533 |
|
|
534 |
|
$out->start_section (id => 'input', title => 'Input'); |
535 |
|
|
536 |
|
$out->start_section (id => 'input-url', title => 'By URL'); |
537 |
|
$out->start_tag ('form', action => './#result-summary', |
538 |
|
'accept-charset' => 'utf-8', |
539 |
|
method => 'get'); |
540 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
541 |
|
|
542 |
|
$out->start_tag ('p'); |
543 |
|
$out->start_tag ('label'); |
544 |
|
$out->nl_text ('URL'); |
545 |
|
$out->text (': '); |
546 |
|
$out->start_tag ('input', |
547 |
|
name => 'uri', |
548 |
|
type => 'url', |
549 |
|
value => $cgi->get_parameter ('uri')); |
550 |
|
$out->end_tag ('label'); |
551 |
|
|
552 |
|
$options->('url'); |
553 |
|
|
554 |
|
$out->start_tag ('p'); |
555 |
|
$out->start_tag ('button', type => 'submit'); |
556 |
|
$out->nl_text ('Check'); |
557 |
|
|
558 |
|
$out->end_tag ('form'); |
559 |
|
$out->end_section; |
560 |
|
|
561 |
|
$out->end_tag ('fieldset'); |
562 |
|
|
563 |
|
## TODO: File upload |
564 |
|
|
565 |
|
$out->start_section (id => 'input-text', title => 'By direct input'); |
566 |
|
$out->start_tag ('form', action => './#result-summary', |
567 |
|
'accept-charset' => 'utf-8', |
568 |
|
method => 'post'); |
569 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
570 |
|
|
571 |
|
$out->start_tag ('p'); |
572 |
|
$out->start_tag ('label'); |
573 |
|
$out->nl_text ('Document source to check'); |
574 |
|
$out->text (': '); |
575 |
|
$out->start_tag ('br'); |
576 |
|
$out->start_tag ('textarea', |
577 |
|
name => 's'); |
578 |
|
my $s = $cgi->get_parameter ('s'); |
579 |
|
$out->html ($htescape_value->($s)) if defined $s; |
580 |
|
$out->end_tag ('textarea'); |
581 |
|
$out->end_tag ('label'); |
582 |
|
|
583 |
|
$options->('text'); |
584 |
|
|
585 |
|
$out->start_tag ('p'); |
586 |
|
$out->start_tag ('button', type => 'submit', |
587 |
|
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
588 |
|
$out->nl_text ('Check'); |
589 |
|
$out->end_tag ('button'); |
590 |
|
|
591 |
|
$out->end_tag ('form'); |
592 |
|
$out->end_section; |
593 |
|
|
594 |
|
$out->end_section; |
595 |
|
} # generate_input_section |
596 |
|
|
597 |
sub encode_url_component ($$) { |
sub encode_url_component ($$) { |
598 |
shift; |
shift; |
599 |
require Encode; |
require Encode; |