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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations) (download)
Thu Aug 14 15:50:42 2008 UTC (16 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +3 -0 lines
++ ChangeLog	14 Aug 2008 15:42:17 -0000
	* cc.cgi: Generate result summary sections for
	each subdocument.

	* error-description-source.xml: New entries to
	support localization of result sections.

2008-08-14  Wakaba  <wakaba@suika.fam.cx>

	* cc-style.css: Support for revised version of result summary
	section styling.

2008-08-14  Wakaba  <wakaba@suika.fam.cx>

++ html/WebHACC/Language/ChangeLog	14 Aug 2008 15:50:38 -0000
	* Base.pm, CSS.pm, CacheManifest.pm, DOM.pm, Default.pm,
	HTML.pm, WebIDL.pm, XML.pm: Set |layer_applicable|
	or |layer_uncertain| flag appropriately.

2008-08-14  Wakaba  <wakaba@suika.fam.cx>

++ html/WebHACC/ChangeLog	14 Aug 2008 15:48:38 -0000
	* Input.pm: Methods |generate_transfer_sections|
	and |generate_http_header_section| are moved to HTTP
	subclass, since they are irrelevant to non-HTTP inputs.
	(_get_document): Forbidden host error was not represented
	by WebHACC::Input::Error subclass.
	(WebHACC::Input::Error generate_transfer_sections): Use
	role name for the section.
	(WebHACC::Input::HTTPError generate_transfer_sections): New method
	added, since the main superclass, i.e. WebHACC::Input::Error,
	no longer dumps HTTP headers due to the change mentioned above.

	* Output.pm (start_section): New roles "transfer-errors" and "result".

	* Result.pm (parent_result): New attribute.
	(layer_applicable, layer_uncertain): New methods to set flags.
	(add_error): Natural language strings are now handled
	by the catalog mechanism.  Use new scoring mechanism.
	(generate_result_section): Use catalog for all natural
	language strings.  Table generation is now much more sophiscated
	that it was.  Support for subdoc result summary.  Support
	for the column of the number of informational message.  Support
	for "N/A" status.

2008-08-14  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 package WebHACC::Language::Base;
2     use strict;
3    
4     sub new ($) {
5     die "$0: No constructor is defined for " . ref $_[0];
6     } # new
7    
8 wakaba 1.2 ## NOTE:
9     ## Language ->input, ->output, ->result
10     ## Input
11     ## Output ->input
12     ## Result ->output
13    
14 wakaba 1.1 sub input ($;$) {
15     if (@_ > 1) {
16     if (defined $_[1]) {
17     $_[0]->{input} = $_[1];
18     } else {
19     delete $_[0]->{input};
20     }
21     }
22    
23     return $_[0]->{input};
24     } # input
25    
26     sub output ($;$) {
27     if (@_ > 1) {
28     if (defined $_[1]) {
29     $_[0]->{output} = $_[1];
30     } else {
31     delete $_[0]->{output};
32     }
33     }
34    
35     return $_[0]->{output};
36     } # output
37    
38     sub result ($;$) {
39     if (@_ > 1) {
40     if (defined $_[1]) {
41     $_[0]->{result} = $_[1];
42     } else {
43     delete $_[0]->{result};
44     }
45     }
46    
47     return $_[0]->{result};
48     } # result
49    
50     sub onsubdoc ($;$) {
51     if (@_ > 1) {
52     if (defined $_[1]) {
53     $_[0]->{onsubdoc} = $_[1];
54     } else {
55     delete $_[0]->{onsubdoc};
56     }
57     }
58    
59     return $_[0]->{onsubdoc} || sub { };
60     } # onsubdoc
61    
62     sub generate_syntax_error_section ($) {
63 wakaba 1.2 die "$0: Syntactical checking for " . (ref $_[0]) . " is not supported";
64 wakaba 1.1 } # generate_syntax_error_section
65    
66     sub generate_structure_dump_section ($) {
67     #
68     } # generate_structure_dump_section
69    
70     sub generate_structure_error_section ($) {
71     my $self = shift;
72    
73     my $out = $self->output;
74    
75 wakaba 1.5 $out->start_section (role => 'structure-errors');
76     $out->start_error_list (role => 'structure-errors');
77 wakaba 1.7 $self->result->layer_applicable ('structure');
78 wakaba 1.5
79     $self->result->add_error (input => $self->input,
80     level => 'u',
81     layer => 'structure',
82     type => 'media type not supported:structure',
83     text => $self->input->{media_type});
84    
85     $out->end_error_list (role => 'structure-errors');
86 wakaba 1.1 $out->end_section;
87 wakaba 1.7
88     $self->result->layer_uncertain ('semantics');
89 wakaba 1.1 } # generate_structure_error_section
90    
91     sub source_charset ($) {
92     return 'utf-8';
93     } # source_charset
94    
95     sub generate_source_string_section ($) {
96     my $self = shift;
97     my $input = $self->input;
98    
99     my $s;
100     unless ($input->{is_char_string}) {
101     open my $byte_stream, '<', \($input->{s});
102     require Message::Charset::Info;
103     my $charset = Message::Charset::Info->get_by_iana_name
104     ($self->source_charset);
105     my ($char_stream, $e_status) = $charset->get_decode_handle
106     ($byte_stream, allow_error_reporting => 1, allow_fallback => 1);
107     return unless $char_stream;
108    
109     $char_stream->onerror (sub {
110     my (undef, $type, %opt) = @_;
111     if ($opt{octets}) {
112     ${$opt{octets}} = "\x{FFFD}";
113     }
114     });
115    
116     my $t = '';
117     while (1) {
118     my $c = $char_stream->getc;
119     last unless defined $c;
120     $t .= $c;
121     }
122     $s = \$t;
123     ## TODO: Output for each line, don't concat all of lines.
124     } else {
125     $s = \($input->{s});
126     }
127    
128     my $out = $self->output;
129     my $i = 1;
130 wakaba 1.6 $out->start_section (role => 'source');
131 wakaba 1.1 $out->start_tag ('ol', lang => '');
132    
133     if (length $$s) {
134     while ($$s =~ /\G([^\x0D\x0A]*?)(?>\x0D\x0A?|\x0A)/gc) {
135     $out->start_tag ('li', id => 'line-' . $i);
136     $out->text ($1);
137     $i++;
138     }
139     if ($$s =~ /\G([^\x0D\x0A]+)/gc) {
140     $out->start_tag ('li', id => 'line-' . $i);
141     $out->text ($1);
142     }
143     } else {
144     $out->start_tag ('li', id => 'line-1');
145     }
146     $out->end_tag ('ol');
147 wakaba 1.4 $out->add_source_to_parse_error_list ('parse-errors-list');
148 wakaba 1.6 $out->end_section;
149 wakaba 1.1 } # generate_source_string_section
150    
151     sub generate_additional_sections ($) {
152     my $self = shift;
153     $self->generate_url_section;
154     } # generate_additional_sections
155    
156     sub generate_url_section ($) {
157     my $self = shift;
158     my $urls = $self->{add_info}->{uri} || {};
159     return unless keys %$urls;
160    
161     ## NOTE: URIs contained in the DOM (i.e. in HTML or XML documents),
162     ## except for those in RDF triples.
163     ## TODO: URIs in CSS
164    
165     my $out = $self->output;
166     $out->start_section (id => 'urls', title => 'URLs');
167     $out->start_tag ('dl');
168    
169     my $input = $self->input;
170     my $result = $self->result;
171    
172     for my $url (sort {$a cmp $b} keys %$urls) {
173     $out->start_tag ('dt');
174     $out->url ($url);
175     $out->start_tag ('dd');
176 wakaba 1.2 $out->link_to_webhacc ('Check conformance of this document', url => $url);
177 wakaba 1.1 $out->html ('<dd>Found in: <ul>');
178     for my $entry (@{$urls->{$url}}) {
179 wakaba 1.3 $out->start_tag ('li');
180     $out->node_link ($entry->{node});
181 wakaba 1.1 if (keys %{$entry->{type} or {}}) {
182     $out->text (' (');
183     $out->text (join ', ', map {
184     {
185     hyperlink => 'Hyperlink',
186     resource => 'Link to an external resource',
187     namespace => 'Namespace URI',
188     cite => 'Citation or link to a long description',
189     embedded => 'Link to an embedded content',
190     base => 'Base URI',
191     action => 'Submission URI',
192     }->{$_}
193     or
194     $_
195     } keys %{$entry->{type}});
196     $out->text (')');
197     }
198     }
199     $out->end_tag ('ul');
200     }
201     $out->end_tag ('dl');
202     $out->end_section;
203     } # generate_url_section
204    
205     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24