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