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