1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
package RDF::RDFa::Generator::HTML::Hidden;
use 5.008;
use base qw'RDF::RDFa::Generator::HTML::Head';
use strict;
use XML::LibXML qw':all';
use warnings;
our $VERSION = '0.201_01';
sub injection_site
{
return '//xhtml:body';
}
sub nodes
{
my ($proto, $model) = @_;
my $self = (ref $proto) ? $proto : $proto->new;
my $stream = $self->_get_stream($model);
my @nodes;
my $rootnode = XML::LibXML::Element->new('i');
$rootnode->setNamespace('http://www.w3.org/1999/xhtml', undef, 1);
$rootnode->setAttribute('style','display:none');
my $subjects = {};
while (my $st = $stream->next)
{
my $s = $st->subject->is_resource ?
$st->subject->abs :
('_:'.$st->subject->value);
push @{ $subjects->{$s} }, $st;
}
foreach my $s (keys %$subjects)
{
my $node = $rootnode->addNewChild('http://www.w3.org/1999/xhtml', 'i');
$self->_process_subject($subjects->{$s}->[0], $node);
foreach my $st (@{ $subjects->{$s} })
{
my $node2 = $node->addNewChild('http://www.w3.org/1999/xhtml', 'i');
$self->_process_predicate($st, $node2)
->_process_object($st, $node2);
}
}
if (defined($self->{'version'}) && $self->{'version'} == 1.1
and $self->{'prefix_attr'}) {
if (defined($self->{namespacemap}->rdfa)) {
$rootnode->setAttribute('prefix', $self->{namespacemap}->rdfa->as_string);
}
} else {
while (my ($prefix, $nsURI) = $self->{namespacemap}->each_map) {
$rootnode->setNamespace($nsURI->as_string, $prefix, 0);
}
}
push @nodes, $rootnode;
return @nodes if wantarray;
my $nodelist = XML::LibXML::NodeList->new;
$nodelist->push(@nodes);
return $nodelist;
}
sub _process_subject
{
my ($self, $st, $node) = @_;
if (defined $self->{'base'}
and $st->subject->is_resource
and $st->subject->abs eq $self->{'base'})
{ $node->setAttribute('about', ''); }
elsif ($st->subject->is_resource)
{ $node->setAttribute('about', $st->subject->abs); }
else
{ $node->setAttribute('about', '[_:'.$st->subject->value.']'); }
return $self;
}
1;
|