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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Sun Jul 20 14:58:24 2008 UTC revision 1.3 by wakaba, Mon Jul 21 05:24:32 2008 UTC
# Line 5  sub new ($) { Line 5  sub new ($) {
5    return bless {}, shift;    return bless {}, shift;
6  } # new  } # 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  sub get_error_label ($$) {    return $_[0]->{output};
18    my $self = shift;  } # output
   my ($input, $err) = @_;  
19    
20    my $r = '';  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;    my $line;
69    my $column;    my $column;
70            
71    if (defined $err->{node}) {    if (defined $opt{node}) {
72      $line = $err->{node}->get_user_data ('manakai_source_line');      $line = $opt{node}->get_user_data ('manakai_source_line');
73      if (defined $line) {      if (defined $line) {
74        $column = $err->{node}->get_user_data ('manakai_source_column');        $column = $opt{node}->get_user_data ('manakai_source_column');
75      } else {      } else {
76        if ($err->{node}->node_type == $err->{node}->ATTRIBUTE_NODE) {        if ($opt{node}->node_type == $opt{node}->ATTRIBUTE_NODE) {
77          my $owner = $err->{node}->owner_element;          my $owner = $opt{node}->owner_element;
78          $line = $owner->get_user_data ('manakai_source_line');          if ($owner) {
79          $column = $owner->get_user_data ('manakai_source_column');            $line = $owner->get_user_data ('manakai_source_line');
80              $column = $owner->get_user_data ('manakai_source_column');
81            }
82        } else {        } else {
83          my $parent = $err->{node}->parent_node;          my $parent = $opt{node}->parent_node;
84          if ($parent) {          if ($parent) {
85            $line = $parent->get_user_data ('manakai_source_line');            $line = $parent->get_user_data ('manakai_source_line');
86            $column = $parent->get_user_data ('manakai_source_column');            $column = $parent->get_user_data ('manakai_source_column');
# Line 34  sub get_error_label ($$) { Line 89  sub get_error_label ($$) {
89      }      }
90    }    }
91    unless (defined $line) {    unless (defined $line) {
92      if (defined $err->{token} and defined $err->{token}->{line}) {      if (defined $opt{token} and defined $opt{token}->{line}) {
93        $line = $err->{token}->{line};        $line = $opt{token}->{line};
94        $column = $err->{token}->{column};        $column = $opt{token}->{column};
95      } elsif (defined $err->{line}) {      } elsif (defined $opt{line}) {
96        $line = $err->{line};        $line = $opt{line};
97        $column = $err->{column};        $column = $opt{column};
98      }      }
99    }    }
100    
101    if (defined $line) {    if (defined $line) {
102      if (defined $column and $column > 0) {      if (defined $column and $column > 0) {
103        $r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a> column $column];        $out->xref ('Line ' . $line, target => 'line-' . $line);
104          $out->text (' column ' . $column);
105      } else {      } else {
106        $line = $line - 1 || 1;        $line = $line - 1 || 1;
107        $r = qq[<a href="#$input->{id_prefix}line-$line">Line $line</a>];        $out->xref ('Line ' . $line, target => 'line-' . $line);
108      }      }
109        $has_location = 1;
110    }    }
111    
112    if (defined $err->{node}) {    ## Node path
113      $r .= ' ' if length $r;  
114      $r .= $self->get_node_link ($input, $err->{node});    if (defined $opt{node}) {
115        $out->html (' ');
116        $out->node_link ($opt{node});
117        $has_location = 1;
118    }    }
119    
120    if (defined $err->{index}) {    if (defined $opt{index}) {
121      if (length $r) {      if ($opt{index_has_link}) {
122        $r .= ', Index ' . (0+$err->{index});        $out->html (' ');
123          $out->xref ('Index ' . (0+$opt{index}),
124                      target => 'index-' . (0+$opt{index}));
125      } else {      } else {
126        $r .= "<a href='#$input->{id_prefix}index-@{[0+$err->{index}]}'>Index "        $out->text (' Index ' . (0+$opt{index}));
           . (0+$err->{index}) . '</a>';  
127      }      }
128        $has_location = 1;
129    }    }
130    
131    if (defined $err->{value}) {    if (defined $opt{value}) {
132      $r .= ' ' if length $r; ## BUG: v must be escaped      $out->html (' ');
133      $r .= '<q><code>' . ($err->{value}) . '</code></q>';      $out->code ($opt{value});
134        $has_location = 1;
135    }    }
136    
137    return $r;    unless ($has_location) {
138  } # get_error_label      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 ($) {  sub get_error_level_label ($) {
297    my $self = shift;    my $self = shift;
# Line 103  sub get_error_level_label ($) { Line 322  sub get_error_level_label ($) {
322    return $r;    return $r;
323  } # get_error_level_label  } # get_error_level_label
324    
 sub get_node_path ($) {  
   my $self = shift;  
   my $node = shift;  
   my @r;  
   while (defined $node) {  
     my $rs;  
     if ($node->node_type == 1) {  
       $rs = $node->node_name;  
       $node = $node->parent_node;  
     } elsif ($node->node_type == 2) {  
       $rs = '@' . $node->node_name;  
       $node = $node->owner_element;  
     } elsif ($node->node_type == 3) {  
       $rs = '"' . $node->data . '"';  
       $node = $node->parent_node;  
     } elsif ($node->node_type == 9) {  
       @r = ('') unless @r;  
       $rs = '';  
       $node = $node->parent_node;  
     } else {  
       $rs = '#' . $node->node_type;  
       $node = $node->parent_node;  
     }  
     unshift @r, $rs;  
   }  
   return join '/', @r;  
 } # get_node_path  
   
 use Scalar::Util qw/refaddr/;  
   
 sub get_node_link ($$) {  
   my $self = shift;  
   return qq[<a href="#$_[0]->{id_prefix}node-@{[refaddr $_[1]]}">] .  
        ($self->get_node_path ($_[1])) . qq[</a>];  
         ## BUG: ^ must be escaped  
 } # get_node_link  
   
325  1;  1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24