/[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.3 - (show annotations) (download)
Mon Jul 21 05:24:32 2008 UTC (16 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +28 -44 lines
++ ChangeLog	21 Jul 2008 05:20:07 -0000
	* cc.cgi: Information sections are now handled by WebHACC::Input
	module.  Input objects for subdocuments now owns their
	own subclass.

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

++ html/WebHACC/Language/ChangeLog	21 Jul 2008 05:24:27 -0000
	* Base.pm: Use new method for node links.

	* CSS.pm: Typo fixes.  Pass |input| object as an argument
	to the CSSOM validation not supported error.

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

++ html/WebHACC/ChangeLog	21 Jul 2008 05:23:21 -0000
	* Input.pm: A new subclass for subdocuments are added.
	Methods for information sections are added (from cc.cgi).

	* Output.pm (code): Support for attributes.
	(script, dt): New methods.
	(node_link): New method (from get_node_link in WebHACC::Result,
	which comes from cc.cgi).

	* Result.pm (add_error): Show some text even if no location
	infomration is available.  Use input object, if available,
	as fallback for location information.
	(get_error_label, get_node_path, get_node_link): Removed.
	The first method is no longer used.  The latters are now
	supported as |node_link| method in WebHACC::Output.

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

1 package WebHACC::Result;
2 use strict;
3
4 sub new ($) {
5 return bless {}, shift;
6 } # new
7
8 sub output ($;$) {
9 if (@_ > 1) {
10 if (defined $_[1]) {
11 $_[0]->{output} = $_[1];
12 } else {
13 delete $_[0]->{output};
14 }
15 }
16
17 return $_[0]->{output};
18 } # output
19
20 sub add_error ($%) {
21 my ($self, %opt) = @_;
22
23 my $out = $self->output;
24
25 my $error_level = $opt{level};
26 if (not defined $error_level) {
27 $error_level = 'm'; ## NOTE: Unknown - an error of the implementation
28 } elsif ({
29 m => 1, s => 1, w => 1, i => 1, u => 1,
30 }->{$error_level}) {
31 #
32 } else {
33 $error_level = 'm'; ## NOTE: Unknown - an error of the implementation
34 }
35
36 my $error_layer = $opt{layer};
37 if (not defined $error_layer) {
38 $error_layer = 'syntax'; ## NOTE: Unknown - an error of the implementation
39 } elsif ({
40 transfer => 1,
41 encode => 1,
42 charset => 1,
43 syntax => 1,
44 structure => 1,
45 semantics => 1,
46 }->{$error_layer}) {
47 #
48 } else {
49 $error_layer = 'syntax'; ## NOTE: Unknown - an error of the implementation
50 }
51
52 my $error_type_text = $opt{type};
53
54 my $class = qq[level-$error_level layer-$error_layer];
55
56 $out->start_tag ('dt', class => $class);
57 my $has_location;
58
59 ## URL
60
61 if (defined $opt{url}) {
62 $out->url ($opt{url});
63 $has_location = 1;
64 }
65
66 ## Line & column number
67
68 my $line;
69 my $column;
70
71 if (defined $opt{node}) {
72 $line = $opt{node}->get_user_data ('manakai_source_line');
73 if (defined $line) {
74 $column = $opt{node}->get_user_data ('manakai_source_column');
75 } else {
76 if ($opt{node}->node_type == $opt{node}->ATTRIBUTE_NODE) {
77 my $owner = $opt{node}->owner_element;
78 if ($owner) {
79 $line = $owner->get_user_data ('manakai_source_line');
80 $column = $owner->get_user_data ('manakai_source_column');
81 }
82 } else {
83 my $parent = $opt{node}->parent_node;
84 if ($parent) {
85 $line = $parent->get_user_data ('manakai_source_line');
86 $column = $parent->get_user_data ('manakai_source_column');
87 }
88 }
89 }
90 }
91 unless (defined $line) {
92 if (defined $opt{token} and defined $opt{token}->{line}) {
93 $line = $opt{token}->{line};
94 $column = $opt{token}->{column};
95 } elsif (defined $opt{line}) {
96 $line = $opt{line};
97 $column = $opt{column};
98 }
99 }
100
101 if (defined $line) {
102 if (defined $column and $column > 0) {
103 $out->xref ('Line ' . $line, target => 'line-' . $line);
104 $out->text (' column ' . $column);
105 } else {
106 $line = $line - 1 || 1;
107 $out->xref ('Line ' . $line, target => 'line-' . $line);
108 }
109 $has_location = 1;
110 }
111
112 ## Node path
113
114 if (defined $opt{node}) {
115 $out->html (' ');
116 $out->node_link ($opt{node});
117 $has_location = 1;
118 }
119
120 if (defined $opt{index}) {
121 if ($opt{index_has_link}) {
122 $out->html (' ');
123 $out->xref ('Index ' . (0+$opt{index}),
124 target => 'index-' . (0+$opt{index}));
125 } else {
126 $out->text (' Index ' . (0+$opt{index}));
127 }
128 $has_location = 1;
129 }
130
131 if (defined $opt{value}) {
132 $out->html (' ');
133 $out->code ($opt{value});
134 $has_location = 1;
135 }
136
137 unless ($has_location) {
138 if (defined $opt{input}) {
139 if (defined $opt{input}->{container_node}) {
140 my $original_input = $out->input;
141 $out->input ($opt{input}->{parent_input});
142 $out->node_link ($opt{input}->{container_node});
143 $out->input ($original_input);
144 $has_location = 1;
145 } elsif (defined $opt{input}->{request_uri}) {
146 $out->url ($opt{input}->{request_uri});
147 $has_location = 1;
148 } elsif (defined $opt{input}->{uri}) {
149 $out->url ($opt{input}->{uri});
150 $has_location = 1;
151 }
152 }
153
154 unless ($has_location) {
155 $out->text ('No location information available');
156 }
157 }
158
159 $out->start_tag ('dd', class => $class);
160 $out->text ($error_type_text);
161
162 if (defined $opt{text}) {
163 $out->html (' (<q>');
164 $out->text ($opt{text});
165 $out->html ('</q>)');
166 }
167
168 my $fragment = $opt{type};
169 $fragment =~ tr/ /-/;
170 $fragment = $out->encode_url_component ($fragment);
171 $out->text (' [');
172 $out->link ('Description', url => '../error-description#' . $fragment);
173 $out->text (']');
174
175
176 # my ($type, $cls, $msg) = main::get_text ($opt{type}, $opt{level});
177 # $out->html (qq[<dt class="$cls">] . $result->get_error_label ($input, \%opt));
178
179 $error_layer = 'char'
180 if $error_layer eq 'charset' or $error_layer eq 'encode';
181 if ($error_level eq 's') {
182 $self->{$error_layer}->{should}++;
183 $self->{$error_layer}->{score_min} -= 2;
184 $self->{conforming_min} = 0;
185 } elsif ($error_level eq 'w') {
186 $self->{$error_layer}->{warning}++;
187 } elsif ($error_level eq 'u') {
188 $self->{$error_layer}->{unsupported}++;
189 $self->{unsupported} = 1;
190 } elsif ($error_level eq 'i') {
191 #
192 } else {
193 $self->{$error_layer}->{must}++;
194 $self->{$error_layer}->{score_max} -= 2;
195 $self->{$error_layer}->{score_min} -= 2;
196 $self->{conforming_min} = 0;
197 $self->{conforming_max} = 0;
198 }
199 } # add_error
200
201 sub generate_result_section ($) {
202 my $result = shift;
203
204 my $out = $result->output;
205
206 $out->start_section (id => 'result-summary',
207 title => 'Result');
208
209 if ($result->{unsupported} and $result->{conforming_max}) {
210 $out->html (qq[<p class=uncertain id=result-para>The conformance
211 checker cannot decide whether the document is conforming or
212 not, since the document contains one or more unsupported
213 features. The document might or might not be conforming.</p>]);
214 } elsif ($result->{conforming_min}) {
215 $out->html (qq[<p class=PASS id=result-para>No conformance-error is
216 found in this document.</p>]);
217 } elsif ($result->{conforming_max}) {
218 $out->html (qq[<p class=SEE-RESULT id=result-para>This document
219 is <strong>likely <em>non</em>-conforming</strong>, but in rare case
220 it might be conforming.</p>]);
221 } else {
222 $out->html (qq[<p class=FAIL id=result-para>This document is
223 <strong><em>non</em>-conforming</strong>.</p>]);
224 }
225
226 $out->html (qq[<table>
227 <colgroup><col><colgroup><col><col><col><colgroup><col>
228 <thead>
229 <tr><th scope=col></th>
230 <th scope=col><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level
231 Errors</a></th>
232 <th scope=col><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level
233 Errors</a></th>
234 <th scope=col><a href="../error-description#level-w">Warnings</a></th>
235 <th scope=col>Score</th></tr></thead><tbody>]);
236
237 ## TODO: Introduce "N/A" value (e.g. Character layer is not applicable
238 ## to binary formats)
239
240 my $must_error = 0;
241 my $should_error = 0;
242 my $warning = 0;
243 my $score_min = 0;
244 my $score_max = 0;
245 my $score_base = 20;
246 my $score_unit = $score_base / 100;
247 for (
248 [Transfer => 'transfer', ''],
249 [Character => 'char', ''],
250 [Syntax => 'syntax', '#parse-errors'],
251 [Structure => 'structure', '#document-errors'],
252 ) {
253 $must_error += ($result->{$_->[1]}->{must} += 0);
254 $should_error += ($result->{$_->[1]}->{should} += 0);
255 $warning += ($result->{$_->[1]}->{warning} += 0);
256 $score_min += (($result->{$_->[1]}->{score_min} *= $score_unit) += $score_base);
257 $score_max += (($result->{$_->[1]}->{score_max} *= $score_unit) += $score_base);
258
259 my $uncertain = $result->{$_->[1]}->{unsupported} ? '?' : '';
260 my $label = $_->[0];
261 if ($result->{$_->[1]}->{must} or
262 $result->{$_->[1]}->{should} or
263 $result->{$_->[1]}->{warning} or
264 $result->{$_->[1]}->{unsupported}) {
265 $label = qq[<a href="$_->[2]">$label</a>];
266 }
267
268 $out->html (qq[<tr class="@{[$uncertain ? 'uncertain' : '']}"><th scope=row>$label</th><td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{must}$uncertain</td><td class="@{[$result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">$result->{$_->[1]}->{should}$uncertain</td><td>$result->{$_->[1]}->{warning}$uncertain</td>]);
269 if ($uncertain) {
270 $out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">&#x2212;&#x221E;..$result->{$_->[1]}->{score_max}]);
271 } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) {
272 $out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}]);
273 } else {
274 $out->html (qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}]);
275 }
276 $out->html (qq[ / 20]);
277 }
278
279 $score_max += $score_base;
280
281 $out->html (qq[
282 <tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>&#x2212;&#x221E;..$score_base / 20
283 </tbody>
284 <tfoot><tr class=uncertain><th scope=row>Total</th>
285 <td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td>
286 <td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td>
287 <td>$warning?</td>
288 <td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>&#x2212;&#x221E;..$score_max</strong> / 100
289 </table>
290
291 <p><strong>Important</strong>: This conformance checking service
292 is <em>under development</em>. The result above might be <em>wrong</em>.</p>]);
293 $out->end_section;
294 } # generate_result_section
295
296 sub get_error_level_label ($) {
297 my $self = shift;
298 my $err = shift;
299
300 my $r = '';
301
302 if (not defined $err->{level} or $err->{level} eq 'm') {
303 $r = qq[<strong><a href="../error-description#level-m"><em class=rfc2119>MUST</em>-level
304 error</a></strong>: ];
305 } elsif ($err->{level} eq 's') {
306 $r = qq[<strong><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>-level
307 error</a></strong>: ];
308 } elsif ($err->{level} eq 'w') {
309 $r = qq[<strong><a href="../error-description#level-w">Warning</a></strong>:
310 ];
311 } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') {
312 $r = qq[<strong><a href="../error-description#level-u">Not
313 supported</a></strong>: ];
314 } elsif ($err->{level} eq 'i') {
315 $r = qq[<strong><a href="../error-description#level-i">Information</a></strong>: ];
316 } else {
317 my $elevel = htescape ($err->{level});
318 $r = qq[<strong><a href="../error-description#level-$elevel">$elevel</a></strong>:
319 ];
320 }
321
322 return $r;
323 } # get_error_level_label
324
325 1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24