| 8 |
my $s = $_[0]; |
my $s = $_[0]; |
| 9 |
$s =~ s/&/&/g; |
$s =~ s/&/&/g; |
| 10 |
$s =~ s/</</g; |
$s =~ s/</</g; |
| 11 |
$s =~ s/>/>/g; |
# $s =~ s/>/>/g; |
| 12 |
$s =~ s/"/"/g; |
$s =~ s/"/"/g; |
| 13 |
$s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{ |
# $s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{ |
| 14 |
sprintf '<var>U+%04X</var>', ord $1; |
# sprintf '<var>U+%04X</var>', ord $1; |
| 15 |
}ge; |
# }ge; |
| 16 |
return $s; |
return $s; |
| 17 |
}; |
}; |
| 18 |
|
|
| 20 |
my $s = $_[0]; |
my $s = $_[0]; |
| 21 |
$s =~ s/&/&/g; |
$s =~ s/&/&/g; |
| 22 |
$s =~ s/</</g; |
$s =~ s/</</g; |
| 23 |
$s =~ s/>/>/g; |
# $s =~ s/>/>/g; |
| 24 |
$s =~ s/"/"/g; |
$s =~ s/"/"/g; |
| 25 |
return $s; |
return $s; |
| 26 |
}; |
}; |
| 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 $_[0]->{handle}, ':utf8'; |
| 72 |
} # set_utf8 |
} # set_utf8 |
| 73 |
|
|
| 74 |
sub set_flush ($) { |
sub set_flush ($) { |
| 75 |
shift->{handle}->autoflush (1); |
$_[0]->{handle}->autoflush (1); |
| 76 |
} # set_flush |
} # set_flush |
| 77 |
|
|
| 78 |
sub unset_flush ($) { |
sub unset_flush ($) { |
| 79 |
shift->{handle}->autoflush (0); |
$_[0]->{handle}->autoflush (0); |
| 80 |
} # unset_flush |
} # unset_flush |
| 81 |
|
|
| 82 |
sub html ($$) { |
sub html ($$) { |
| 83 |
shift->{handle}->print (shift); |
$_[0]->{handle}->print ($_[1]); |
| 84 |
} # html |
} # html |
| 85 |
|
|
| 86 |
sub text ($$) { |
sub text ($$) { |
| 87 |
shift->html ($htescape->(shift)); |
$_[0]->{handle}->print ($htescape->($_[1])); |
| 88 |
} # text |
} # text |
| 89 |
|
|
| 90 |
sub url ($$%) { |
sub url ($$%) { |
| 91 |
my ($self, $url, %opt) = @_; |
my ($self, $url, %opt) = @_; |
| 92 |
$self->html (q[<code class=uri><]); |
$self->{handle}->print (q[<code class=uri><]); |
| 93 |
$self->link ($url, %opt, url => $url); |
$self->link ($url, %opt, url => $url); |
| 94 |
$self->html (q[></code>]); |
$self->{handle}->print (q[></code>]); |
| 95 |
} # url |
} # url |
| 96 |
|
|
| 97 |
sub start_tag ($$%) { |
sub start_tag ($$%) { |
| 98 |
my ($self, $tag_name, %opt) = @_; |
my ($self, $tag_name, %opt) = @_; |
| 99 |
$self->html ('<' . $htescape_value->($tag_name)); # escape for safety |
$self->{handle}->print ('<' . $tag_name); |
| 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_value->($id) . '"'); |
$self->{handle}->print (' id="' . $htescape_value->($id) . '"'); |
| 103 |
delete $opt{id}; |
delete $opt{id}; |
| 104 |
} |
} |
| 105 |
for (keys %opt) { # for safety |
for (keys %opt) { |
| 106 |
$self->html (' ' . $htescape_value->($_) . '="' . |
$self->{handle}->print |
| 107 |
$htescape_value->($opt{$_}) . '"'); |
(' ' . $_ . '="' . $htescape_value->($opt{$_}) . '"'); |
| 108 |
} |
} |
| 109 |
$self->html ('>'); |
$self->{handle}->print ('>'); |
| 110 |
} # start_tag |
} # start_tag |
| 111 |
|
|
| 112 |
sub end_tag ($$) { |
sub end_tag ($$) { |
| 113 |
shift->html ('</' . $htescape_value->(shift) . '>'); |
$_[0]->{handle}->print ('</' . $_[1] . '>'); |
| 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 Section'; |
$opt{title} ||= 'Parse Errors Section'; |
| 124 |
$opt{short_title} ||= 'Parse Errors'; |
$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 |
|
$opt{parent_id} ||= $prefix; |
| 179 |
|
my $id = $prefix . $opt{id}; |
| 180 |
$self->html (' id="' . $htescape->($id) . '">'); |
$self->html (' id="' . $htescape->($id) . '">'); |
| 181 |
if ($self->{section_rank} == 2) { |
if ($self->{section_rank} == 2 or length $opt{parent_id}) { |
| 182 |
my $st = $opt{short_title} || $opt{title}; |
my $st = $opt{short_title} || $opt{title}; |
| 183 |
push @{$self->{nav}}, |
push @{$self->{nav}}, |
| 184 |
[$id => $st => $opt{text}]; |
[$id => $st => $opt{text}] if $self->{section_rank} == 2; |
| 185 |
|
|
| 186 |
$self->start_tag ('script'); |
$self->start_tag ('script'); |
| 187 |
$self->html (qq[ addSectionLink ('] . $self->input->id_prefix . |
$self->html (qq[ addSectionLink ('$id', ']); |
|
qq[$id', ']); |
|
| 188 |
$self->nl_text ($st, text => $opt{text}); |
$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[') ]); |
$self->html (q[') ]); |
| 193 |
$self->end_tag ('script'); |
$self->end_tag ('script'); |
| 194 |
} |
} |
| 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 ($$) { |
| 271 |
} # add_source_to_parse_error_list |
} # add_source_to_parse_error_list |
| 272 |
|
|
| 273 |
sub start_code_block ($) { |
sub start_code_block ($) { |
| 274 |
shift->html ('<pre><code>'); |
$_[0]->{handle}->print ('<pre><code>'); |
| 275 |
} # start_code_block |
} # start_code_block |
| 276 |
|
|
| 277 |
sub end_code_block ($) { |
sub end_code_block ($) { |
| 278 |
shift->html ('</code></pre>'); |
$_[0]->{handle}->print ('</code></pre>'); |
| 279 |
} # end_code_block |
} # end_code_block |
| 280 |
|
|
| 281 |
sub code ($$;%) { |
sub code ($$;%) { |
| 282 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
| 283 |
$self->start_tag ('code', %opt); |
$self->start_tag ('code', %opt); |
| 284 |
$self->text ($content); |
$self->text ($content); |
| 285 |
$self->html ('</code>'); |
$self->{handle}->print ('</code>'); |
| 286 |
} # code |
} # code |
| 287 |
|
|
| 288 |
sub script ($$;%) { |
sub script ($$;%) { |
| 289 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
| 290 |
$self->start_tag ('script', %opt); |
$self->start_tag ('script', %opt); |
| 291 |
$self->html ($content); |
$self->{handle}->print ($content . '</script>'); |
|
$self->html ('</script>'); |
|
| 292 |
} # script |
} # script |
| 293 |
|
|
| 294 |
sub dt ($$;%) { |
sub dt ($$;%) { |
| 309 |
while (@options) { |
while (@options) { |
| 310 |
my $opt = shift @options; |
my $opt = shift @options; |
| 311 |
if ($opt->{options}) { |
if ($opt->{options}) { |
| 312 |
$self->html ('<optgroup label="'); |
$self->{handle}->print ('<optgroup label="'); |
| 313 |
$self->nl_text ($opt->{label}); |
$self->nl_text ($opt->{label}); |
| 314 |
$self->html ('">'); |
$self->{handle}->print ('">'); |
| 315 |
unshift @options, @{$opt->{options}}, {end_options => 1}; |
unshift @options, @{$opt->{options}}, {end_options => 1}; |
| 316 |
} elsif ($opt->{end_options}) { |
} elsif ($opt->{end_options}) { |
| 317 |
$self->end_tag ('optgroup'); |
$self->end_tag ('optgroup'); |
| 329 |
sub link ($$%) { |
sub link ($$%) { |
| 330 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
| 331 |
$self->start_tag ('a', %opt, href => $opt{url}); |
$self->start_tag ('a', %opt, href => $opt{url}); |
| 332 |
$self->text ($content); |
$self->{handle}->print ($htescape->($content) . '</a>'); |
|
$self->html ('</a>'); |
|
| 333 |
} # link |
} # link |
| 334 |
|
|
| 335 |
sub xref ($$%) { |
sub xref ($$%) { |
| 336 |
my ($self, $content, %opt) = @_; |
my ($self, $content, %opt) = @_; |
| 337 |
$self->html ('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">'); |
$self->{handle}->print |
| 338 |
|
('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">'); |
| 339 |
$self->nl_text ($content, text => $opt{text}); |
$self->nl_text ($content, text => $opt{text}); |
| 340 |
$self->html ('</a>'); |
$self->{handle}->print ('</a>'); |
| 341 |
|
} # xref |
| 342 |
|
|
| 343 |
|
sub xref_text ($$%) { |
| 344 |
|
my ($self, $content, %opt) = @_; |
| 345 |
|
$self->html ('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">'); |
| 346 |
|
$self->{handle}->print ($htescape->($content) . '</a>'); |
| 347 |
} # xref |
} # xref |
| 348 |
|
|
| 349 |
sub link_to_webhacc ($$%) { |
sub link_to_webhacc ($$%) { |
| 399 |
sub node_link ($$) { |
sub node_link ($$) { |
| 400 |
my ($self, $node) = @_; |
my ($self, $node) = @_; |
| 401 |
if ($node->isa ('Message::IF::Node')) { |
if ($node->isa ('Message::IF::Node')) { |
| 402 |
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
$self->xref_text ($get_node_path->($node), |
| 403 |
|
target => 'node-' . refaddr $node); |
| 404 |
} else { |
} else { |
| 405 |
$self->html ($get_object_path->($node)); |
$self->{handle}->print ($get_object_path->($node)); |
| 406 |
} |
} |
| 407 |
} # node_link |
} # node_link |
| 408 |
|
|
| 431 |
my ($self, $type, %opt) = @_; |
my ($self, $type, %opt) = @_; |
| 432 |
my $node = $opt{node}; |
my $node = $opt{node}; |
| 433 |
|
|
| 434 |
my @arg; |
if (defined $Msg->{$type}) { |
| 435 |
{ |
my $msg = $Msg->{$type}->[1]; |
| 436 |
if (defined $Msg->{$type}) { |
if ($msg =~ /<var>/) { |
| 437 |
my $msg = $Msg->{$type}->[1]; |
$msg =~ s{<var>{\@([A-Za-z0-9:_.-]+)}</var>}{ |
| 438 |
if ($msg =~ /<var>/) { |
UNIVERSAL::can ($node, 'get_attribute_ns') |
| 439 |
$msg =~ s{<var>\$([0-9]+)</var>}{ |
? $htescape->($node->get_attribute_ns (undef, $1)) : '' |
| 440 |
defined $arg[$1] ? $htescape->($arg[$1]) : '(undef)'; |
}ge; |
| 441 |
}ge; |
$msg =~ s{<var>{\@}</var>}{ |
| 442 |
$msg =~ s{<var>{\@([A-Za-z0-9:_.-]+)}</var>}{ |
UNIVERSAL::can ($node, 'value') ? $htescape->($node->value) : '' |
| 443 |
UNIVERSAL::can ($node, 'get_attribute_ns') |
}ge; |
| 444 |
? $htescape->($node->get_attribute_ns (undef, $1)) : '' |
$msg =~ s{<var>{text}</var>}{ |
| 445 |
}ge; |
defined $opt{text} ? $htescape->($opt{text}) : '' |
| 446 |
$msg =~ s{<var>{\@}</var>}{ |
}ge; |
| 447 |
UNIVERSAL::can ($node, 'value') ? $htescape->($node->value) : '' |
$msg =~ s{<var>{value}</var>}{ |
| 448 |
}ge; |
defined $opt{value} ? $htescape->($opt{value}) : '' |
| 449 |
$msg =~ s{<var>{text}</var>}{ |
}ge; |
| 450 |
defined $opt{text} ? $htescape->($opt{text}) : '' |
$msg =~ s{<var>{octets}</var>}{ |
| 451 |
}ge; |
if (defined $opt{octets}) { |
| 452 |
$msg =~ s{<var>{local-name}</var>}{ |
join ', ', map {sprintf '0x%02X', ord $_} split //, ${$opt{octets}}; |
| 453 |
UNIVERSAL::can ($node, 'manakai_local_name') |
} else { |
| 454 |
|
''; |
| 455 |
|
} |
| 456 |
|
}ge; |
| 457 |
|
$msg =~ s{<var>{char}</var>}{ |
| 458 |
|
defined $opt{char} ? $htescape->(${$opt{char}}) : '' |
| 459 |
|
}ge; |
| 460 |
|
$msg =~ s{<var>{char:hexref}</var>}{ |
| 461 |
|
if (defined $opt{char}) { |
| 462 |
|
join '', map {sprintf '&#x%02X;', ord $_} split //, ${$opt{char}}; |
| 463 |
|
} else { |
| 464 |
|
''; |
| 465 |
|
} |
| 466 |
|
}ge; |
| 467 |
|
$msg =~ s{<var>{local-name}</var>}{ |
| 468 |
|
UNIVERSAL::can ($node, 'manakai_local_name') |
| 469 |
? $htescape->($node->manakai_local_name) : '' |
? $htescape->($node->manakai_local_name) : '' |
| 470 |
}ge; |
}ge; |
| 471 |
$msg =~ s{<var>{element-local-name}</var>}{ |
$msg =~ s{<var>{element-local-name}</var>}{ |
| 472 |
(UNIVERSAL::can ($node, 'owner_element') and |
(UNIVERSAL::can ($node, 'owner_element') and $node->owner_element) |
|
$node->owner_element) |
|
| 473 |
? $htescape->($node->owner_element->manakai_local_name) : '' |
? $htescape->($node->owner_element->manakai_local_name) : '' |
| 474 |
}ge; |
}ge; |
|
} |
|
|
$self->html ($msg); |
|
|
return; |
|
|
} elsif ($type =~ s/:([^:]*)$//) { |
|
|
unshift @arg, $1; |
|
|
redo; |
|
| 475 |
} |
} |
| 476 |
|
$self->{handle}->print ($msg); |
| 477 |
|
} else { |
| 478 |
|
$self->{handle}->print ($htescape->($type)); |
| 479 |
} |
} |
|
$self->text ($type); |
|
| 480 |
} # nl_text |
} # nl_text |
| 481 |
|
|
| 482 |
} |
} |
| 483 |
|
|
| 484 |
sub nav_list ($) { |
sub nav_list ($) { |
| 485 |
my $self = shift; |
# my $self = shift; |
| 486 |
$self->html (q[<ul class="navigation" id="nav-items">]); |
# $self->html (q[<ul class="navigation" id="nav-items">]); |
| 487 |
for (@{$self->{nav}}) { |
# for (@{$self->{nav}}) { |
| 488 |
$self->html (qq[<li><a href="#@{[$htescape->($_->[0])]}">]); |
# $self->html (qq[<li><a href="#@{[$htescape->($_->[0])]}">]); |
| 489 |
$self->nl_text ($_->[1], text => $_->[2]); |
# $self->nl_text ($_->[1], text => $_->[2]); |
| 490 |
$self->html ('</a>'); |
# $self->html ('</a>'); |
| 491 |
} |
# } |
| 492 |
$self->html ('</ul>'); |
# $self->html ('</ul>'); |
| 493 |
} # nav_list |
} # nav_list |
| 494 |
|
|
| 495 |
sub http_header ($) { |
sub http_header ($) { |
| 496 |
shift->html (qq[Content-Type: text/html; charset=utf-8\n\n]); |
$_[0]->{handle}->print (qq[Content-Type: text/html; charset=utf-8\n\n]); |
| 497 |
} # http_header |
} # http_header |
| 498 |
|
|
| 499 |
sub http_error ($$) { |
sub http_error ($$) { |
| 502 |
my $text = { |
my $text = { |
| 503 |
404 => 'Not Found', |
404 => 'Not Found', |
| 504 |
}->{$code}; |
}->{$code}; |
| 505 |
$self->html (qq[Status: $code $text\nContent-Type: text/html ; charset=us-ascii\n\n$code $text]); |
$self->{handle}->print |
| 506 |
|
(qq[Status: $code $text\nContent-Type: text/html ; charset=us-ascii\n\n$code $text]); |
| 507 |
} # http_error |
} # http_error |
| 508 |
|
|
| 509 |
sub html_header ($) { |
sub html_header ($) { |
| 510 |
my $self = shift; |
my $self = shift; |
| 511 |
$self->html (q[<!DOCTYPE html>]); |
$self->{handle}->print (q[<!DOCTYPE html>]); |
| 512 |
$self->start_tag ('html', lang => $self->{primary_language}); |
$self->start_tag ('html', lang => $self->{primary_language}); |
| 513 |
$self->html (q[<head><title>]); |
$self->{handle}->print (q[<head><title>]); |
| 514 |
$self->nl_text (q[WebHACC:Title]); |
$self->nl_text (q[WebHACC:Title]); |
| 515 |
$self->html (q[</title> |
$self->{handle}->print (q[</title> |
| 516 |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
| 517 |
<script src="../cc-script.js"></script> |
<script src="../cc-script.js"></script> |
| 518 |
</head> |
</head> |
| 519 |
<body onclick=" return onbodyclick (event) " onload=" onbodyload () "> |
<body onclick=" return onbodyclick (event) " onload=" onbodyload () "> |
| 520 |
<h1>]); |
<h1>]); |
| 521 |
$self->nl_text (q[WebHACC:Heading]); |
$self->nl_text (q[WebHACC:Heading]); |
| 522 |
$self->html (q[</h1><script> insertNavSections () </script>]); |
$self->{handle}->print (q[</h1><script> insertNavSections () </script>]); |
| 523 |
} # html_header |
} # html_header |
| 524 |
|
|
| 525 |
sub generate_input_section ($$) { |
sub generate_input_section ($$) { |
| 526 |
my ($out, $cgi) = @_; |
my ($out, $cgi) = @_; |
| 527 |
|
|
| 528 |
|
require Encode; |
| 529 |
|
my $decode = sub ($) { |
| 530 |
|
if (defined $_[0]) { |
| 531 |
|
return Encode::decode ('utf-8', $_[0]); |
| 532 |
|
} else { |
| 533 |
|
return undef; |
| 534 |
|
} |
| 535 |
|
}; # $decode |
| 536 |
|
|
| 537 |
my $options = sub ($) { |
my $options = sub ($) { |
| 538 |
my $context = shift; |
my $context = shift; |
| 539 |
|
|
| 540 |
$out->html (q[<div class=details><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'none' ? 'block' : 'none'">]); |
$out->{handle}->print (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'" tabindex=0>]); |
| 541 |
$out->nl_text (q[Options]); |
$out->nl_text (q[Options]); |
| 542 |
$out->start_tag ('div'); |
$out->start_tag ('div'); |
| 543 |
|
|
| 559 |
$out->select ([ |
$out->select ([ |
| 560 |
{value => '', label => 'As specified'}, |
{value => '', label => 'As specified'}, |
| 561 |
{value => 'application/atom+xml'}, |
{value => 'application/atom+xml'}, |
| 562 |
|
{value => 'text/cache-manifest'}, |
| 563 |
|
{value => 'text/css'}, |
| 564 |
|
{value => 'text/x-css-inline'}, |
| 565 |
|
{value => 'text/x-h2h'}, |
| 566 |
|
{value => 'text/html'}, |
| 567 |
|
{value => 'text/x-regexp-js'}, |
| 568 |
|
{value => 'text/x-webidl'}, |
| 569 |
{value => 'application/xhtml+xml'}, |
{value => 'application/xhtml+xml'}, |
| 570 |
{value => 'application/xml'}, |
{value => 'application/xml'}, |
|
{value => 'text/html'}, |
|
| 571 |
{value => 'text/xml'}, |
{value => 'text/xml'}, |
|
{value => 'text/css'}, |
|
|
{value => 'text/cache-manifest'}, |
|
|
{value => 'text/x-webidl'}, |
|
| 572 |
], name => 'i', selected => scalar $cgi->get_parameter ('i')); |
], name => 'i', selected => scalar $cgi->get_parameter ('i')); |
| 573 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 574 |
|
|
| 582 |
{label => 'Japanese charsets', options => [ |
{label => 'Japanese charsets', options => [ |
| 583 |
{value => 'Windows-31J'}, |
{value => 'Windows-31J'}, |
| 584 |
{value => 'Shift_JIS'}, |
{value => 'Shift_JIS'}, |
| 585 |
|
{value => 'x-sjis'}, |
| 586 |
{value => 'EUC-JP'}, |
{value => 'EUC-JP'}, |
| 587 |
|
{value => 'x-euc-jp'}, |
| 588 |
{value => 'ISO-2022-JP'}, |
{value => 'ISO-2022-JP'}, |
| 589 |
|
{value => 'ISO-2022-JP-1'}, |
| 590 |
|
{value => 'ISO-2022-JP-2'}, |
| 591 |
]}, |
]}, |
| 592 |
{label => 'European charsets', options => [ |
{label => 'Latin charsets', options => [ |
| 593 |
|
{value => 'Windows-1250'}, |
| 594 |
{value => 'Windows-1252'}, |
{value => 'Windows-1252'}, |
| 595 |
|
{value => 'Windows-1254'}, |
| 596 |
|
{value => 'Windows-1257'}, |
| 597 |
|
{value => 'Windows-1258'}, |
| 598 |
{value => 'ISO-8859-1'}, |
{value => 'ISO-8859-1'}, |
| 599 |
|
{value => 'ISO-8859-2'}, |
| 600 |
|
{value => 'ISO-8859-3'}, |
| 601 |
|
{value => 'ISO-8859-4'}, |
| 602 |
|
{value => 'ISO-8859-9'}, |
| 603 |
|
{value => 'ISO-8859-10'}, |
| 604 |
|
{value => 'ISO-8859-13'}, |
| 605 |
|
{value => 'ISO-8859-14'}, |
| 606 |
|
{value => 'ISO-8859-15'}, |
| 607 |
|
{value => 'ISO-8859-16'}, |
| 608 |
{value => 'US-ASCII'}, |
{value => 'US-ASCII'}, |
| 609 |
]}, |
]}, |
| 610 |
{label => 'Asian charsets', options => [ |
{label => 'Greek charsets', options => [ |
| 611 |
|
{value => 'Windows-1253'}, |
| 612 |
|
{value => 'ISO-8859-7'}, |
| 613 |
|
]}, |
| 614 |
|
{label => 'Cyrillic charsets', options => [ |
| 615 |
|
{value => 'Windows-1251'}, |
| 616 |
|
{value => 'ISO-8859-5'}, |
| 617 |
|
]}, |
| 618 |
|
{label => 'Arabic charsets', options => [ |
| 619 |
|
{value => 'Windows-1256'}, |
| 620 |
|
{value => 'ISO-8859-6'}, |
| 621 |
|
]}, |
| 622 |
|
{label => 'Hebrew charsets', options => [ |
| 623 |
|
{value => 'Windows-1255'}, |
| 624 |
|
{value => 'ISO-8859-8'}, |
| 625 |
|
]}, |
| 626 |
|
{label => 'Thai charsets', options => [ |
| 627 |
{value => 'Windows-874'}, |
{value => 'Windows-874'}, |
| 628 |
{value => 'ISO-8859-11'}, |
{value => 'ISO-8859-11'}, |
| 629 |
{value => 'TIS-620'}, |
{value => 'TIS-620'}, |
| 630 |
]}, |
]}, |
| 631 |
|
{label => 'Chinese charsets', options => [ |
| 632 |
|
{value => 'Big5'}, |
| 633 |
|
{value => 'x-x-big5'}, |
| 634 |
|
{value => 'Big5-HKSCS'}, |
| 635 |
|
{value => 'GBK'}, |
| 636 |
|
{value => 'GB2312'}, |
| 637 |
|
{value => 'GB_2312-80'}, |
| 638 |
|
{value => 'ISO-2022-CN'}, |
| 639 |
|
{value => 'ISO-2022-CN-EXT'}, |
| 640 |
|
]}, |
| 641 |
|
{label => 'Korean charsets', options => [ |
| 642 |
|
{value => 'Windows-949'}, |
| 643 |
|
{value => 'EUC-KR'}, |
| 644 |
|
{value => 'KS_C_5601-1987'}, |
| 645 |
|
{value => 'ISO-2022-KR'}, |
| 646 |
|
]}, |
| 647 |
{label => 'Unicode charsets', options => [ |
{label => 'Unicode charsets', options => [ |
| 648 |
{value => 'UTF-8'}, |
{value => 'UTF-8'}, |
| 649 |
{value => 'UTF-8n'}, |
{value => 'UTF-8n'}, |
| 650 |
]}, |
{value => 'UTF-16'}, |
| 651 |
|
{value => 'UTF-16BE'}, |
| 652 |
|
{value => 'UTF-16LE'}, |
| 653 |
|
]}, |
| 654 |
], name => 'charset', |
], name => 'charset', |
| 655 |
selected => scalar $cgi->get_parameter ('charset')); |
selected => scalar $cgi->get_parameter ('charset')); |
| 656 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 662 |
$out->nl_text ('Setting innerHTML'); |
$out->nl_text ('Setting innerHTML'); |
| 663 |
$out->text (': '); |
$out->text (': '); |
| 664 |
$out->start_tag ('input', name => 'e', |
$out->start_tag ('input', name => 'e', |
| 665 |
value => scalar $cgi->get_parameter ('e')); |
value => $decode->(scalar $cgi->get_parameter ('e'))); |
| 666 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 667 |
} |
} |
| 668 |
|
|
| 669 |
$out->html (q[</div></div>]); |
$out->{handle}->print (q[</div></div>]); |
| 670 |
}; # $options |
}; # $options |
| 671 |
|
|
| 672 |
$out->start_section (id => 'input', title => 'Input'); |
$out->start_section (id => 'input', title => 'Input'); |
| 673 |
|
$out->html (q[<script> insertNavSections ('input') </script>]); |
| 674 |
|
|
| 675 |
$out->start_section (id => 'input-url', title => 'By URL'); |
$out->start_section (id => 'input-url', title => 'By URL', |
| 676 |
|
parent_id => 'input'); |
| 677 |
$out->start_tag ('form', action => './#result-summary', |
$out->start_tag ('form', action => './#result-summary', |
| 678 |
'accept-charset' => 'utf-8', |
'accept-charset' => 'utf-8', |
| 679 |
method => 'get'); |
method => 'get'); |
| 686 |
$out->start_tag ('input', |
$out->start_tag ('input', |
| 687 |
name => 'uri', |
name => 'uri', |
| 688 |
type => 'url', |
type => 'url', |
| 689 |
value => $cgi->get_parameter ('uri')); |
value => $decode->(scalar $cgi->get_parameter ('uri'))); |
| 690 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 691 |
|
|
|
$options->('url'); |
|
|
|
|
| 692 |
$out->start_tag ('p'); |
$out->start_tag ('p'); |
| 693 |
$out->start_tag ('button', type => 'submit'); |
$out->start_tag ('button', type => 'submit'); |
| 694 |
$out->nl_text ('Check'); |
$out->nl_text ('Check'); |
| 695 |
|
$out->end_tag ('button'); |
| 696 |
|
|
| 697 |
|
$options->('url'); |
| 698 |
|
|
| 699 |
$out->end_tag ('form'); |
$out->end_tag ('form'); |
| 700 |
$out->end_section; |
$out->end_section; |
| 701 |
|
|
|
$out->end_tag ('fieldset'); |
|
|
|
|
| 702 |
## TODO: File upload |
## TODO: File upload |
| 703 |
|
|
| 704 |
$out->start_section (id => 'input-text', title => 'By direct input'); |
$out->start_section (id => 'input-text', title => 'By direct input', |
| 705 |
|
parent_id => 'input'); |
| 706 |
$out->start_tag ('form', action => './#result-summary', |
$out->start_tag ('form', action => './#result-summary', |
| 707 |
'accept-charset' => 'utf-8', |
'accept-charset' => 'utf-8', |
| 708 |
method => 'post'); |
method => 'post'); |
| 715 |
$out->start_tag ('br'); |
$out->start_tag ('br'); |
| 716 |
$out->start_tag ('textarea', |
$out->start_tag ('textarea', |
| 717 |
name => 's'); |
name => 's'); |
| 718 |
my $s = $cgi->get_parameter ('s'); |
my $s = $decode->($cgi->get_parameter ('s')); |
| 719 |
$out->html ($htescape_value->($s)) if defined $s; |
$out->html ($htescape_value->($s)) if defined $s; |
| 720 |
$out->end_tag ('textarea'); |
$out->end_tag ('textarea'); |
| 721 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 722 |
|
|
|
$options->('text'); |
|
|
|
|
| 723 |
$out->start_tag ('p'); |
$out->start_tag ('p'); |
| 724 |
$out->start_tag ('button', type => 'submit', |
$out->start_tag ('button', type => 'submit', |
| 725 |
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
| 726 |
$out->nl_text ('Check'); |
$out->nl_text ('Check'); |
| 727 |
$out->end_tag ('button'); |
$out->end_tag ('button'); |
| 728 |
|
|
| 729 |
|
$options->('text'); |
| 730 |
|
|
| 731 |
$out->end_tag ('form'); |
$out->end_tag ('form'); |
| 732 |
$out->end_section; |
$out->end_section; |
| 733 |
|
|
| 734 |
|
$out->script (q[ |
| 735 |
|
if (!document.webhaccNavigated && |
| 736 |
|
document.getElementsByTagName ('textarea')[0].value.length > 0) { |
| 737 |
|
showTab ('input-text'); |
| 738 |
|
document.webhaccNavigated = false; |
| 739 |
|
} |
| 740 |
|
]); |
| 741 |
|
|
| 742 |
$out->end_section; |
$out->end_section; |
| 743 |
} # generate_input_section |
} # generate_input_section |
| 744 |
|
|