package MobyServices::b64_encoded_jpeg_renderer;
use strict;
use XML::LibXML;
use MOBY::MobyXMLConstants;
our @ISA = qw(Exporter);
use File::Temp qw/ tempfile /;
our @EXPORT_OK = qw(render type);
use MIME::Base64;
sub types {
return ["b64_encoded_jpeg"];
}
sub render {
my ($DOM, $htmldir,$imgdir) = @_;
my $content;
$content = &getStringContent($DOM);
$content =~ s/^\s+//; $content =~ s/\s+$//;
my $bindata = decode_base64($content);
my ($fh, $filename) = tempfile( DIR => "$htmldir/$imgdir/", SUFFIX=> ".jpg" );
$filename =~ /(\w+\.jpg)$/;
$filename = $1;
binmode($fh);
print $fh $bindata;
close $fh;
return ("");
}
sub getStringContent {
my ($ROOT) = @_;
my $content;
my @childnodes = $ROOT->childNodes;
foreach (@childnodes){
next unless ($_->nodeType == ELEMENT_NODE);
next unless ($_->localname eq "String");
my $article = $_->getAttributeNode('articleName');
$article = $_->getAttributeNode('moby:articleName') unless $article;
next unless $article;
next unless $article->getValue eq 'content'; # the articleName for String content of a text-xml node
foreach my $subnode($_->childNodes){ # if it is correct, then get the text content
next unless (($subnode->nodeType == TEXT_NODE) || ($subnode->nodeType == CDATA_SECTION_NODE));
$content .=$subnode->textContent;
}
$ROOT->removeChild($_);
last;
}
return $content;
}
1;
=head1 NAME
b64_encoded_jpeg_renderer.pm - a renderer (HTML) for b64_encoded_jpeg type MOBY Objects
=head1 AUTHOR
Please report all bugs to Mark Wilkinson (markw at illuminae.com)
=head1 SYNOPSIS
just put the renderer in your gbrowse.conf/MobyServices folder
and it will work.
=head1 DESCRIPTION
This renderer returns HTML that fits between the