| 1 |
package WebHACC::Language::CacheManifest; |
package WebHACC::Language::CacheManifest; |
| 2 |
use strict; |
use strict; |
| 3 |
require WebHACC::Language::Base; |
require WebHACC::Language::Base; |
| 4 |
push our @ISA, 'WebHACC::Langauge::Base'; |
push our @ISA, 'WebHACC::Language::Base'; |
| 5 |
|
|
| 6 |
sub new ($) { |
sub new ($) { |
| 7 |
my $self = bless {}, shift; |
my $self = bless {}, shift; |
| 15 |
|
|
| 16 |
my $out = $self->output; |
my $out = $self->output; |
| 17 |
|
|
| 18 |
$out->start_section (id => 'parse-errors', title => 'Parse Errors'); |
$self->result->layer_uncertain ('charset'); |
| 19 |
$out->start_tag ('dl', id => 'parse-errors-list'); |
|
| 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; |
my $input = $self->input; |
| 25 |
my $result = $self->result; |
my $result = $self->result; |
| 26 |
|
|
| 27 |
my $onerror = sub { |
$self->result->layer_uncertain ('encode') unless $input->{is_char_string}; |
|
my (%opt) = @_; |
|
|
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); |
|
|
$out->html (qq[<dt class="$cls">], get_error_label ($input, \%opt)); |
|
|
$type =~ tr/ /-/; |
|
|
$type =~ s/\|/%7C/g; |
|
|
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
|
|
$out->html (qq[<dd class="$cls">], get_error_level_label (\%opt) . $msg); |
|
|
|
|
|
add_error ('syntax', \%opt => $result); |
|
|
}; |
|
| 28 |
|
|
| 29 |
my $m = $input->{is_char_string} ? 'parse_char_string' : 'parse_byte_string'; |
my $m = $input->{is_char_string} ? 'parse_char_string' : 'parse_byte_string'; |
| 30 |
$self->{structure} = Whatpm::CacheManifest->$m |
$self->{structure} = Whatpm::CacheManifest->$m |
| 31 |
($input->{s}, $input->{uri}, $input->{base_uri}, $onerror); |
($input->{s}, $input->url, $input->{base_uri}, sub { |
| 32 |
|
$result->add_error (@_, layer => 'syntax', index_has_link => 1); |
| 33 |
$out->end_tag ('dl'); |
}); |
| 34 |
|
|
| 35 |
|
$out->end_error_list (role => 'parse-errors'); |
| 36 |
$out->end_section; |
$out->end_section; |
| 37 |
} # generate_syntax_error_section |
} # generate_syntax_error_section |
| 38 |
|
|
| 39 |
sub generate_structure_dump_section ($) { |
sub generate_structure_dump_section ($) { |
| 40 |
my $self = shift; |
my $self = shift; |
| 41 |
my $manifest = $self->{structure}; |
my $manifest = $self->{structure} || [[], {}, []]; # undef if it is not a manifest. |
| 42 |
|
|
| 43 |
$self->start_section (id => 'dump-manifest', title => 'Cache Manifest'); |
my $out = $self->output; |
| 44 |
|
|
| 45 |
$self->html (qq[<dl><dt>Explicit entries</dt>]); |
$out->start_section (role => 'structure'); |
|
my $i = 0; |
|
|
for my $uri (@{$manifest->[0]}) { |
|
|
$out->start_tag ('dd', id => 'index-' . $i++); |
|
|
$out->url ($uri); |
|
|
} |
|
| 46 |
|
|
| 47 |
$out->html (qq[<dt>Fallback entries</dt><dd> |
$out->start_tag ('dl'); |
| 48 |
<table><thead><tr><th scope=row>Oppotunistic Caching Namespace</th> |
my $i = 0; |
|
<th scope=row>Fallback Entry</tr><tbody>]); |
|
|
for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) { |
|
|
$out->start_tag ('tr'); |
|
| 49 |
|
|
| 50 |
$out->start_tag ('td', id => 'index-' . $i++); |
$out->start_tag ('dt'); |
| 51 |
$out->url ($uri); |
$out->nl_text ('Explicit entries'); |
| 52 |
|
if (@{$manifest->[0]}) { |
| 53 |
|
for my $uri (@{$manifest->[0]}) { |
| 54 |
|
$out->start_tag ('dd', id => 'index-' . $i++); |
| 55 |
|
$out->url ($uri); |
| 56 |
|
} |
| 57 |
|
} else { |
| 58 |
|
$out->start_tag ('dd', class => 'no-entry'); |
| 59 |
|
$out->nl_text ('No entry'); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
$out->start_tag ('td', id => 'index-' . $i++); |
$out->start_tag ('dt'); |
| 63 |
$out->url ($manifest->[1]->{$uri}); |
$out->nl_text ('Fallback entries'); |
| 64 |
|
if (keys %{$manifest->[1]}) { |
| 65 |
|
$out->start_tag ('dd', class => 'manifest-fallbacks'); |
| 66 |
|
for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) { |
| 67 |
|
$out->start_tag ('p', id => 'index-' . $i++); |
| 68 |
|
$out->nl_text ('Opportunistic caching namespace'); |
| 69 |
|
$out->text (': '); |
| 70 |
|
$out->url ($uri); |
| 71 |
|
|
| 72 |
|
$out->start_tag ('p', id => 'index-' . $i++); |
| 73 |
|
$out->nl_text ('Fallback entry'); |
| 74 |
|
$out->text (': '); |
| 75 |
|
$out->url ($manifest->[1]->{$uri}); |
| 76 |
|
} |
| 77 |
|
} else { |
| 78 |
|
$out->start_tag ('dd', class => 'no-entry'); |
| 79 |
|
$out->nl_text ('No entry'); |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
$out->html (qq[</table><dt>Online whitelist</dt>]); |
$out->start_tag ('dt'); |
| 83 |
for my $uri (@{$manifest->[2]}) { |
$out->nl_text ('Online whitelist'); |
| 84 |
$out->start_tag ('dd', id => 'index-' . $i++); |
if (@{$manifest->[2]}) { |
| 85 |
$out->url ($uri); |
for my $uri (@{$manifest->[2]}) { |
| 86 |
|
$out->start_tag ('dd', id => 'index-' . $i++); |
| 87 |
|
$out->url ($uri); |
| 88 |
|
} |
| 89 |
|
} else { |
| 90 |
|
$out->start_tag ('dd', class => 'no-entry'); |
| 91 |
|
$out->nl_text ('No entry'); |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
|
$out->end_tag ('dl'); |
| 95 |
|
|
| 96 |
$out->end_section; |
$out->end_section; |
| 97 |
} # generate_structure_dump_section |
} # generate_structure_dump_section |
| 98 |
|
|
| 101 |
|
|
| 102 |
my $out = $self->output; |
my $out = $self->output; |
| 103 |
|
|
| 104 |
$out->start_section (id => 'document-errors', title => 'Document Errors'); |
$out->start_section (role => 'structure-errors'); |
| 105 |
$out->start_tag ('dl'); |
$out->start_error_list (role => 'structure-errors'); |
| 106 |
|
$self->result->layer_applicable ('structure'); |
| 107 |
|
|
| 108 |
my $result = $out->result; |
my $result = $self->result; |
| 109 |
|
|
| 110 |
Whatpm::CacheManifest->check_manifest ($self->{structure}, sub { |
Whatpm::CacheManifest->check_manifest ($self->{structure}, sub { |
| 111 |
my %opt = @_; |
$result->add_error (@_, layer => 'structure'); |
|
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}, $opt{node}); |
|
|
$type =~ tr/ /-/; |
|
|
$type =~ s/\|/%7C/g; |
|
|
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
|
|
$out->html (qq[<dt class="$cls">] . get_error_label ($input, \%opt) . |
|
|
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"); |
|
|
add_error ('structure', \%opt => $result); |
|
| 112 |
}); |
}); |
| 113 |
|
|
| 114 |
|
$out->end_error_list; |
| 115 |
$out->end_section; |
$out->end_section; |
| 116 |
} # generate_structure_error_section |
} # generate_structure_error_section |
| 117 |
|
|