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