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