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, |
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 ($%) { |
105 |
my ($self, %opt) = @_; |
my ($self, %opt) = @_; |
106 |
|
|
107 |
|
my $class = 'section'; |
108 |
if (defined $opt{role}) { |
if (defined $opt{role}) { |
109 |
if ($opt{role} eq 'parse-errors') { |
if ($opt{role} eq 'parse-errors') { |
110 |
$opt{id} ||= 'parse-errors'; |
$opt{id} ||= 'parse-errors'; |
111 |
$opt{title} ||= 'Parse Errors Section'; |
$opt{title} ||= 'Parse Errors Section'; |
112 |
$opt{short_title} ||= 'Parse Errors'; |
$opt{short_title} ||= 'Parse Errors'; |
113 |
|
$class .= ' errors'; |
114 |
delete $opt{role}; |
delete $opt{role}; |
115 |
} elsif ($opt{role} eq 'structure-errors') { |
} elsif ($opt{role} eq 'structure-errors') { |
116 |
$opt{id} ||= 'document-errors'; |
$opt{id} ||= 'document-errors'; |
117 |
$opt{title} ||= 'Structural Errors'; |
$opt{title} ||= 'Structural Errors'; |
118 |
$opt{short_title} ||= 'Struct. Errors'; |
$opt{short_title} ||= 'Struct. Errors'; |
119 |
|
$class .= ' errors'; |
120 |
|
delete $opt{role}; |
121 |
|
} elsif ($opt{role} eq 'transfer-errors') { |
122 |
|
$opt{id} ||= 'transfer-errors'; |
123 |
|
$opt{title} ||= 'Transfer Errors'; |
124 |
|
$opt{short_title} ||= 'Trans. Errors'; |
125 |
|
$class .= ' errors'; |
126 |
delete $opt{role}; |
delete $opt{role}; |
127 |
} elsif ($opt{role} eq 'reformatted') { |
} elsif ($opt{role} eq 'reformatted') { |
128 |
$opt{id} ||= 'document-tree'; |
$opt{id} ||= 'document-tree'; |
129 |
$opt{title} ||= 'Reformatted Document Source'; |
$opt{title} ||= 'Reformatted Document Source'; |
130 |
$opt{short_title} ||= 'Reformatted'; |
$opt{short_title} ||= 'Reformatted'; |
131 |
|
$class .= ' dump'; |
132 |
delete $opt{role} |
delete $opt{role} |
133 |
} elsif ($opt{role} eq 'tree') { |
} elsif ($opt{role} eq 'tree') { |
134 |
$opt{id} ||= 'document-tree'; |
$opt{id} ||= 'document-tree'; |
135 |
$opt{title} ||= 'Document Tree'; |
$opt{title} ||= 'Document Tree'; |
136 |
$opt{short_title} ||= 'Tree'; |
$opt{short_title} ||= 'Tree'; |
137 |
|
$class .= ' dump'; |
138 |
delete $opt{role}; |
delete $opt{role}; |
139 |
} elsif ($opt{role} eq 'structure') { |
} elsif ($opt{role} eq 'structure') { |
140 |
$opt{id} ||= 'document-structure'; |
$opt{id} ||= 'document-structure'; |
141 |
$opt{title} ||= 'Document Structure'; |
$opt{title} ||= 'Document Structure'; |
142 |
$opt{short_title} ||= 'Structure'; |
$opt{short_title} ||= 'Structure'; |
143 |
|
$class .= ' dump'; |
144 |
|
delete $opt{role}; |
145 |
|
} elsif ($opt{role} eq 'subdoc') { |
146 |
|
$class .= ' subdoc'; |
147 |
|
delete $opt{role}; |
148 |
|
} elsif ($opt{role} eq 'source') { |
149 |
|
$opt{id} ||= 'source-string'; |
150 |
|
$opt{title} ||= 'Document Source'; |
151 |
|
$opt{short_title} ||= 'Source'; |
152 |
|
$class .= ' source'; |
153 |
|
delete $opt{role}; |
154 |
|
} elsif ($opt{role} eq 'result') { |
155 |
|
$opt{id} ||= 'result-summary'; |
156 |
|
$opt{title} ||= 'Result'; |
157 |
|
$class .= ' result'; |
158 |
delete $opt{role}; |
delete $opt{role}; |
159 |
} |
} |
160 |
} |
} |
161 |
|
|
162 |
$self->{section_rank}++; |
$self->{section_rank}++; |
163 |
$self->html ('<div class=section'); |
$self->html (qq[<div class="$class"]); |
164 |
if (defined $opt{id}) { |
if (defined $opt{id}) { |
165 |
my $id = $self->input->id_prefix . $opt{id}; |
my $prefix = $self->input->id_prefix; |
166 |
$self->html (' id="' . $htescape->($id) . '"'); |
$opt{parent_id} ||= $prefix; |
167 |
push @{$self->{nav}}, |
my $id = $prefix . $opt{id}; |
168 |
[$id => $opt{short_title} || $opt{title} => $opt{text}] |
$self->html (' id="' . $htescape->($id) . '">'); |
169 |
if $self->{section_rank} == 2; |
if ($self->{section_rank} == 2 or length $opt{parent_id}) { |
170 |
|
my $st = $opt{short_title} || $opt{title}; |
171 |
|
push @{$self->{nav}}, |
172 |
|
[$id => $st => $opt{text}]; |
173 |
|
|
174 |
|
$self->start_tag ('script'); |
175 |
|
$self->html (qq[ addSectionLink ('$id', ']); |
176 |
|
$self->nl_text ($st, text => $opt{text}); |
177 |
|
if (defined $opt{parent_id}) { |
178 |
|
$self->html (q[', '] . $opt{parent_id}); |
179 |
|
} |
180 |
|
$self->html (q[') ]); |
181 |
|
$self->end_tag ('script'); |
182 |
|
} |
183 |
|
} else { |
184 |
|
$self->html ('>'); |
185 |
} |
} |
186 |
my $section_rank = $self->{section_rank}; |
my $section_rank = $self->{section_rank}; |
187 |
$section_rank = 6 if $section_rank > 6; |
$section_rank = 6 if $section_rank > 6; |
188 |
$self->html ('><h' . $section_rank . '>'); |
$self->html ('<h' . $section_rank . '>'); |
189 |
$self->nl_text ($opt{title}, text => $opt{text}); |
$self->nl_text ($opt{title}, text => $opt{text}); |
190 |
$self->html ('</h' . $section_rank . '>'); |
$self->html ('</h' . $section_rank . '>'); |
191 |
} # start_section |
} # start_section |
347 |
return join '/', @r; |
return join '/', @r; |
348 |
}; # $get_node_path |
}; # $get_node_path |
349 |
|
|
350 |
|
my $get_object_path = sub ($) { |
351 |
|
my $node = shift; |
352 |
|
my @r; |
353 |
|
while (defined $node) { |
354 |
|
my $ref = ref $node; |
355 |
|
$ref =~ /([^:]+)$/; |
356 |
|
my $rs = $1; |
357 |
|
my $node_name = $node->node_name; |
358 |
|
if (defined $node_name) { |
359 |
|
$rs .= ' <code>' . $htescape->($node_name) . '</code>'; |
360 |
|
} |
361 |
|
$node = undef; |
362 |
|
unshift @r, $rs; |
363 |
|
} |
364 |
|
return join '/', @r; |
365 |
|
}; # $get_object_path |
366 |
|
|
367 |
sub node_link ($$) { |
sub node_link ($$) { |
368 |
my ($self, $node) = @_; |
my ($self, $node) = @_; |
369 |
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
if ($node->isa ('Message::IF::Node')) { |
370 |
|
$self->xref ($get_node_path->($node), target => 'node-' . refaddr $node); |
371 |
|
} else { |
372 |
|
$self->html ($get_object_path->($node)); |
373 |
|
} |
374 |
} # node_link |
} # node_link |
375 |
|
|
376 |
{ |
{ |
472 |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
473 |
<script src="../cc-script.js"></script> |
<script src="../cc-script.js"></script> |
474 |
</head> |
</head> |
475 |
<body> |
<body onclick=" return onbodyclick (event) " onload=" onbodyload () "> |
476 |
<h1>]); |
<h1>]); |
477 |
$self->nl_text (q[WebHACC:Heading]); |
$self->nl_text (q[WebHACC:Heading]); |
478 |
$self->html ('</h1>'); |
$self->html (q[</h1><script> insertNavSections () </script>]); |
479 |
} # html_header |
} # html_header |
480 |
|
|
481 |
sub generate_input_section ($$) { |
sub generate_input_section ($$) { |
484 |
my $options = sub ($) { |
my $options = sub ($) { |
485 |
my $context = shift; |
my $context = shift; |
486 |
|
|
487 |
$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'">]); |
488 |
$out->nl_text (q[Options]); |
$out->nl_text (q[Options]); |
489 |
$out->start_tag ('div'); |
$out->start_tag ('div'); |
490 |
|
|
562 |
}; # $options |
}; # $options |
563 |
|
|
564 |
$out->start_section (id => 'input', title => 'Input'); |
$out->start_section (id => 'input', title => 'Input'); |
565 |
|
$out->html (q[<script> insertNavSections ('input') </script>]); |
566 |
|
|
567 |
$out->start_section (id => 'input-url', title => 'By URL'); |
$out->start_section (id => 'input-url', title => 'By URL', |
568 |
$out->start_tag ('form', action => './', 'accept-charset' => 'utf-8', |
parent_id => 'input'); |
569 |
|
$out->start_tag ('form', action => './#result-summary', |
570 |
|
'accept-charset' => 'utf-8', |
571 |
method => 'get'); |
method => 'get'); |
572 |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
573 |
|
|
581 |
value => $cgi->get_parameter ('uri')); |
value => $cgi->get_parameter ('uri')); |
582 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
583 |
|
|
|
$options->('url'); |
|
|
|
|
584 |
$out->start_tag ('p'); |
$out->start_tag ('p'); |
585 |
$out->start_tag ('button', type => 'submit'); |
$out->start_tag ('button', type => 'submit'); |
586 |
$out->nl_text ('Check'); |
$out->nl_text ('Check'); |
587 |
|
$out->end_tag ('button'); |
588 |
|
|
589 |
|
$options->('url'); |
590 |
|
|
591 |
$out->end_tag ('form'); |
$out->end_tag ('form'); |
592 |
$out->end_section; |
$out->end_section; |
595 |
|
|
596 |
## TODO: File upload |
## TODO: File upload |
597 |
|
|
598 |
$out->start_section (id => 'input-text', title => 'By direct input'); |
$out->start_section (id => 'input-text', title => 'By direct input', |
599 |
$out->start_tag ('form', action => './', 'accept-charset' => 'utf-8', |
parent_id => 'input'); |
600 |
|
$out->start_tag ('form', action => './#result-summary', |
601 |
|
'accept-charset' => 'utf-8', |
602 |
method => 'post'); |
method => 'post'); |
603 |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
$out->start_tag ('input', type => 'hidden', name => '_charset_'); |
604 |
|
|
610 |
$out->start_tag ('textarea', |
$out->start_tag ('textarea', |
611 |
name => 's'); |
name => 's'); |
612 |
my $s = $cgi->get_parameter ('s'); |
my $s = $cgi->get_parameter ('s'); |
613 |
$out->text ($s) if defined $s; |
$out->html ($htescape_value->($s)) if defined $s; |
614 |
$out->end_tag ('textarea'); |
$out->end_tag ('textarea'); |
615 |
$out->end_tag ('label'); |
$out->end_tag ('label'); |
616 |
|
|
|
$options->('text'); |
|
|
|
|
617 |
$out->start_tag ('p'); |
$out->start_tag ('p'); |
618 |
$out->start_tag ('button', type => 'submit', |
$out->start_tag ('button', type => 'submit', |
619 |
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"'); |
620 |
$out->nl_text ('Check'); |
$out->nl_text ('Check'); |
621 |
$out->end_tag ('button'); |
$out->end_tag ('button'); |
622 |
|
|
623 |
|
$options->('text'); |
624 |
|
|
625 |
$out->end_tag ('form'); |
$out->end_tag ('form'); |
626 |
$out->end_section; |
$out->end_section; |
627 |
|
|
628 |
|
$out->script (q[ |
629 |
|
if (!document.webhaccNavigated && |
630 |
|
document.getElementsByTagName ('textarea')[0].value.length > 0) { |
631 |
|
showTab ('input-text'); |
632 |
|
document.webhaccNavigated = false; |
633 |
|
} |
634 |
|
]); |
635 |
|
|
636 |
$out->end_section; |
$out->end_section; |
637 |
} # generate_input_section |
} # generate_input_section |
638 |
|
|