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