/[suikacvs]/test/html-webhacc/WebHACC/Language/DOM.pm
Suika

Contents of /test/html-webhacc/WebHACC/Language/DOM.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Mon Jul 21 12:56:34 2008 UTC (16 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +38 -14 lines
++ ChangeLog	21 Jul 2008 12:51:50 -0000
	* .htaccess: error-description-source.xml is in UTF-8
	actually.

	* Makefile: Rule to make Japanese language catalog file
	is added.

	* cc-script.js: Line and column numbers are now taken
	from data-* attributes, not from textContent.

	* cc.cgi: Tentative support for Japanese/English conneg.
	(load_text_catalog, get_text): Removed (catalog text selection
	is now handled by WebHACC::Output).

	* error-description-source.xml: Catalog entries in new
	format are added.  Old catalog element is removed.

	* mkcatalog.pl: Support for non-English languages.
	Drop support for old catalog element.  Add support
	for new cat element.

	* mkdescription.pl: Drop support for old catalog element.
	Add support for new cat element.

2008-07-21  Wakaba  <wakaba@suika.fam.cx>

++ html/WebHACC/Language/ChangeLog	21 Jul 2008 12:56:30 -0000
	* DOM.pm (generate_structure_dump_section): Use catalog
	for human-readable texts.
	(generate_table_section): Use catalog for human readable texts.

2008-07-21  Wakaba  <wakaba@suika.fam.cx>

++ html/WebHACC/ChangeLog	21 Jul 2008 12:55:41 -0000
	* Input.pm: Most human-readable texts are now handled by
	catalog.
	(id_prefix): Support for nested subdocuments.

	* Output.pm (start_section, dt, xref): Section/item names and
	link labels are now handled by catalog.
	(load_text_catalog, nl_text): New methods.
	(html_header): Application name is moved to catalog.

	* Result.pm (add_error): Important error properties are
	now exposed to client-side script as data-* attributes.
	Labels are now handled by catalog.  Error descriptions
	are now taken from catalog as it were.

2008-07-21  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 package WebHACC::Language::DOM;
2     use strict;
3     require WebHACC::Language::Base;
4     push our @ISA, 'WebHACC::Language::Base';
5    
6     use Scalar::Util qw[refaddr];
7    
8     sub generate_structure_dump_section ($) {
9     my $self = shift;
10    
11     my $out = $self->output;
12    
13 wakaba 1.3 $out->start_section (role => 'tree');
14 wakaba 1.1
15     $out->start_tag ('ol', class => 'xoxo');
16    
17     my @node = ($self->{structure});
18     while (@node) {
19     my $child = shift @node;
20     unless (ref $child) {
21     $out->html ($child);
22     next;
23     }
24    
25     my $node_id = 'node-'.refaddr $child;
26     my $nt = $child->node_type;
27     if ($nt == $child->ELEMENT_NODE) {
28     my $child_nsuri = $child->namespace_uri;
29     $out->start_tag ('li', id => $node_id, class => 'tree-element');
30     $out->start_tag ('code',
31     title => defined $child_nsuri ? $child_nsuri : '');
32     $out->text ($child->tag_name); ## TODO: case
33     $out->end_tag ('code');
34    
35     if ($child->has_attributes) {
36     $out->start_tag ('ul', class => 'attributes');
37     for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] }
38     @{$child->attributes}) {
39     $out->start_tag ('li', id => $attr->[3], class => 'tree-attribute');
40     $out->start_tag ('code',
41     title => defined $attr->[2] ? $attr->[2] : '');
42     $out->html ($attr->[0]); ## ISSUE: case
43     $out->end_tag ('code');
44     $out->text (' = ');
45     $out->start_tag ('q');
46     $out->text ($attr->[1]); ## TODO: children
47     $out->end_tag ('q');
48     }
49     $out->end_tag ('ul');
50     }
51    
52     if ($child->has_child_nodes) {
53     $out->start_tag ('ol', class => 'children');
54     unshift @node, @{$child->child_nodes}, '</ol></li>';
55     }
56     } elsif ($nt == $child->TEXT_NODE) {
57     $out->start_tag ('li', id => $node_id, class => 'tree-text');
58     $out->start_tag ('q', lang => '');
59     $out->text ($child->data);
60     $out->end_tag ('q');
61     } elsif ($nt == $child->CDATA_SECTION_NODE) {
62     $out->start_tag ('li', id => $node_id, class => 'tree-cdata');
63     $out->start_tag ('code');
64     $out->text ('<![CDATA[');
65     $out->end_tag ('code');
66     $out->start_tag ('q', lang => '');
67     $out->text ($child->data);
68     $out->end_tag ('q');
69     $out->start_tag ('code');
70     $out->text (']]>');
71     $out->end_tag ('code');
72     } elsif ($nt == $child->COMMENT_NODE) {
73     $out->start_tag ('li', id => $node_id, class => 'tree-cdata');
74     $out->start_tag ('code');
75     $out->text ('<!--');
76     $out->end_tag ('code');
77     $out->start_tag ('q', lang => '');
78     $out->text ($child->data);
79     $out->end_tag ('q');
80     $out->start_tag ('code');
81     $out->text ('-->');
82     $out->end_tag ('code');
83     } elsif ($nt == $child->DOCUMENT_NODE) {
84     $out->start_tag ('li', id => $node_id, class => 'tree-document');
85 wakaba 1.6 $out->nl_text ('Document');
86    
87 wakaba 1.1 $out->start_tag ('ul', class => 'attributes');
88 wakaba 1.6
89 wakaba 1.1 my $cp = $child->manakai_charset;
90     if (defined $cp) {
91 wakaba 1.6 $out->start_tag ('li');
92     $out->nl_text ('manakaiCharset');
93     $out->text (' = ');
94     $out->code ($cp);
95 wakaba 1.1 }
96 wakaba 1.6
97     $out->start_tag ('li');
98     $out->nl_text ('inputEncoding');
99     $out->text (' = ');
100 wakaba 1.1 my $ie = $child->input_encoding;
101     if (defined $ie) {
102     $out->code ($ie);
103     if ($child->manakai_has_bom) {
104 wakaba 1.6 $out->nl_text ('... with BOM');
105 wakaba 1.1 }
106     } else {
107     $out->html (qq[(<code>null</code>)]);
108     }
109 wakaba 1.6
110     $out->start_tag ('li');
111     $out->nl_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0));
112    
113     $out->start_tag ('li');
114     $out->nl_text ('manakaiCompatMode:'.$child->manakai_compat_mode);
115    
116 wakaba 1.1 unless ($child->manakai_is_html) {
117 wakaba 1.6 $out->start_tag ('li');
118     $out->nl_text ('xmlVersion');
119     $out->text (' = ');
120 wakaba 1.1 $out->code ($child->xml_version);
121 wakaba 1.6
122     $out->start_tag ('li');
123     $out->nl_text ('xmlEncoding');
124     $out->text (' = ');
125 wakaba 1.1 if (defined $child->xml_encoding) {
126     $out->code ($child->xml_encoding);
127     } else {
128 wakaba 1.6 $out->html ('(<code>null</code>)');
129 wakaba 1.1 }
130 wakaba 1.6
131     $out->start_tag ('li');
132     $out->nl_text ('xmlStandalone');
133     $out->text (' = ');
134     $out->code ($child->xml_standalone ? 'true' : 'false');
135 wakaba 1.1 }
136 wakaba 1.6
137 wakaba 1.1 $out->end_tag ('ul');
138 wakaba 1.6
139 wakaba 1.1 if ($child->has_child_nodes) {
140     $out->start_tag ('ol', class => 'children');
141     unshift @node, @{$child->child_nodes}, '</ol></li>';
142     }
143     } elsif ($nt == $child->DOCUMENT_TYPE_NODE) {
144     $out->start_tag ('li', id => $node_id, class => 'tree-doctype');
145     $out->code ('<!DOCTYPE>');
146     $out->start_tag ('ul', class => 'attributes');
147    
148     $out->start_tag ('li', class => 'tree-doctype-name');
149     $out->text ('Name = ');
150     $out->code ($child->name);
151    
152     $out->start_tag ('li', class => 'tree-doctype-publicid');
153     $out->text ('Public identifier = ');
154     $out->code ($child->public_id);
155    
156     $out->start_tag ('li', class => 'tree-doctype-systemid');
157     $out->text ('System identifier = ');
158     $out->code ($child->system_id);
159    
160     $out->end_tag ('ul');
161     } elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) {
162     $out->start_tag ('li', id => $node_id, class => 'tree-id');
163     $out->code ('<?');
164     $out->code ($child->target);
165     $out->text (' ');
166     $out->code ($child->data);
167     $out->code ('?>');
168     } else { # error
169     $out->start_tag ('li', id => $node_id, class => 'tree-unknown');
170     $out->text ($child->node_type . ' ' . $child->node_name);
171     }
172     }
173     $out->end_tag ('ol');
174    
175     $out->end_section;
176     } # generate_structure_dump_section
177    
178     sub generate_structure_error_section ($) {
179     my $self = shift;
180    
181     my $out = $self->output;
182 wakaba 1.3 $out->start_section (role => 'structure-errors');
183     $out->start_error_list (role => 'structure-errors');
184 wakaba 1.1
185     my $input = $self->input;
186     my $result = $self->result;
187    
188     require Whatpm::ContentChecker;
189     my $onerror = sub {
190 wakaba 1.2 $result->add_error (@_, layer => 'structure');
191 wakaba 1.1 };
192    
193     my $onsubdoc = $self->onsubdoc;
194     if ($self->{structure}->node_type == $self->{structure}->ELEMENT_NODE) {
195     $self->{add_info} = Whatpm::ContentChecker->check_element
196     ($self->{structure}, $onerror, $onsubdoc);
197     } else {
198     $self->{add_info} = Whatpm::ContentChecker->check_document
199     ($self->{structure}, $onerror, $onsubdoc);
200     }
201    
202 wakaba 1.3 $out->end_error_list (role => 'structure-errors');
203 wakaba 1.1 $out->end_section;
204     } # generate_structure_error_section
205 wakaba 1.3
206     sub generate_additional_sections ($) {
207     my $self = shift;
208     $self->SUPER::generate_additional_sections;
209 wakaba 1.4
210 wakaba 1.3 $self->generate_table_section;
211 wakaba 1.4
212     $self->generate_listing_section (
213     key => 'id', id => 'identifiers',
214     short_title => 'IDs', title => 'Identifiers',
215     );
216     $self->generate_listing_section (
217     key => 'term', id => 'terms',
218     short_title => 'Terms', title => 'Terms',
219     );
220     $self->generate_listing_section (
221     key => 'class', id => 'classes',
222     short_title => 'Classes', title => 'Classes',
223     );
224    
225     $self->generate_rdf_section;
226 wakaba 1.3 } # generate_additional_sections
227    
228     sub generate_table_section ($) {
229     my $self = shift;
230    
231     my $tables = $self->{add_info}->{table} || [];
232     return unless @$tables;
233    
234     my $out = $self->output;
235 wakaba 1.6 $out->start_section (id => 'tables', short_title => 'Tables',
236     title => 'Tables Section');
237 wakaba 1.3
238     $out->html (q[<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
239     <script src="../table-script.js" type="text/javascript"></script>
240     <noscript>
241     <p><em>Structure of tables are visualized here if scripting is enabled.</em></p>
242     </noscript>]);
243    
244     require JSON;
245    
246     my $i = 0;
247     for my $table (@$tables) {
248     $i++;
249 wakaba 1.5 my $index = $out->input->full_subdocument_index;
250     $index = $index ? $index . '.' . $i : $i;
251 wakaba 1.3 $out->start_section (id => 'table-' . $i,
252 wakaba 1.6 title => 'Table #',
253     text => $index);
254 wakaba 1.3
255     $out->start_tag ('dl');
256     $out->dt ('Table Element');
257     $out->start_tag ('dd');
258     $out->node_link ($table->{element});
259     $out->end_tag ('dl');
260     delete $table->{element};
261    
262     for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption},
263     @{$table->{row}}) {
264     next unless $_;
265     delete $_->{element};
266     }
267    
268     for (@{$table->{row_group}}) {
269     next unless $_;
270     next unless $_->{element};
271     $_->{type} = $_->{element}->manakai_local_name;
272     delete $_->{element};
273     }
274    
275     for (@{$table->{cell}}) {
276     next unless $_;
277     for (@{$_}) {
278     next unless $_;
279     for (@$_) {
280     $_->{id} = refaddr $_->{element} if defined $_->{element};
281     delete $_->{element};
282     $_->{is_header} = $_->{is_header} ? 1 : 0;
283     }
284     }
285     }
286    
287     my $id_prefix = $self->input->id_prefix;
288     $out->script (q[tableToCanvas (] .
289     JSON::objToJson ($table) .
290     q[, document.getElementById ('] . $id_prefix . 'table-' . $i . q[')] .
291     q[, '] . $id_prefix . q[');]);
292    
293     $out->end_section;
294     }
295    
296     $out->end_section;
297 wakaba 1.4 } # generate_table_section
298 wakaba 1.3
299 wakaba 1.4 sub generate_listing_section ($%) {
300     my $self = shift;
301     my %opt = @_;
302 wakaba 1.3
303 wakaba 1.4 my $list = $self->{add_info}->{$opt{key}} || {};
304     return unless keys %$list;
305 wakaba 1.3
306 wakaba 1.4 my $out = $self->output;
307 wakaba 1.3
308 wakaba 1.4 $out->start_section (id => $opt{id},
309     title => $opt{title},
310     short_title => $opt{short_title});
311     $out->start_tag ('dl');
312    
313     for my $id (sort {$a cmp $b} keys %$list) {
314     $out->start_tag ('dt');
315     $out->code ($id);
316     for (@{$list->{$id}}) {
317     $out->start_tag ('dd');
318     $out->node_link ($_);
319 wakaba 1.3 }
320     }
321    
322 wakaba 1.4 $out->end_tag ('dl');
323     $out->end_section;
324     } # generate_listing_section
325    
326     my $generate_rdf_resource_html = sub ($$) {
327     my ($resource, $out) = @_;
328    
329 wakaba 1.3 if (defined $resource->{uri}) {
330 wakaba 1.4 $out->url ($resource->{uri});
331 wakaba 1.3 } elsif (defined $resource->{bnodeid}) {
332 wakaba 1.4 $out->text ('_:' . $resource->{bnodeid});
333 wakaba 1.3 } elsif ($resource->{nodes}) {
334 wakaba 1.4 $out->text ('(rdf:XMLLiteral)');
335 wakaba 1.3 } elsif (defined $resource->{value}) {
336 wakaba 1.4 $out->start_tag ('q',
337     lang => defined $resource->{language}
338     ? $resource->{language} : '');
339     $out->text ($resource->{value});
340     $out->end_tag ('q');
341    
342 wakaba 1.3 if (defined $resource->{datatype}) {
343 wakaba 1.4 $out->text ('^^');
344     $out->url ($resource->{datatype});
345 wakaba 1.3 } elsif (length $resource->{language}) {
346 wakaba 1.4 $out->text ('@' . $resource->{language});
347 wakaba 1.3 }
348     } else {
349 wakaba 1.4 $out->text ('??'); ## NOTE: An error of the implementation.
350 wakaba 1.3 }
351 wakaba 1.4 }; # $generate_rdf_resource_html
352    
353     ## TODO: Should we move this method to another module,
354     ## such as Base or RDF?
355     sub generate_rdf_section ($) {
356     my $self = shift;
357    
358     my $list = $self->{add_info}->{rdf} || [];
359     return unless @$list;
360    
361     my $out = $self->output;
362     $out->start_section (id => 'rdf', short_title => 'RDF',
363     title => 'RDF Triples');
364     $out->start_tag ('dl');
365    
366     my $i = 0;
367     for my $rdf (@$list) {
368     $out->start_tag ('dt', id => 'rdf-' . $i++);
369     $out->node_link ($rdf->[0]);
370     $out->start_tag ('dd');
371     $out->start_tag ('dl');
372     for my $triple (@{$rdf->[1]}) {
373     $out->start_tag ('dt');
374     $out->node_link ($triple->[0]);
375     $out->start_tag ('dd');
376     $out->text ('Subject: ');
377     $generate_rdf_resource_html->($triple->[1] => $out);
378     $out->start_tag ('dd');
379     $out->text ('Predicate: ');
380     $generate_rdf_resource_html->($triple->[2] => $out);
381     $out->start_tag ('dd');
382     $out->text ('Object: ');
383     $generate_rdf_resource_html->($triple->[3] => $out);
384     }
385     $out->end_tag ('dl');
386     }
387     $out->end_tag ('dl');
388     $out->end_section;
389     } # generate_rdf_section
390 wakaba 1.1
391     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24