/[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.6 - (show annotations) (download)
Thu Aug 14 11:58:32 2008 UTC (16 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +2 -3 lines
++ ChangeLog	14 Aug 2008 11:57:12 -0000
	* cc-style.css: Revised such that subdocument check results
	do not look stupid and that new class name rules
	for level-* and layer-* is reflected by icons.

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

++ html/WebHACC/Language/ChangeLog	14 Aug 2008 11:58:26 -0000
	* Base.pm: Use "role" for source code sections.

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

++ html/WebHACC/ChangeLog	14 Aug 2008 11:58:10 -0000
	* Output.pm (start_section): Roles set class="", too.  New "source"
	role for source code sections.

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

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 ## NOTE:
9 ## Language ->input, ->output, ->result
10 ## Input
11 ## Output ->input
12 ## Result ->output
13
14 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 die "$0: Syntactical checking for " . (ref $_[0]) . " is not supported";
64 } # 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 $out->start_section (role => 'structure-errors');
76 $out->start_error_list (role => 'structure-errors');
77
78 $self->result->add_error (input => $self->input,
79 level => 'u',
80 layer => 'structure',
81 type => 'media type not supported:structure',
82 text => $self->input->{media_type});
83
84 $out->end_error_list (role => 'structure-errors');
85 $out->end_section;
86 } # generate_structure_error_section
87
88 sub source_charset ($) {
89 return 'utf-8';
90 } # source_charset
91
92 sub generate_source_string_section ($) {
93 my $self = shift;
94 my $input = $self->input;
95
96 my $s;
97 unless ($input->{is_char_string}) {
98 open my $byte_stream, '<', \($input->{s});
99 require Message::Charset::Info;
100 my $charset = Message::Charset::Info->get_by_iana_name
101 ($self->source_charset);
102 my ($char_stream, $e_status) = $charset->get_decode_handle
103 ($byte_stream, allow_error_reporting => 1, allow_fallback => 1);
104 return unless $char_stream;
105
106 $char_stream->onerror (sub {
107 my (undef, $type, %opt) = @_;
108 if ($opt{octets}) {
109 ${$opt{octets}} = "\x{FFFD}";
110 }
111 });
112
113 my $t = '';
114 while (1) {
115 my $c = $char_stream->getc;
116 last unless defined $c;
117 $t .= $c;
118 }
119 $s = \$t;
120 ## TODO: Output for each line, don't concat all of lines.
121 } else {
122 $s = \($input->{s});
123 }
124
125 my $out = $self->output;
126 my $i = 1;
127 $out->start_section (role => 'source');
128 $out->start_tag ('ol', lang => '');
129
130 if (length $$s) {
131 while ($$s =~ /\G([^\x0D\x0A]*?)(?>\x0D\x0A?|\x0A)/gc) {
132 $out->start_tag ('li', id => 'line-' . $i);
133 $out->text ($1);
134 $i++;
135 }
136 if ($$s =~ /\G([^\x0D\x0A]+)/gc) {
137 $out->start_tag ('li', id => 'line-' . $i);
138 $out->text ($1);
139 }
140 } else {
141 $out->start_tag ('li', id => 'line-1');
142 }
143 $out->end_tag ('ol');
144 $out->add_source_to_parse_error_list ('parse-errors-list');
145 $out->end_section;
146 } # generate_source_string_section
147
148 sub generate_additional_sections ($) {
149 my $self = shift;
150 $self->generate_url_section;
151 } # generate_additional_sections
152
153 sub generate_url_section ($) {
154 my $self = shift;
155 my $urls = $self->{add_info}->{uri} || {};
156 return unless keys %$urls;
157
158 ## NOTE: URIs contained in the DOM (i.e. in HTML or XML documents),
159 ## except for those in RDF triples.
160 ## TODO: URIs in CSS
161
162 my $out = $self->output;
163 $out->start_section (id => 'urls', title => 'URLs');
164 $out->start_tag ('dl');
165
166 my $input = $self->input;
167 my $result = $self->result;
168
169 for my $url (sort {$a cmp $b} keys %$urls) {
170 $out->start_tag ('dt');
171 $out->url ($url);
172 $out->start_tag ('dd');
173 $out->link_to_webhacc ('Check conformance of this document', url => $url);
174 $out->html ('<dd>Found in: <ul>');
175 for my $entry (@{$urls->{$url}}) {
176 $out->start_tag ('li');
177 $out->node_link ($entry->{node});
178 if (keys %{$entry->{type} or {}}) {
179 $out->text (' (');
180 $out->text (join ', ', map {
181 {
182 hyperlink => 'Hyperlink',
183 resource => 'Link to an external resource',
184 namespace => 'Namespace URI',
185 cite => 'Citation or link to a long description',
186 embedded => 'Link to an embedded content',
187 base => 'Base URI',
188 action => 'Submission URI',
189 }->{$_}
190 or
191 $_
192 } keys %{$entry->{type}});
193 $out->text (')');
194 }
195 }
196 $out->end_tag ('ul');
197 }
198 $out->end_tag ('dl');
199 $out->end_section;
200 } # generate_url_section
201
202 1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24