/[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.16 - (hide annotations) (download)
Sat Aug 30 05:32:51 2008 UTC (16 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.15: +30 -1 lines
++ ChangeLog	30 Aug 2008 05:32:30 -0000
2008-08-30  Wakaba  <wakaba@suika.fam.cx>

	* cc-style.css: Rule for empty |mark| elements is added.

	* error-description-source.xml: Error message for
	unknown address type error is updated.

++ html/WebHACC/ChangeLog	30 Aug 2008 05:32:47 -0000
2008-08-30  Wakaba  <wakaba@suika.fam.cx>

	* Result.pm (add_error): Support for |value|-segment marking.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24