| 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 |
require WebHACC::Input; |
require WebHACC::Input; |
| 30 |
return bless {nav => [], section_rank => 1, |
return bless {nav => [], section_rank => 1, |
| 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 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 |
$self->html (' id="' . $htescape->($id) . '"'); |
$opt{parent_id} ||= $prefix; |
| 179 |
push @{$self->{nav}}, |
my $id = $prefix . $opt{id}; |
| 180 |
[$id => $opt{short_title} || $opt{title} => $opt{text}] |
$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}; |
| 183 |
|
push @{$self->{nav}}, |
| 184 |
|
[$id => $st => $opt{text}]; |
| 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 |
$self->nl_text ($opt{title}, text => $opt{text}); |
$self->nl_text ($opt{title}, text => $opt{text}); |
| 202 |
$self->html ('</h' . $section_rank . '>'); |
$self->html ('</h' . $section_rank . '>'); |
| 203 |
} # start_section |
} # start_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 ($$) { |
| 374 |
return join '/', @r; |
return join '/', @r; |
| 375 |
}; # $get_node_path |
}; # $get_node_path |
| 376 |
|
|
| 377 |
|
my $get_object_path = sub ($) { |
| 378 |
|
my $node = shift; |
| 379 |
|
my @r; |
| 380 |
|
while (defined $node) { |
| 381 |
|
my $ref = ref $node; |
| 382 |
|
$ref =~ /([^:]+)$/; |
| 383 |
|
my $rs = $1; |
| 384 |
|
my $node_name = $node->node_name; |
| 385 |
|
if (defined $node_name) { |
| 386 |
|
$rs .= ' <code>' . $htescape->($node_name) . '</code>'; |
| 387 |
|
} |
| 388 |
|
$node = undef; |
| 389 |
|
unshift @r, $rs; |
| 390 |
|
} |
| 391 |
|
return join '/', @r; |
| 392 |
|
}; # $get_object_path |
| 393 |
|
|
| 394 |
sub node_link ($$) { |
sub node_link ($$) { |
| 395 |
my ($self, $node) = @_; |
my ($self, $node) = @_; |
| 396 |
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
if ($node->isa ('Message::IF::Node')) { |
| 397 |
|
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
| 398 |
|
} else { |
| 399 |
|
$self->html ($get_object_path->($node)); |
| 400 |
|
} |
| 401 |
} # node_link |
} # node_link |
| 402 |
|
|
| 403 |
{ |
{ |
| 443 |
$msg =~ s{<var>{text}</var>}{ |
$msg =~ s{<var>{text}</var>}{ |
| 444 |
defined $opt{text} ? $htescape->($opt{text}) : '' |
defined $opt{text} ? $htescape->($opt{text}) : '' |
| 445 |
}ge; |
}ge; |
| 446 |
|
$msg =~ s{<var>{value}</var>}{ |
| 447 |
|
defined $opt{value} ? $htescape->($opt{value}) : '' |
| 448 |
|
}ge; |
| 449 |
$msg =~ s{<var>{local-name}</var>}{ |
$msg =~ s{<var>{local-name}</var>}{ |
| 450 |
UNIVERSAL::can ($node, 'manakai_local_name') |
UNIVERSAL::can ($node, 'manakai_local_name') |
| 451 |
? $htescape->($node->manakai_local_name) : '' |
? $htescape->($node->manakai_local_name) : '' |
| 502 |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
| 503 |
<script src="../cc-script.js"></script> |
<script src="../cc-script.js"></script> |
| 504 |
</head> |
</head> |
| 505 |
<body> |
<body onclick=" return onbodyclick (event) " onload=" onbodyload () "> |
| 506 |
<h1>]); |
<h1>]); |
| 507 |
$self->nl_text (q[WebHACC:Heading]); |
$self->nl_text (q[WebHACC:Heading]); |
| 508 |
$self->html ('</h1>'); |
$self->html (q[</h1><script> insertNavSections () </script>]); |
| 509 |
} # html_header |
} # html_header |
| 510 |
|
|
| 511 |
sub generate_input_section ($$) { |
sub generate_input_section ($$) { |
| 512 |
my ($out, $cgi) = @_; |
my ($out, $cgi) = @_; |
| 513 |
|
|
| 514 |
|
require Encode; |
| 515 |
|
my $decode = sub ($) { |
| 516 |
|
if (defined $_[0]) { |
| 517 |
|
return Encode::decode ('utf-8', $_[0]); |
| 518 |
|
} else { |
| 519 |
|
return undef; |
| 520 |
|
} |
| 521 |
|
}; # $decode |
| 522 |
|
|
| 523 |
my $options = sub ($) { |
my $options = sub ($) { |
| 524 |
my $context = shift; |
my $context = shift; |
| 525 |
|
|
| 526 |
$out->html (q[<div class=details><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'none' ? 'block' : 'none'">]); |
$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'">]); |
| 527 |
$out->nl_text (q[Options]); |
$out->nl_text (q[Options]); |
| 528 |
$out->start_tag ('div'); |
$out->start_tag ('div'); |
| 529 |
|
|
| 593 |
$out->nl_text ('Setting innerHTML'); |
$out->nl_text ('Setting innerHTML'); |
| 594 |
$out->text (': '); |
$out->text (': '); |
| 595 |
$out->start_tag ('input', name => 'e', |
$out->start_tag ('input', name => 'e', |
| 596 |
value => scalar $cgi->get_parameter ('e')); |
value => $decode->(scalar $cgi->get_parameter ('e'))); |
| 597 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 598 |
} |
} |
| 599 |
|
|
| 601 |
}; # $options |
}; # $options |
| 602 |
|
|
| 603 |
$out->start_section (id => 'input', title => 'Input'); |
$out->start_section (id => 'input', title => 'Input'); |
| 604 |
|
$out->html (q[<script> insertNavSections ('input') </script>]); |
| 605 |
|
|
| 606 |
$out->start_section (id => 'input-url', title => 'By URL'); |
$out->start_section (id => 'input-url', title => 'By URL', |
| 607 |
$out->start_tag ('form', action => './', 'accept-charset' => 'utf-8', |
parent_id => 'input'); |
| 608 |
|
$out->start_tag ('form', action => './#result-summary', |
| 609 |
|
'accept-charset' => 'utf-8', |
| 610 |
method => 'get'); |
method => 'get'); |
| 611 |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
| 612 |
|
|
| 617 |
$out->start_tag ('input', |
$out->start_tag ('input', |
| 618 |
name => 'uri', |
name => 'uri', |
| 619 |
type => 'url', |
type => 'url', |
| 620 |
value => $cgi->get_parameter ('uri')); |
value => $decode->(scalar $cgi->get_parameter ('uri'))); |
| 621 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 622 |
|
|
|
$options->('url'); |
|
|
|
|
| 623 |
$out->start_tag ('p'); |
$out->start_tag ('p'); |
| 624 |
$out->start_tag ('button', type => 'submit'); |
$out->start_tag ('button', type => 'submit'); |
| 625 |
$out->nl_text ('Check'); |
$out->nl_text ('Check'); |
| 626 |
|
$out->end_tag ('button'); |
| 627 |
|
|
| 628 |
|
$options->('url'); |
| 629 |
|
|
| 630 |
$out->end_tag ('form'); |
$out->end_tag ('form'); |
| 631 |
$out->end_section; |
$out->end_section; |
| 632 |
|
|
|
$out->end_tag ('fieldset'); |
|
|
|
|
| 633 |
## TODO: File upload |
## TODO: File upload |
| 634 |
|
|
| 635 |
$out->start_section (id => 'input-text', title => 'By direct input'); |
$out->start_section (id => 'input-text', title => 'By direct input', |
| 636 |
$out->start_tag ('form', action => './', 'accept-charset' => 'utf-8', |
parent_id => 'input'); |
| 637 |
|
$out->start_tag ('form', action => './#result-summary', |
| 638 |
|
'accept-charset' => 'utf-8', |
| 639 |
method => 'post'); |
method => 'post'); |
| 640 |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
| 641 |
|
|
| 646 |
$out->start_tag ('br'); |
$out->start_tag ('br'); |
| 647 |
$out->start_tag ('textarea', |
$out->start_tag ('textarea', |
| 648 |
name => 's'); |
name => 's'); |
| 649 |
my $s = $cgi->get_parameter ('s'); |
my $s = $decode->($cgi->get_parameter ('s')); |
| 650 |
$out->text ($s) if defined $s; |
$out->html ($htescape_value->($s)) if defined $s; |
| 651 |
$out->end_tag ('textarea'); |
$out->end_tag ('textarea'); |
| 652 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
| 653 |
|
|
|
$options->('text'); |
|
|
|
|
| 654 |
$out->start_tag ('p'); |
$out->start_tag ('p'); |
| 655 |
$out->start_tag ('button', type => 'submit', |
$out->start_tag ('button', type => 'submit', |
| 656 |
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
| 657 |
$out->nl_text ('Check'); |
$out->nl_text ('Check'); |
| 658 |
$out->end_tag ('button'); |
$out->end_tag ('button'); |
| 659 |
|
|
| 660 |
|
$options->('text'); |
| 661 |
|
|
| 662 |
$out->end_tag ('form'); |
$out->end_tag ('form'); |
| 663 |
$out->end_section; |
$out->end_section; |
| 664 |
|
|
| 665 |
|
$out->script (q[ |
| 666 |
|
if (!document.webhaccNavigated && |
| 667 |
|
document.getElementsByTagName ('textarea')[0].value.length > 0) { |
| 668 |
|
showTab ('input-text'); |
| 669 |
|
document.webhaccNavigated = false; |
| 670 |
|
} |
| 671 |
|
]); |
| 672 |
|
|
| 673 |
$out->end_section; |
$out->end_section; |
| 674 |
} # generate_input_section |
} # generate_input_section |
| 675 |
|
|