« blib/lib/Bio/Graphics/Browser2/Session.pm
↑ Summary
blib/conf/MobyServices/b64_encoded_jpeg_renderer.pm »
| 1 | package MobyServices::b64_encoded_gif_renderer; | ||
| 2 | use strict; | ||
| 3 | use XML::LibXML; | ||
| 4 | use MOBY::MobyXMLConstants; | ||
| 5 | our @ISA = qw(Exporter); | ||
| 6 | use File::Temp qw/ tempfile /; | ||
| 7 | our @EXPORT_OK = qw(render type); | ||
| 8 | use MIME::Base64; | ||
| 9 | |||
| 10 | sub types { | ||
| 11 | return ["b64_encoded_gif"]; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub render { | ||
| 15 | my ($DOM, $htmldir,$imgdir) = @_; | ||
| 16 | my $content; | ||
| 17 | $content = &getStringContent($DOM); | ||
| 18 | $content =~ s/^\s+//; $content =~ s/\s+$//; | ||
| 19 | my $bindata = decode_base64($content); | ||
| 20 | my ($fh, $filename) = tempfile( DIR => "$htmldir/$imgdir/", SUFFIX=> ".gif" ); | ||
| 21 | $filename =~ /(\w+\.gif)$/; | ||
| 22 | $filename = $1; | ||
| 23 | binmode($fh); | ||
| 24 | print $fh $bindata; | ||
| 25 | close $fh; | ||
| 26 | return ("<img src='$imgdir/$filename'>"); | ||
| 27 | } | ||
| 28 | |||
| 29 | sub getStringContent { | ||
| 30 | my ($ROOT) = @_; | ||
| 31 | my $content; | ||
| 32 | my @childnodes = $ROOT->childNodes; | ||
| 33 | foreach (@childnodes){ | ||
| 34 | next unless ($_->nodeType == ELEMENT_NODE); | ||
| 35 | next unless ($_->localname eq "String"); | ||
| 36 | my $article = $_->getAttributeNode('articleName'); | ||
| 37 | $article = $_->getAttributeNode('moby:articleName') unless $article; | ||
| 38 | next unless $article; | ||
| 39 | next unless $article->getValue eq 'content'; # the articleName for String content of a text-xml node | ||
| 40 | foreach my $subnode($_->childNodes){ # if it is correct, then get the text content | ||
| 41 | next unless (($subnode->nodeType == TEXT_NODE) || ($subnode->nodeType == CDATA_SECTION_NODE)); | ||
| 42 | $content .=$subnode->textContent; | ||
| 43 | } | ||
| 44 | $ROOT->removeChild($_); | ||
| 45 | last; | ||
| 46 | } | ||
| 47 | return $content; | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; | ||
| 51 | |||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | b64_encoded_gif_renderer.pm - a renderer (HTML) for b64_encoded_gif type MOBY Objects | ||
| 56 | |||
| 57 | =head1 AUTHOR | ||
| 58 | |||
| 59 | Please report all bugs to Mark Wilkinson (markw at illuminae.com) | ||
| 60 | |||
| 61 | =head1 SYNOPSIS | ||
| 62 | |||
| 63 | just put the renderer in your gbrowse.conf/MobyServices folder | ||
| 64 | and it will work. | ||
| 65 | |||
| 66 | =head1 DESCRIPTION | ||
| 67 | |||
| 68 | This renderer returns HTML that fits between the | ||
| 69 | <td> tags in a web-page to display the content | ||
| 70 | of a b64_encoded_gif (or ontological child of) object. | ||
| 71 | |||
| 72 | =head1 METHODS | ||
| 73 | |||
| 74 | The module has two methods: | ||
| 75 | |||
| 76 | =over | ||
| 77 | |||
| 78 | =item type | ||
| 79 | |||
| 80 | this returns a scalar indicating the MOBY Object | ||
| 81 | Class that this renderer is designed to handle. Objects | ||
| 82 | of this type, or objects that inherit from this type, | ||
| 83 | will be passed to this renderer. | ||
| 84 | |||
| 85 | =item render | ||
| 86 | |||
| 87 | This is called with three pieces of data which may or may not | ||
| 88 | be useful to your script: | ||
| 89 | |||
| 90 | =over | ||
| 91 | |||
| 92 | =item 1) $data - an XML::DOM object | ||
| 93 | representing the deserialized MOBY object | ||
| 94 | |||
| 95 | |||
| 96 | =item 2) $htmldir - the full path to the directory serving your html | ||
| 97 | |||
| 98 | e.g. /usr/local/apache/htdocs/ | ||
| 99 | |||
| 100 | (this is the HTDOCS parameter you specified | ||
| 101 | when you installed Gbrowse) | ||
| 102 | |||
| 103 | =item 3) $imgdir - the additional path information to a writable directory for images | ||
| 104 | |||
| 105 | e.g. /gbrowse/tmp | ||
| 106 | |||
| 107 | (this is the folder specified in the tmpimages parameter | ||
| 108 | in your organism.conf file) | ||
| 109 | |||
| 110 | |||
| 111 | =back | ||
| 112 | |||
| 113 | =back | ||
| 114 | |||
| 115 | =head1 RETURNS | ||
| 116 | |||
| 117 | The subroutine should return two pieces of data: | ||
| 118 | |||
| 119 | =over | ||
| 120 | |||
| 121 | =item 1) An HTML representation of the Object | ||
| 122 | |||
| 123 | this will appear between <td></td> tags in the webpage | ||
| 124 | |||
| 125 | =item 2) A boolean indicating whether the renderer has parsed all sub-objects, or just the top level object | ||
| 126 | |||
| 127 | '1' indicates that the renderer has fully parsed the Object XML | ||
| 128 | '0' indicates that you need Gbrowse to follow child objects | ||
| 129 | and render them independently | ||
| 130 | |||
| 131 | =back | ||
| 132 | |||
| 133 | =cut |