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

Contents of /test/html-webhacc/WebHACC/Result.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations) (download)
Fri Aug 15 05:53:23 2008 UTC (16 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.9: +8 -7 lines
++ ChangeLog	15 Aug 2008 05:43:43 -0000
2008-08-15  Wakaba  <wakaba@suika.fam.cx>

	* cc-style.css: Add icons to links and headings of error sections.
	Use standard "uncertain" color for level-u errors.  "No error found"
	messages are now handled by catalog, not by CSS presentation.
	The result paragraph saying that the conformance is unknown
	should be bordered as uncertain error messages are.

	* error-description-source.xml: New message entries
	for not-translated-yet messages.  Distinguish result table's
	layer names from other similar texts.

++ html/WebHACC/Language/ChangeLog	15 Aug 2008 05:53:19 -0000
2008-08-15  Wakaba  <wakaba@suika.fam.cx>

	* CSS.pm, CacheManifest.pm, HTML.pm, WebIDL.pm, XML.pm: Don't
	set "uncertain" flag to character encoding (encode) layer if the
	input is a character string.

++ html/WebHACC/ChangeLog	15 Aug 2008 05:51:54 -0000
2008-08-15  Wakaba  <wakaba@suika.fam.cx>

	* Input.pm (generate_transfer_sections): Use standard
	error list methods for transfer errors.  Typos fixed.

	* Output.pm (has_error): New attribute.
	(start_error_list, end_error_list): Support for role "transfer-errors".
	(end_error_list): Generate "no error found" paragraph if it should be.
	(generate_input_section): Decode parameters as UTF-8.

	* Result.pm (add_error): Set |has_error| flag.  Use catalog
	for "Unknown location" message.
	(generate_result_section): Use different text for
	result table rows than normal messages, to avoid collision
	with other messages (such as "Charset").

1 wakaba 1.1 package WebHACC::Result;
2     use strict;
3    
4     sub new ($) {
5 wakaba 1.9 return bless {
6     global_status => 'conforming',
7     # or, 'should-error', 'non-conforming', 'uncertain'
8     subdoc_results => [],
9     }, shift;
10 wakaba 1.1 } # new
11    
12 wakaba 1.2 sub output ($;$) {
13     if (@_ > 1) {
14     if (defined $_[1]) {
15     $_[0]->{output} = $_[1];
16     } else {
17     delete $_[0]->{output};
18     }
19     }
20    
21     return $_[0]->{output};
22     } # output
23    
24 wakaba 1.9 sub parent_result ($;$) {
25     if (@_ > 1) {
26     if (defined $_[1]) {
27     $_[0]->{parent_result} = $_[1];
28     } else {
29     delete $_[0]->{parent_result};
30     }
31     }
32    
33     return $_[0]->{parent_result};
34     } # parent_result
35    
36     sub layer_applicable ($$) {
37     my $self = shift;
38     my $layer = shift;
39     $self->{layers}->{$layer}->{applicable} = 1;
40     } # layer_applicable
41    
42     sub layer_uncertain ($$) {
43     my $self = shift;
44     my $layer = shift;
45     $self->{layers}->{$layer}->{uncertain} ||= 1;
46     $self->{layers}->{$layer}->{applicable} = 1;
47     $self->{global_status} = 'uncertain'
48     unless $self->{global_status} eq 'non-conforming';
49     } # layer_uncertain
50    
51 wakaba 1.2 sub add_error ($%) {
52     my ($self, %opt) = @_;
53    
54     my $out = $self->output;
55 wakaba 1.10 $out->has_error (1);
56 wakaba 1.2
57     my $error_level = $opt{level};
58     if (not defined $error_level) {
59     $error_level = 'm'; ## NOTE: Unknown - an error of the implementation
60     } elsif ({
61     m => 1, s => 1, w => 1, i => 1, u => 1,
62     }->{$error_level}) {
63     #
64     } else {
65     $error_level = 'm'; ## NOTE: Unknown - an error of the implementation
66     }
67    
68     my $error_layer = $opt{layer};
69     if (not defined $error_layer) {
70     $error_layer = 'syntax'; ## NOTE: Unknown - an error of the implementation
71     } elsif ({
72     transfer => 1,
73     encode => 1,
74     charset => 1,
75     syntax => 1,
76     structure => 1,
77     semantics => 1,
78     }->{$error_layer}) {
79     #
80     } else {
81     $error_layer = 'syntax'; ## NOTE: Unknown - an error of the implementation
82     }
83    
84     my $error_type_text = $opt{type};
85    
86     my $class = qq[level-$error_level layer-$error_layer];
87    
88 wakaba 1.6 ## Line & column numbers (prepare values)
89 wakaba 1.1
90     my $line;
91     my $column;
92    
93 wakaba 1.2 if (defined $opt{node}) {
94     $line = $opt{node}->get_user_data ('manakai_source_line');
95 wakaba 1.1 if (defined $line) {
96 wakaba 1.2 $column = $opt{node}->get_user_data ('manakai_source_column');
97 wakaba 1.7 } elsif ($opt{node}->isa ('Message::IF::Node')) {
98 wakaba 1.2 if ($opt{node}->node_type == $opt{node}->ATTRIBUTE_NODE) {
99     my $owner = $opt{node}->owner_element;
100     if ($owner) {
101     $line = $owner->get_user_data ('manakai_source_line');
102     $column = $owner->get_user_data ('manakai_source_column');
103     }
104 wakaba 1.1 } else {
105 wakaba 1.2 my $parent = $opt{node}->parent_node;
106 wakaba 1.1 if ($parent) {
107     $line = $parent->get_user_data ('manakai_source_line');
108     $column = $parent->get_user_data ('manakai_source_column');
109     }
110     }
111     }
112     }
113     unless (defined $line) {
114 wakaba 1.2 if (defined $opt{token} and defined $opt{token}->{line}) {
115     $line = $opt{token}->{line};
116     $column = $opt{token}->{column};
117     } elsif (defined $opt{line}) {
118     $line = $opt{line};
119     $column = $opt{column};
120 wakaba 1.1 }
121     }
122 wakaba 1.6 $line = $line - 1 || 1
123     if defined $line and not (defined $column and $column > 0);
124    
125     $out->start_tag ('dt', class => $class,
126     'data-type' => $opt{type},
127     'data-level' => $error_level,
128     'data-layer' => $error_layer,
129     ($line ? ('data-line' => $line) : ()),
130     ($column ? ('data-column' => $column) : ()));
131     my $has_location;
132    
133     ## URL
134    
135     if (defined $opt{url}) {
136     $out->url ($opt{url});
137     $has_location = 1;
138     }
139    
140     ## Line & column numbers (real output)
141 wakaba 1.1
142     if (defined $line) {
143     if (defined $column and $column > 0) {
144 wakaba 1.6 $out->xref ('Line #', text => $line, target => 'line-' . $line);
145     $out->text (' ');
146     $out->nl_text ('column #', text => $column);
147 wakaba 1.1 } else {
148 wakaba 1.6 $out->xref ('Line #', text => $line, target => 'line-' . $line);
149 wakaba 1.1 }
150 wakaba 1.3 $has_location = 1;
151 wakaba 1.1 }
152    
153 wakaba 1.2 ## Node path
154    
155     if (defined $opt{node}) {
156     $out->html (' ');
157     $out->node_link ($opt{node});
158 wakaba 1.3 $has_location = 1;
159 wakaba 1.1 }
160    
161 wakaba 1.2 if (defined $opt{index}) {
162     if ($opt{index_has_link}) {
163     $out->html (' ');
164 wakaba 1.6 $out->xref ('Index #', text => (0+$opt{index}),
165 wakaba 1.2 target => 'index-' . (0+$opt{index}));
166 wakaba 1.1 } else {
167 wakaba 1.6 $out->html (' ');
168     $out->nl_text ('Index #', text => (0+$opt{index}));
169 wakaba 1.1 }
170 wakaba 1.3 $has_location = 1;
171 wakaba 1.1 }
172    
173 wakaba 1.2 if (defined $opt{value}) {
174     $out->html (' ');
175     $out->code ($opt{value});
176 wakaba 1.3 $has_location = 1;
177     }
178    
179     unless ($has_location) {
180     if (defined $opt{input}) {
181     if (defined $opt{input}->{container_node}) {
182     my $original_input = $out->input;
183     $out->input ($opt{input}->{parent_input});
184     $out->node_link ($opt{input}->{container_node});
185     $out->input ($original_input);
186     $has_location = 1;
187     } elsif (defined $opt{input}->{request_uri}) {
188     $out->url ($opt{input}->{request_uri});
189     $has_location = 1;
190     } elsif (defined $opt{input}->{uri}) {
191     $out->url ($opt{input}->{uri});
192     $has_location = 1;
193     }
194     }
195    
196     unless ($has_location) {
197 wakaba 1.10 $out->nl_text ('Unknown location');
198 wakaba 1.3 }
199 wakaba 1.1 }
200 wakaba 1.2
201     $out->start_tag ('dd', class => $class);
202 wakaba 1.4
203     ## Error level
204 wakaba 1.9 $out->nl_text ('Error level ' . $error_level);
205     $out->text (': ');
206 wakaba 1.4
207     ## Error message
208 wakaba 1.6 $out->nl_text ($error_type_text, node => $opt{node}, text => $opt{text});
209 wakaba 1.2
210 wakaba 1.4 ## Additional error description
211 wakaba 1.2 if (defined $opt{text}) {
212     $out->html (' (<q>');
213     $out->text ($opt{text});
214     $out->html ('</q>)');
215     }
216 wakaba 1.4
217     ## Link to a long description
218 wakaba 1.2
219     my $fragment = $opt{type};
220     $fragment =~ tr/ /-/;
221     $fragment = $out->encode_url_component ($fragment);
222     $out->text (' [');
223 wakaba 1.4 $out->link ('Description', url => '../error-description#' . $fragment,
224     rel => 'help');
225 wakaba 1.2 $out->text (']');
226    
227 wakaba 1.9 if ($error_level eq 'm') {
228     $self->{layers}->{$error_layer}->{must}++;
229     $self->{global_status} = 'non-conforming';
230     } elsif ($error_level eq 's') {
231     $self->{layers}->{$error_layer}->{should}++;
232     $self->{global_status} = 'should-error'
233     unless {'non-conforming' => 1,
234     uncertain => 1}->{$self->{global_status}};
235 wakaba 1.2 } elsif ($error_level eq 'w') {
236 wakaba 1.9 $self->{layers}->{$error_layer}->{warning}++;
237 wakaba 1.2 } elsif ($error_level eq 'u') {
238 wakaba 1.9 $self->{layers}->{$error_layer}->{uncertain}++;
239     $self->{global_status} = 'uncertain'
240     unless $self->{global_status} eq 'non-conforming';
241 wakaba 1.2 } elsif ($error_level eq 'i') {
242 wakaba 1.9 $self->{layers}->{$error_layer}->{info}++;
243 wakaba 1.2 }
244     } # add_error
245    
246     sub generate_result_section ($) {
247 wakaba 1.9 my $self = shift;
248    
249     my $result = $self;
250 wakaba 1.2
251     my $out = $result->output;
252    
253 wakaba 1.9 $out->start_section (role => 'result');
254 wakaba 1.2
255 wakaba 1.9 my $para_class = {
256     'conforming' => 'result-para no-error',
257     'should-error' => 'result-para should-errors',
258     'non-conforming' => 'result-para must-errors',
259     'uncertain' => 'result-para uncertain',
260     }->{$self->{global_status}};
261     $out->start_tag ('p', class => $para_class);
262     $out->nl_text ('Conformance is ' . $self->{global_status});
263     $out->end_tag ('p');
264    
265     $out->html (qq[<table>
266     <colgroup><col><col><colgroup><col><col><col><col><colgroup><col>
267     <thead>
268     <tr><th scope=col colspan=2>]);
269     for ('Error level m', 'Error level s', 'Error level w',
270     'Error level i', 'Score') {
271     $out->start_tag ('th');
272     $out->nl_text ($_);
273     }
274    
275     my $maindoc_status = {must => 0, should => 0, warning => 0, info => 0,
276     uncertain => 0, applicable => 1};
277     my $subdocs_status = {must => 0, should => 0, warning => 0, info => 0,
278     uncertain => 0, applicable => 1};
279     my $global_status = {must => 0, should => 0, warning => 0, info => 0,
280     uncertain => 0, applicable => 1};
281    
282     my $score_unit = 2;
283    
284     my @row = (
285     sub {
286     $out->start_tag ('tbody');
287     $out->start_tag ('tr');
288     $out->start_tag ('th', colspan => 7, scope => 'col');
289     $out->nl_text ('Main document');
290     },
291 wakaba 1.10 {label => 'Transfer L.', status => $self->{layers}->{transfer},
292 wakaba 1.9 target => 'transfer-errors', score_base => 20,
293     parent_status => $maindoc_status},
294 wakaba 1.10 {label => 'Encode L.', status => $self->{layers}->{encode},
295 wakaba 1.9 score_base => 10,
296     parent_status => $maindoc_status},
297 wakaba 1.10 {label => 'Char L.', status => $self->{layers}->{charset},
298 wakaba 1.9 score_base => 10,
299     parent_status => $maindoc_status},
300 wakaba 1.10 {label => 'Syntax L.', status => $self->{layers}->{syntax},
301 wakaba 1.9 target => 'parse-errors', score_base => 20,
302     parent_status => $maindoc_status},
303 wakaba 1.10 {label => 'Structure L.', status => $self->{layers}->{structure},
304 wakaba 1.9 target => 'document-errors', score_base => 20,
305     parent_status => $maindoc_status},
306 wakaba 1.10 {label => 'Semantics L.', status => $self->{layers}->{semantics},
307 wakaba 1.9 score_base => 20,
308     parent_status => $maindoc_status},
309     );
310    
311     if (@{$self->{subdoc_results}}) {
312     push @row, {label => 'Subtotal', status => $maindoc_status,
313     score_base => 100,
314     parent_status => $global_status, is_total => 1};
315     push @row, sub {
316     $out->start_tag ('tbody');
317     $out->start_tag ('tr');
318     $out->start_tag ('th', colspan => 7, scope => 'col');
319     $out->nl_text ('Subdocuments');
320     };
321     for (@{$self->{subdoc_results}}) {
322     push @row, {label => '#' . $_->{input}->full_subdocument_index,
323     status => $_,
324     target => $_->{input}->id_prefix . 'result-summary',
325     score_base => 100, parent_status => $subdocs_status};
326     }
327     push @row, {label => 'Subtotal', status => $subdocs_status,
328     score_base => 100 * @{$self->{subdoc_results}},
329     parent_status => $global_status, is_total => 1};
330 wakaba 1.2 } else {
331 wakaba 1.9 $global_status = $maindoc_status;
332 wakaba 1.2 }
333    
334 wakaba 1.9 push @row, sub {
335     $out->start_tag ('tfoot');
336     };
337     push @row, {label => 'Total', status => $global_status,
338     score_base => 100 * (@{$self->{subdoc_results}} + 1),
339     parent_status => {}, is_total => 1};
340    
341     for my $x (@row) {
342     if (ref $x eq 'CODE') {
343     $x->();
344     next;
345     }
346    
347     $x->{parent_status}->{$_} += $x->{status}->{$_}
348     for qw/must should warning info uncertain/;
349    
350     my $row_class = $x->{status}->{uncertain} ? 'uncertain' : '';
351     $row_class .= ' total' if $x->{is_total};
352     $out->start_tag ('tr', class => $row_class);
353     my $uncertain = $x->{status}->{uncertain} ? '?' : '';
354    
355     $out->start_tag ('td', class => 'subrow') unless $x->{is_total};
356    
357     ## Layer name
358     $out->start_tag ('th', colspan => $x->{is_total} ? 2 : 1,
359     scope => 'row');
360     if (defined $x->{target} and
361     ($x->{status}->{must} or $x->{status}->{should} or
362     $x->{status}->{warning} or $x->{status}->{info} or
363     $x->{status}->{uncertain})) {
364     $out->xref ($x->{label}, target => $x->{target});
365     } else {
366     $out->nl_text ($x->{label});
367     }
368    
369     ## MUST-level errors
370     $out->start_tag ('td', class => $x->{status}->{must} ? 'must-errors' : '');
371     if ($x->{status}->{applicable}) {
372     $out->text (($x->{status}->{must} or 0) . $uncertain);
373     } else {
374     $out->nl_text ('N/A');
375     }
376    
377     ## SHOULD-level errors
378     $out->start_tag ('td',
379     class => $x->{status}->{should} ? 'should-errors' : '');
380     if ($x->{status}->{applicable}) {
381     $out->text (($x->{status}->{should} or 0) . $uncertain);
382     } else {
383     $out->nl_text ('N/A');
384     }
385    
386     ## Warnings
387     $out->start_tag ('td', class => $x->{status}->{warning} ? 'warnings' : '');
388     if ($x->{status}->{applicable}) {
389     $out->text (($x->{status}->{warning} or 0) . $uncertain);
390     } else {
391     $out->nl_text ('N/A');
392     }
393    
394     ## Informations
395     $out->start_tag ('td', class => $x->{status}->{info} ? 'infos' : '');
396     if ($x->{status}->{applicable}) {
397     $out->text (($x->{status}->{info} or 0) . $uncertain);
398     } else {
399     $out->nl_text ('N/A');
400     }
401    
402     ## Score
403     $out->start_tag ('td',
404     class => $x->{status}->{must} ? 'score must-errors' :
405     $x->{status}->{should} ? 'score should-errors' :
406     'score');
407    
408     my $max_score = $x->{score_base};
409     $max_score -= $x->{status}->{must} * $score_unit;
410     my $min_score = $max_score;
411     $min_score -= $x->{status}->{should} * $score_unit;
412    
413     $out->start_tag ('strong');
414     if ($x->{status}->{uncertain}) {
415     $out->html ('&#x2212;&#x221E; '); # negative inifinity
416     $out->nl_text ('...');
417     $out->html ($max_score < 0 ?
418     ' &#x2212;' . substr ($max_score, 1) : ' ' . $max_score);
419     } elsif ($min_score != $max_score) {
420     $out->html ($min_score < 0 ?
421     '&#x2212;' . substr ($min_score, 1) . ' ': $min_score . ' ');
422     $out->nl_text ('...');
423     $out->html ($max_score < 0 ?
424     ' &#x2212;' . substr ($max_score, 1) : ' ' . $max_score);
425 wakaba 1.2 } else {
426 wakaba 1.9 $out->html ($max_score < 0 ?
427     '&#x2212;' . substr ($max_score, 1) : $max_score);
428 wakaba 1.2 }
429 wakaba 1.9 $out->end_tag ('strong');
430    
431     $out->text (' / ' . $x->{score_base});
432 wakaba 1.2 }
433 wakaba 1.9
434     $out->end_tag ('table');
435 wakaba 1.2
436 wakaba 1.9 my $parent = $self->parent_result;
437     if ($parent) {
438     $global_status->{input} = $out->input;
439     push @{$parent->{subdoc_results}}, $global_status;
440     }
441 wakaba 1.2
442 wakaba 1.9 $out->nl_text ('This checker is work in progress.');
443 wakaba 1.2 $out->end_section;
444     } # generate_result_section
445 wakaba 1.1
446     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24