1 |
package WebHACC::Language::CacheManifest; |
2 |
use strict; |
3 |
require WebHACC::Language::Base; |
4 |
push our @ISA, 'WebHACC::Language::Base'; |
5 |
|
6 |
sub new ($) { |
7 |
my $self = bless {}, shift; |
8 |
return $self; |
9 |
} # new |
10 |
|
11 |
sub generate_syntax_error_section ($) { |
12 |
my $self = shift; |
13 |
|
14 |
require Whatpm::CacheManifest; |
15 |
|
16 |
my $out = $self->output; |
17 |
|
18 |
$self->result->layer_uncertain ('charset'); |
19 |
|
20 |
$out->start_section (role => 'parse-errors'); |
21 |
$out->start_error_list (role => 'parse-errors'); |
22 |
$self->result->layer_applicable ('syntax'); |
23 |
|
24 |
my $input = $self->input; |
25 |
my $result = $self->result; |
26 |
|
27 |
$self->result->layer_uncertain ('encode') unless $input->{is_char_string}; |
28 |
|
29 |
my $m = $input->{is_char_string} ? 'parse_char_string' : 'parse_byte_string'; |
30 |
$self->{structure} = Whatpm::CacheManifest->$m |
31 |
($input->{s}, $input->{uri}, $input->{base_uri}, sub { |
32 |
$result->add_error (@_, layer => 'syntax', index_has_link => 1); |
33 |
}); |
34 |
|
35 |
$out->end_error_list (role => 'parse-errors'); |
36 |
$out->end_section; |
37 |
} # generate_syntax_error_section |
38 |
|
39 |
sub generate_structure_dump_section ($) { |
40 |
my $self = shift; |
41 |
my $manifest = $self->{structure}; |
42 |
|
43 |
my $out = $self->output; |
44 |
|
45 |
$out->start_section (role => 'structure'); |
46 |
|
47 |
$out->html (qq[<dl><dt>Explicit entries</dt>]); |
48 |
my $i = 0; |
49 |
for my $uri (@{$manifest->[0]}) { |
50 |
$out->start_tag ('dd', id => 'index-' . $i++); |
51 |
$out->url ($uri); |
52 |
} |
53 |
|
54 |
$out->html (qq[<dt>Fallback entries</dt><dd> |
55 |
<table><thead><tr><th scope=row>Oppotunistic Caching Namespace</th> |
56 |
<th scope=row>Fallback Entry</tr><tbody>]); |
57 |
for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) { |
58 |
$out->start_tag ('tr'); |
59 |
|
60 |
$out->start_tag ('td', id => 'index-' . $i++); |
61 |
$out->url ($uri); |
62 |
|
63 |
$out->start_tag ('td', id => 'index-' . $i++); |
64 |
$out->url ($manifest->[1]->{$uri}); |
65 |
} |
66 |
|
67 |
$out->html (qq[</table><dt>Online whitelist</dt>]); |
68 |
for my $uri (@{$manifest->[2]}) { |
69 |
$out->start_tag ('dd', id => 'index-' . $i++); |
70 |
$out->url ($uri); |
71 |
} |
72 |
|
73 |
$out->end_section; |
74 |
} # generate_structure_dump_section |
75 |
|
76 |
sub generate_structure_error_section ($) { |
77 |
my $self = shift; |
78 |
|
79 |
my $out = $self->output; |
80 |
|
81 |
$out->start_section (role => 'structure-errors'); |
82 |
$out->start_error_list (role => 'structure-errors'); |
83 |
$self->result->layer_applicable ('structure'); |
84 |
|
85 |
my $result = $self->result; |
86 |
|
87 |
Whatpm::CacheManifest->check_manifest ($self->{structure}, sub { |
88 |
$result->add_error (@_, layer => 'structure'); |
89 |
}); |
90 |
|
91 |
$out->end_error_list; |
92 |
$out->end_section; |
93 |
} # generate_structure_error_section |
94 |
|
95 |
sub source_charset ($) { |
96 |
return 'utf-8'; |
97 |
} # source_charset |
98 |
|
99 |
1; |