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 |
|
|
55 |
return $_[0]->{handle}; |
return $_[0]->{handle}; |
56 |
} # handle |
} # handle |
57 |
|
|
58 |
|
sub has_error ($;$) { |
59 |
|
if (@_ > 1) { |
60 |
|
if (defined $_[1]) { |
61 |
|
$_[0]->{has_error} = 1; |
62 |
|
} else { |
63 |
|
delete $_[0]->{has_error}; |
64 |
|
} |
65 |
|
} |
66 |
|
|
67 |
|
return $_[0]->{has_error}; |
68 |
|
} # has_error |
69 |
|
|
70 |
sub set_utf8 ($) { |
sub set_utf8 ($) { |
71 |
binmode shift->{handle}, ':utf8'; |
binmode shift->{handle}, ':utf8'; |
72 |
} # set_utf8 |
} # set_utf8 |
96 |
|
|
97 |
sub start_tag ($$%) { |
sub start_tag ($$%) { |
98 |
my ($self, $tag_name, %opt) = @_; |
my ($self, $tag_name, %opt) = @_; |
99 |
$self->html ('<' . $htescape->($tag_name)); # escape for safety |
$self->html ('<' . $htescape_value->($tag_name)); # escape for safety |
100 |
if (exists $opt{id}) { |
if (exists $opt{id}) { |
101 |
my $id = $self->input->id_prefix . $opt{id}; |
my $id = $self->input->id_prefix . $opt{id}; |
102 |
$self->html (' id="' . $htescape->($id) . '"'); |
$self->html (' id="' . $htescape_value->($id) . '"'); |
103 |
delete $opt{id}; |
delete $opt{id}; |
104 |
} |
} |
105 |
for (keys %opt) { # for safety |
for (keys %opt) { # for safety |
106 |
$self->html (' ' . $htescape->($_) . '="' . $htescape->($opt{$_}) . '"'); |
$self->html (' ' . $htescape_value->($_) . '="' . |
107 |
|
$htescape_value->($opt{$_}) . '"'); |
108 |
} |
} |
109 |
$self->html ('>'); |
$self->html ('>'); |
110 |
} # start_tag |
} # start_tag |
111 |
|
|
112 |
sub end_tag ($$) { |
sub end_tag ($$) { |
113 |
shift->html ('</' . $htescape->(shift) . '>'); |
shift->html ('</' . $htescape_value->(shift) . '>'); |
114 |
} # end_tag |
} # end_tag |
115 |
|
|
116 |
sub start_section ($%) { |
sub start_section ($%) { |
117 |
my ($self, %opt) = @_; |
my ($self, %opt) = @_; |
118 |
|
|
119 |
|
my $class = 'section'; |
120 |
if (defined $opt{role}) { |
if (defined $opt{role}) { |
121 |
if ($opt{role} eq 'parse-errors') { |
if ($opt{role} eq 'parse-errors') { |
122 |
$opt{id} ||= 'parse-errors'; |
$opt{id} ||= 'parse-errors'; |
123 |
$opt{title} ||= 'Parse Errors'; |
$opt{title} ||= 'Parse Errors Section'; |
124 |
|
$opt{short_title} ||= 'Parse Errors'; |
125 |
|
$class .= ' errors'; |
126 |
delete $opt{role}; |
delete $opt{role}; |
127 |
} elsif ($opt{role} eq 'structure-errors') { |
} elsif ($opt{role} eq 'structure-errors') { |
128 |
$opt{id} ||= 'document-errors'; |
$opt{id} ||= 'document-errors'; |
129 |
$opt{title} ||= 'Structural Errors'; |
$opt{title} ||= 'Structural Errors'; |
130 |
$opt{short_title} ||= 'Struct. Errors'; |
$opt{short_title} ||= 'Struct. Errors'; |
131 |
|
$class .= ' errors'; |
132 |
|
delete $opt{role}; |
133 |
|
} elsif ($opt{role} eq 'transfer-errors') { |
134 |
|
$opt{id} ||= 'transfer-errors'; |
135 |
|
$opt{title} ||= 'Transfer Errors'; |
136 |
|
$opt{short_title} ||= 'Trans. Errors'; |
137 |
|
$class .= ' errors'; |
138 |
delete $opt{role}; |
delete $opt{role}; |
139 |
} elsif ($opt{role} eq 'reformatted') { |
} elsif ($opt{role} eq 'reformatted') { |
140 |
$opt{id} ||= 'document-tree'; |
$opt{id} ||= 'document-tree'; |
141 |
$opt{title} ||= 'Reformatted Document Source'; |
$opt{title} ||= 'Reformatted Document Source'; |
142 |
$opt{short_title} ||= 'Reformatted'; |
$opt{short_title} ||= 'Reformatted'; |
143 |
|
$class .= ' dump'; |
144 |
delete $opt{role} |
delete $opt{role} |
145 |
} elsif ($opt{role} eq 'tree') { |
} elsif ($opt{role} eq 'tree') { |
146 |
$opt{id} ||= 'document-tree'; |
$opt{id} ||= 'document-tree'; |
147 |
$opt{title} ||= 'Document Tree'; |
$opt{title} ||= 'Document Tree'; |
148 |
$opt{short_title} ||= 'Tree'; |
$opt{short_title} ||= 'Tree'; |
149 |
|
$class .= ' dump'; |
150 |
delete $opt{role}; |
delete $opt{role}; |
151 |
} elsif ($opt{role} eq 'structure') { |
} elsif ($opt{role} eq 'structure') { |
152 |
$opt{id} ||= 'document-structure'; |
$opt{id} ||= 'document-structure'; |
153 |
$opt{title} ||= 'Document Structure'; |
$opt{title} ||= 'Document Structure'; |
154 |
$opt{short_title} ||= 'Structure'; |
$opt{short_title} ||= 'Structure'; |
155 |
|
$class .= ' dump'; |
156 |
|
delete $opt{role}; |
157 |
|
} elsif ($opt{role} eq 'subdoc') { |
158 |
|
$class .= ' subdoc'; |
159 |
|
delete $opt{role}; |
160 |
|
} elsif ($opt{role} eq 'source') { |
161 |
|
$opt{id} ||= 'source-string'; |
162 |
|
$opt{title} ||= 'Document Source'; |
163 |
|
$opt{short_title} ||= 'Source'; |
164 |
|
$class .= ' source'; |
165 |
|
delete $opt{role}; |
166 |
|
} elsif ($opt{role} eq 'result') { |
167 |
|
$opt{id} ||= 'result-summary'; |
168 |
|
$opt{title} ||= 'Result'; |
169 |
|
$class .= ' result'; |
170 |
delete $opt{role}; |
delete $opt{role}; |
171 |
} |
} |
172 |
} |
} |
173 |
|
|
174 |
$self->{section_rank}++; |
$self->{section_rank}++; |
175 |
$self->html ('<div class=section'); |
$self->html (qq[<div class="$class"]); |
176 |
if (defined $opt{id}) { |
if (defined $opt{id}) { |
177 |
my $id = $self->input->id_prefix . $opt{id}; |
my $prefix = $self->input->id_prefix; |
178 |
$self->html (' id="' . $htescape->($id) . '"'); |
$opt{parent_id} ||= $prefix; |
179 |
push @{$self->{nav}}, [$id => $opt{short_title} || $opt{title}] |
my $id = $prefix . $opt{id}; |
180 |
if $self->{section_rank} == 2; |
$self->html (' id="' . $htescape->($id) . '">'); |
181 |
|
if ($self->{section_rank} == 2 or length $opt{parent_id}) { |
182 |
|
my $st = $opt{short_title} || $opt{title}; |
183 |
|
push @{$self->{nav}}, |
184 |
|
[$id => $st => $opt{text}] if $self->{section_rank} == 2; |
185 |
|
|
186 |
|
$self->start_tag ('script'); |
187 |
|
$self->html (qq[ addSectionLink ('$id', ']); |
188 |
|
$self->nl_text ($st, text => $opt{text}); |
189 |
|
if (defined $opt{parent_id}) { |
190 |
|
$self->html (q[', '] . $opt{parent_id}); |
191 |
|
} |
192 |
|
$self->html (q[') ]); |
193 |
|
$self->end_tag ('script'); |
194 |
|
} |
195 |
|
} else { |
196 |
|
$self->html ('>'); |
197 |
} |
} |
198 |
my $section_rank = $self->{section_rank}; |
my $section_rank = $self->{section_rank}; |
199 |
$section_rank = 6 if $section_rank > 6; |
$section_rank = 6 if $section_rank > 6; |
200 |
$self->html ('><h' . $section_rank . '>' . |
$self->html ('<h' . $section_rank . '>'); |
201 |
$htescape->($opt{title}) . |
$self->nl_text ($opt{title}, text => $opt{text}); |
202 |
'</h' . $section_rank . '>'); |
$self->html ('</h' . $section_rank . '>'); |
203 |
} # start_section |
} # start_section |
204 |
|
|
205 |
sub end_section ($) { |
sub end_section ($) { |
219 |
} elsif ($opt{role} eq 'structure-errors') { |
} elsif ($opt{role} eq 'structure-errors') { |
220 |
$opt{id} ||= 'document-errors-list'; |
$opt{id} ||= 'document-errors-list'; |
221 |
delete $opt{role}; |
delete $opt{role}; |
222 |
|
} elsif ($opt{role} eq 'transfer-errors') { |
223 |
|
$opt{id} ||= 'transfer-errors-list'; |
224 |
|
delete $opt{role}; |
225 |
} |
} |
226 |
} |
} |
227 |
|
|
228 |
$self->start_tag ('dl', %opt); |
$self->start_tag ('dl', %opt); |
229 |
|
|
230 |
|
delete $self->{has_error}; # reset |
231 |
} # start_error_list |
} # start_error_list |
232 |
|
|
233 |
sub end_error_list ($%) { |
sub end_error_list ($%) { |
234 |
my ($self, %opt) = @_; |
my ($self, %opt) = @_; |
235 |
|
|
236 |
|
my $no_error_message = 'No error found.'; |
237 |
|
|
238 |
if (defined $opt{role}) { |
if (defined $opt{role}) { |
239 |
if ($opt{role} eq 'parse-errors') { |
if ($opt{role} eq 'parse-errors') { |
|
delete $opt{role}; |
|
240 |
$self->end_tag ('dl'); |
$self->end_tag ('dl'); |
241 |
## NOTE: For parse error list, the |add_source_to_parse_error_list| |
## NOTE: For parse error list, the |add_source_to_parse_error_list| |
242 |
## method is invoked at the end of |generate_source_string_section|, |
## method is invoked at the end of |generate_source_string_section|, |
243 |
## since that generation method is invoked after the error list |
## since that generation method is invoked after the error list |
244 |
## is generated. |
## is generated. |
245 |
|
$no_error_message = 'No parse error found.'; |
246 |
} elsif ($opt{role} eq 'structure-errors') { |
} elsif ($opt{role} eq 'structure-errors') { |
|
delete $opt{role}; |
|
247 |
$self->end_tag ('dl'); |
$self->end_tag ('dl'); |
248 |
$self->add_source_to_parse_error_list ('document-errors-list'); |
$self->add_source_to_parse_error_list ('document-errors-list'); |
249 |
|
$no_error_message = 'No structural error found.'; |
250 |
|
} elsif ($opt{role} eq 'transfer-errors') { |
251 |
|
$self->end_tag ('dl'); |
252 |
|
$no_error_message = 'No transfer error found.'; |
253 |
} else { |
} else { |
254 |
$self->end_tag ('dl'); |
$self->end_tag ('dl'); |
255 |
} |
} |
256 |
} else { |
} else { |
257 |
$self->end_tag ('dl'); |
$self->end_tag ('dl'); |
258 |
} |
} |
259 |
|
|
260 |
|
unless ($self->{has_error}) { |
261 |
|
$self->start_tag ('p', class => 'no-errors'); |
262 |
|
$self->nl_text ($no_error_message); |
263 |
|
} |
264 |
} # end_error_list |
} # end_error_list |
265 |
|
|
266 |
sub add_source_to_parse_error_list ($$) { |
sub add_source_to_parse_error_list ($$) { |
267 |
my $self = shift; |
my $self = shift; |
268 |
|
|
269 |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
$self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix . |
270 |
q[', '] . shift . q[')]); |
q[', '] . shift () . q[')]); |
271 |
} # add_source_to_parse_error_list |
} # add_source_to_parse_error_list |
272 |
|
|
273 |
sub start_code_block ($) { |
sub start_code_block ($) { |
295 |
sub dt ($$;%) { |
sub dt ($$;%) { |
296 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
297 |
$self->start_tag ('dt', %opt); |
$self->start_tag ('dt', %opt); |
298 |
$self->text ($content); |
$self->nl_text ($content, text => $opt{text}); |
299 |
} # dt |
} # dt |
300 |
|
|
301 |
|
sub select ($$%) { |
302 |
|
my ($self, $options, %opt) = @_; |
303 |
|
|
304 |
|
my $selected = $opt{selected}; |
305 |
|
delete $opt{selected}; |
306 |
|
|
307 |
|
$self->start_tag ('select', %opt); |
308 |
|
|
309 |
|
my @options = @$options; |
310 |
|
while (@options) { |
311 |
|
my $opt = shift @options; |
312 |
|
if ($opt->{options}) { |
313 |
|
$self->html ('<optgroup label="'); |
314 |
|
$self->nl_text ($opt->{label}); |
315 |
|
$self->html ('">'); |
316 |
|
unshift @options, @{$opt->{options}}, {end_options => 1}; |
317 |
|
} elsif ($opt->{end_options}) { |
318 |
|
$self->end_tag ('optgroup'); |
319 |
|
} else { |
320 |
|
$self->start_tag ('option', value => $opt->{value}, |
321 |
|
((defined $selected and $opt->{value} eq $selected) |
322 |
|
? (selected => '') : ())); |
323 |
|
$self->nl_text (defined $opt->{label} ? $opt->{label} : $opt->{value}); |
324 |
|
} |
325 |
|
} |
326 |
|
|
327 |
|
$self->end_tag ('select'); |
328 |
|
} # select |
329 |
|
|
330 |
sub link ($$%) { |
sub link ($$%) { |
331 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
332 |
$self->start_tag ('a', %opt, href => $opt{url}); |
$self->start_tag ('a', %opt, href => $opt{url}); |
337 |
sub xref ($$%) { |
sub xref ($$%) { |
338 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
339 |
$self->html ('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">'); |
$self->html ('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">'); |
340 |
|
$self->nl_text ($content, text => $opt{text}); |
341 |
|
$self->html ('</a>'); |
342 |
|
} # xref |
343 |
|
|
344 |
|
sub xref_text ($$%) { |
345 |
|
my ($self, $content, %opt) = @_; |
346 |
|
$self->html ('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">'); |
347 |
$self->text ($content); |
$self->text ($content); |
348 |
$self->html ('</a>'); |
$self->html ('</a>'); |
349 |
} # xref |
} # xref |
354 |
$self->link ($content, %opt); |
$self->link ($content, %opt); |
355 |
} # link_to_webhacc |
} # link_to_webhacc |
356 |
|
|
|
|
|
357 |
my $get_node_path = sub ($) { |
my $get_node_path = sub ($) { |
358 |
my $node = shift; |
my $node = shift; |
359 |
my @r; |
my @r; |
381 |
return join '/', @r; |
return join '/', @r; |
382 |
}; # $get_node_path |
}; # $get_node_path |
383 |
|
|
384 |
|
my $get_object_path = sub ($) { |
385 |
|
my $node = shift; |
386 |
|
my @r; |
387 |
|
while (defined $node) { |
388 |
|
my $ref = ref $node; |
389 |
|
$ref =~ /([^:]+)$/; |
390 |
|
my $rs = $1; |
391 |
|
my $node_name = $node->node_name; |
392 |
|
if (defined $node_name) { |
393 |
|
$rs .= ' <code>' . $htescape->($node_name) . '</code>'; |
394 |
|
} |
395 |
|
$node = undef; |
396 |
|
unshift @r, $rs; |
397 |
|
} |
398 |
|
return join '/', @r; |
399 |
|
}; # $get_object_path |
400 |
|
|
401 |
sub node_link ($$) { |
sub node_link ($$) { |
402 |
my ($self, $node) = @_; |
my ($self, $node) = @_; |
403 |
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
if ($node->isa ('Message::IF::Node')) { |
404 |
|
$self->xref_text ($get_node_path->($node), |
405 |
|
target => 'node-' . refaddr $node); |
406 |
|
} else { |
407 |
|
$self->html ($get_object_path->($node)); |
408 |
|
} |
409 |
} # node_link |
} # node_link |
410 |
|
|
411 |
|
{ |
412 |
|
my $Msg = {}; |
413 |
|
|
414 |
|
sub load_text_catalog ($$) { |
415 |
|
my $self = shift; |
416 |
|
|
417 |
|
my $lang = shift; # MUST be a canonical lang name |
418 |
|
my $file_name = qq[cc-msg.$lang.txt]; |
419 |
|
$lang = 'en' unless -f $file_name; |
420 |
|
$self->{primary_language} = $lang; |
421 |
|
|
422 |
|
open my $file, '<:utf8', $file_name or die "$0: $file_name: $!"; |
423 |
|
while (<$file>) { |
424 |
|
if (s/^([^;]+);([^;]*);//) { |
425 |
|
my ($type, $cls, $msg) = ($1, $2, $_); |
426 |
|
$msg =~ tr/\x0D\x0A//d; |
427 |
|
$Msg->{$type} = [$cls, $msg]; |
428 |
|
} |
429 |
|
} |
430 |
|
} # load_text_catalog |
431 |
|
|
432 |
|
sub nl_text ($$;%) { |
433 |
|
my ($self, $type, %opt) = @_; |
434 |
|
my $node = $opt{node}; |
435 |
|
|
436 |
|
if (defined $Msg->{$type}) { |
437 |
|
my $msg = $Msg->{$type}->[1]; |
438 |
|
if ($msg =~ /<var>/) { |
439 |
|
$msg =~ s{<var>{\@([A-Za-z0-9:_.-]+)}</var>}{ |
440 |
|
UNIVERSAL::can ($node, 'get_attribute_ns') |
441 |
|
? $htescape->($node->get_attribute_ns (undef, $1)) : '' |
442 |
|
}ge; |
443 |
|
$msg =~ s{<var>{\@}</var>}{ |
444 |
|
UNIVERSAL::can ($node, 'value') ? $htescape->($node->value) : '' |
445 |
|
}ge; |
446 |
|
$msg =~ s{<var>{text}</var>}{ |
447 |
|
defined $opt{text} ? $htescape->($opt{text}) : '' |
448 |
|
}ge; |
449 |
|
$msg =~ s{<var>{value}</var>}{ |
450 |
|
defined $opt{value} ? $htescape->($opt{value}) : '' |
451 |
|
}ge; |
452 |
|
$msg =~ s{<var>{octets}</var>}{ |
453 |
|
if (defined $opt{octets}) { |
454 |
|
join ', ', map {sprintf '0x%02X', ord $_} split //, ${$opt{octets}}; |
455 |
|
} else { |
456 |
|
''; |
457 |
|
} |
458 |
|
}ge; |
459 |
|
$msg =~ s{<var>{char}</var>}{ |
460 |
|
defined $opt{char} ? $htescape->(${$opt{char}}) : '' |
461 |
|
}ge; |
462 |
|
$msg =~ s{<var>{char:hexref}</var>}{ |
463 |
|
if (defined $opt{char}) { |
464 |
|
join '', map {sprintf '&#x%02X;', ord $_} split //, ${$opt{char}}; |
465 |
|
} else { |
466 |
|
''; |
467 |
|
} |
468 |
|
}ge; |
469 |
|
$msg =~ s{<var>{local-name}</var>}{ |
470 |
|
UNIVERSAL::can ($node, 'manakai_local_name') |
471 |
|
? $htescape->($node->manakai_local_name) : '' |
472 |
|
}ge; |
473 |
|
$msg =~ s{<var>{element-local-name}</var>}{ |
474 |
|
(UNIVERSAL::can ($node, 'owner_element') and $node->owner_element) |
475 |
|
? $htescape->($node->owner_element->manakai_local_name) : '' |
476 |
|
}ge; |
477 |
|
} |
478 |
|
$self->html ($msg); |
479 |
|
} else { |
480 |
|
$self->text ($type); |
481 |
|
} |
482 |
|
} # nl_text |
483 |
|
|
484 |
|
} |
485 |
|
|
486 |
sub nav_list ($) { |
sub nav_list ($) { |
487 |
my $self = shift; |
my $self = shift; |
488 |
$self->html (q[<ul class="navigation" id="nav-items">]); |
$self->html (q[<ul class="navigation" id="nav-items">]); |
489 |
for (@{$self->{nav}}) { |
for (@{$self->{nav}}) { |
490 |
$self->html (qq[<li><a href="#@{[$htescape->($_->[0])]}">@{[$htescape->($_->[1])]}</a>]); |
$self->html (qq[<li><a href="#@{[$htescape->($_->[0])]}">]); |
491 |
|
$self->nl_text ($_->[1], text => $_->[2]); |
492 |
|
$self->html ('</a>'); |
493 |
} |
} |
494 |
$self->html ('</ul>'); |
$self->html ('</ul>'); |
495 |
} # nav_list |
} # nav_list |
509 |
|
|
510 |
sub html_header ($) { |
sub html_header ($) { |
511 |
my $self = shift; |
my $self = shift; |
512 |
$self->html (q[<!DOCTYPE html> |
$self->html (q[<!DOCTYPE html>]); |
513 |
<html lang="en"> |
$self->start_tag ('html', lang => $self->{primary_language}); |
514 |
<head> |
$self->html (q[<head><title>]); |
515 |
<title>Web Document Conformance Checker (BETA)</title> |
$self->nl_text (q[WebHACC:Title]); |
516 |
|
$self->html (q[</title> |
517 |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
518 |
|
<script src="../cc-script.js"></script> |
519 |
</head> |
</head> |
520 |
<body> |
<body onclick=" return onbodyclick (event) " onload=" onbodyload () "> |
521 |
<h1><a href="../cc-interface">Web Document Conformance Checker</a> |
<h1>]); |
522 |
(<em>beta</em>)</h1> |
$self->nl_text (q[WebHACC:Heading]); |
523 |
]); |
$self->html (q[</h1><script> insertNavSections () </script>]); |
524 |
} # html_header |
} # html_header |
525 |
|
|
526 |
|
sub generate_input_section ($$) { |
527 |
|
my ($out, $cgi) = @_; |
528 |
|
|
529 |
|
require Encode; |
530 |
|
my $decode = sub ($) { |
531 |
|
if (defined $_[0]) { |
532 |
|
return Encode::decode ('utf-8', $_[0]); |
533 |
|
} else { |
534 |
|
return undef; |
535 |
|
} |
536 |
|
}; # $decode |
537 |
|
|
538 |
|
my $options = sub ($) { |
539 |
|
my $context = shift; |
540 |
|
|
541 |
|
$out->html (q[<div class="details default"><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'block' ? 'none' : 'block'; parentNode.className = nextSibling.style.display == 'none' ? 'details' : 'details open'">]); |
542 |
|
$out->nl_text (q[Options]); |
543 |
|
$out->start_tag ('div'); |
544 |
|
|
545 |
|
if ($context eq 'url') { |
546 |
|
$out->start_tag ('p'); |
547 |
|
$out->start_tag ('label'); |
548 |
|
$out->start_tag ('input', type => 'checkbox', name => 'error-page', |
549 |
|
value => 1, |
550 |
|
($cgi->get_parameter ('error-page') |
551 |
|
? (checked => '') : ())); |
552 |
|
$out->nl_text ('Check error page'); |
553 |
|
$out->end_tag ('label'); |
554 |
|
} |
555 |
|
|
556 |
|
$out->start_tag ('p'); |
557 |
|
$out->start_tag ('label'); |
558 |
|
$out->nl_text (q[Content type]); |
559 |
|
$out->text (': '); |
560 |
|
$out->select ([ |
561 |
|
{value => '', label => 'As specified'}, |
562 |
|
{value => 'application/atom+xml'}, |
563 |
|
{value => 'text/cache-manifest'}, |
564 |
|
{value => 'text/css'}, |
565 |
|
{value => 'text/x-h2h'}, |
566 |
|
{value => 'text/html'}, |
567 |
|
{value => 'text/x-webidl'}, |
568 |
|
{value => 'application/xhtml+xml'}, |
569 |
|
{value => 'application/xml'}, |
570 |
|
{value => 'text/xml'}, |
571 |
|
], name => 'i', selected => scalar $cgi->get_parameter ('i')); |
572 |
|
$out->end_tag ('label'); |
573 |
|
|
574 |
|
if ($context ne 'text') { |
575 |
|
$out->start_tag ('p'); |
576 |
|
$out->start_tag ('label'); |
577 |
|
$out->nl_text (q[Charset]); |
578 |
|
$out->text (q[: ]); |
579 |
|
$out->select ([ |
580 |
|
{value => '', label => 'As specified'}, |
581 |
|
{label => 'Japanese charsets', options => [ |
582 |
|
{value => 'Windows-31J'}, |
583 |
|
{value => 'Shift_JIS'}, |
584 |
|
{value => 'x-sjis'}, |
585 |
|
{value => 'EUC-JP'}, |
586 |
|
{value => 'x-euc-jp'}, |
587 |
|
{value => 'ISO-2022-JP'}, |
588 |
|
{value => 'ISO-2022-JP-1'}, |
589 |
|
{value => 'ISO-2022-JP-2'}, |
590 |
|
]}, |
591 |
|
{label => 'Latin charsets', options => [ |
592 |
|
{value => 'Windows-1250'}, |
593 |
|
{value => 'Windows-1252'}, |
594 |
|
{value => 'Windows-1254'}, |
595 |
|
{value => 'Windows-1257'}, |
596 |
|
{value => 'Windows-1258'}, |
597 |
|
{value => 'ISO-8859-1'}, |
598 |
|
{value => 'ISO-8859-2'}, |
599 |
|
{value => 'ISO-8859-3'}, |
600 |
|
{value => 'ISO-8859-4'}, |
601 |
|
{value => 'ISO-8859-9'}, |
602 |
|
{value => 'ISO-8859-10'}, |
603 |
|
{value => 'ISO-8859-13'}, |
604 |
|
{value => 'ISO-8859-14'}, |
605 |
|
{value => 'ISO-8859-15'}, |
606 |
|
{value => 'ISO-8859-16'}, |
607 |
|
{value => 'US-ASCII'}, |
608 |
|
]}, |
609 |
|
{label => 'Greek charsets', options => [ |
610 |
|
{value => 'Windows-1253'}, |
611 |
|
{value => 'ISO-8859-7'}, |
612 |
|
]}, |
613 |
|
{label => 'Cyrillic charsets', options => [ |
614 |
|
{value => 'Windows-1251'}, |
615 |
|
{value => 'ISO-8859-5'}, |
616 |
|
]}, |
617 |
|
{label => 'Arabic charsets', options => [ |
618 |
|
{value => 'Windows-1256'}, |
619 |
|
{value => 'ISO-8859-6'}, |
620 |
|
]}, |
621 |
|
{label => 'Hebrew charsets', options => [ |
622 |
|
{value => 'Windows-1255'}, |
623 |
|
{value => 'ISO-8859-8'}, |
624 |
|
]}, |
625 |
|
{label => 'Thai charsets', options => [ |
626 |
|
{value => 'Windows-874'}, |
627 |
|
{value => 'ISO-8859-11'}, |
628 |
|
{value => 'TIS-620'}, |
629 |
|
]}, |
630 |
|
{label => 'Chinese charsets', options => [ |
631 |
|
{value => 'Big5'}, |
632 |
|
{value => 'x-x-big5'}, |
633 |
|
{value => 'Big5-HKSCS'}, |
634 |
|
{value => 'GBK'}, |
635 |
|
{value => 'GB2312'}, |
636 |
|
{value => 'GB_2312-80'}, |
637 |
|
{value => 'ISO-2022-CN'}, |
638 |
|
{value => 'ISO-2022-CN-EXT'}, |
639 |
|
]}, |
640 |
|
{label => 'Korean charsets', options => [ |
641 |
|
{value => 'Windows-949'}, |
642 |
|
{value => 'EUC-KR'}, |
643 |
|
{value => 'KS_C_5601-1987'}, |
644 |
|
{value => 'ISO-2022-KR'}, |
645 |
|
]}, |
646 |
|
{label => 'Unicode charsets', options => [ |
647 |
|
{value => 'UTF-8'}, |
648 |
|
{value => 'UTF-8n'}, |
649 |
|
{value => 'UTF-16'}, |
650 |
|
{value => 'UTF-16BE'}, |
651 |
|
{value => 'UTF-16LE'}, |
652 |
|
]}, |
653 |
|
], name => 'charset', |
654 |
|
selected => scalar $cgi->get_parameter ('charset')); |
655 |
|
$out->end_tag ('label'); |
656 |
|
} |
657 |
|
|
658 |
|
if ($context eq 'text') { |
659 |
|
$out->start_tag ('p'); |
660 |
|
$out->start_tag ('label'); |
661 |
|
$out->nl_text ('Setting innerHTML'); |
662 |
|
$out->text (': '); |
663 |
|
$out->start_tag ('input', name => 'e', |
664 |
|
value => $decode->(scalar $cgi->get_parameter ('e'))); |
665 |
|
$out->end_tag ('label'); |
666 |
|
} |
667 |
|
|
668 |
|
$out->html (q[</div></div>]); |
669 |
|
}; # $options |
670 |
|
|
671 |
|
$out->start_section (id => 'input', title => 'Input'); |
672 |
|
$out->html (q[<script> insertNavSections ('input') </script>]); |
673 |
|
|
674 |
|
$out->start_section (id => 'input-url', title => 'By URL', |
675 |
|
parent_id => 'input'); |
676 |
|
$out->start_tag ('form', action => './#result-summary', |
677 |
|
'accept-charset' => 'utf-8', |
678 |
|
method => 'get'); |
679 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
680 |
|
|
681 |
|
$out->start_tag ('p'); |
682 |
|
$out->start_tag ('label'); |
683 |
|
$out->nl_text ('URL'); |
684 |
|
$out->text (': '); |
685 |
|
$out->start_tag ('input', |
686 |
|
name => 'uri', |
687 |
|
type => 'url', |
688 |
|
value => $decode->(scalar $cgi->get_parameter ('uri'))); |
689 |
|
$out->end_tag ('label'); |
690 |
|
|
691 |
|
$out->start_tag ('p'); |
692 |
|
$out->start_tag ('button', type => 'submit'); |
693 |
|
$out->nl_text ('Check'); |
694 |
|
$out->end_tag ('button'); |
695 |
|
|
696 |
|
$options->('url'); |
697 |
|
|
698 |
|
$out->end_tag ('form'); |
699 |
|
$out->end_section; |
700 |
|
|
701 |
|
## TODO: File upload |
702 |
|
|
703 |
|
$out->start_section (id => 'input-text', title => 'By direct input', |
704 |
|
parent_id => 'input'); |
705 |
|
$out->start_tag ('form', action => './#result-summary', |
706 |
|
'accept-charset' => 'utf-8', |
707 |
|
method => 'post'); |
708 |
|
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
709 |
|
|
710 |
|
$out->start_tag ('p'); |
711 |
|
$out->start_tag ('label'); |
712 |
|
$out->nl_text ('Document source to check'); |
713 |
|
$out->text (': '); |
714 |
|
$out->start_tag ('br'); |
715 |
|
$out->start_tag ('textarea', |
716 |
|
name => 's'); |
717 |
|
my $s = $decode->($cgi->get_parameter ('s')); |
718 |
|
$out->html ($htescape_value->($s)) if defined $s; |
719 |
|
$out->end_tag ('textarea'); |
720 |
|
$out->end_tag ('label'); |
721 |
|
|
722 |
|
$out->start_tag ('p'); |
723 |
|
$out->start_tag ('button', type => 'submit', |
724 |
|
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
725 |
|
$out->nl_text ('Check'); |
726 |
|
$out->end_tag ('button'); |
727 |
|
|
728 |
|
$options->('text'); |
729 |
|
|
730 |
|
$out->end_tag ('form'); |
731 |
|
$out->end_section; |
732 |
|
|
733 |
|
$out->script (q[ |
734 |
|
if (!document.webhaccNavigated && |
735 |
|
document.getElementsByTagName ('textarea')[0].value.length > 0) { |
736 |
|
showTab ('input-text'); |
737 |
|
document.webhaccNavigated = false; |
738 |
|
} |
739 |
|
]); |
740 |
|
|
741 |
|
$out->end_section; |
742 |
|
} # generate_input_section |
743 |
|
|
744 |
sub encode_url_component ($$) { |
sub encode_url_component ($$) { |
745 |
shift; |
shift; |
746 |
require Encode; |
require Encode; |