[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Thu Jul 17 19:51:43 UTC 2003


mwilkinson
Thu Jul 17 15:51:43 EDT 2003
Update of /home/repository/moby/moby-live/Perl/scripts
In directory pub.open-bio.org:/tmp/cvs-serv15831

Modified Files:
	MOBY-Client05.cgi 
Log Message:
The newfangled Client has some intelligence v.v. the types of objects it is trying to display, and will interpret and display image data so long as the image is NOT embedded deep within another object (this simple client only burrows down one level into an object, and everything deeper is displayed as textualized XML)

moby-live/Perl/scripts MOBY-Client05.cgi,1.15,1.16
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/MOBY-Client05.cgi,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Perl/scripts/MOBY-Client05.cgi	2003/07/12 18:51:02	1.15
+++ /home/repository/moby/moby-live/Perl/scripts/MOBY-Client05.cgi	2003/07/17 19:51:43	1.16
@@ -231,13 +231,12 @@
         $OBJ .= "<b>NameSpace: </b>$ns<br>
                  <b>ID:$id</b><br>";
         
-        foreach ($Object->getChildNodes()){
+        my $type = &_what_am_i($Object); # returns b64jpeg, b64gif, TEXT
+        my $alldata;
+        foreach ($Object->getChildNodes()){  # this is TERRIBLE parsing of a MOBY Object!!  It only goes one level deep, but it is sufficient for a prototype client
             my $data;
             if (($_->getNodeType == TEXT_NODE) || ($_->getNodeType == CDATA_SECTION_NODE)){
-                $data = $_->toString;
-                $data =~ s/^\s+//; $data =~ s/\s+$//; chomp $data;
-                next unless $data;
-                $data = "<pre>".($_->toString)."</pre>";
+                $alldata .= $_->toString;  # deal with the text content of this node separately from the object content
             } elsif ($_->getNodeType == ELEMENT_NODE){
                 next if  ($_->getTagName =~ /CrossReference/);
                 my $article = $_->getAttributeNode('articleName');
@@ -250,11 +249,27 @@
                 foreach my $content($_->getChildNodes){
                     $data .= $content->toString if (($content->getNodeTypeName eq "TEXT_NODE") || ($_->getNodeTypeName eq "CDATA_SECTION_NODE"));
                 }
-            }
+            }            
 #                $OBJ .= "".escapeHTML($Payload->item($_)->toString)."<br>";
-            $OBJ .= "$data<br>";
+            $data && ($OBJ .= "$data<br>");
+        }
+        if ($alldata){
+            use MIME::Base64;
+            use File::Temp qw/ tempfile /;
+            if ($type =~ /b64/){
+                $alldata = decode_base64($alldata);
+                my ($fh, $filename);
+                ($fh, $filename) = tempfile( DIR => "/usr/local/apache/htdocs/tmp", SUFFIX=> ".jpeg" ) if ($type =~ /b64jpeg/);
+                ($fh, $filename) = tempfile( DIR => "/usr/local/apache/htdocs/tmp", SUFFIX=> ".gif" ) if ($type =~ /b64gif/);
+                binmode $fh;
+                print $fh $alldata;
+                close $fh;
+                $filename =~ s"^/usr/local/apache/htdocs/tmp/"";
+                $OBJ .="<br><IMG src=http://mobycentral.cbr.nrc.ca/tmp/$filename><br>";
+            } else {
+                $OBJ .= "<pre>$alldata</pre><BR>";
+            }
         }
-    
         $response .= "<td BGCOLOR = '#CCCCFF' valign='top' align='left'><SMALL>$XrefString$OBJ</SMALL></td></tr>\n"; #  HTML escaped XML of the object
     }
     $response .="</table>";
@@ -299,19 +314,42 @@
     my $doc = $parser->parse($result);
     my $moby = $doc->getDocumentElement();
 
-    my @objects; my @Xrefs; my $success = 0;
+    my @objects;
+    my @collections;
+    my @Xrefs;
+    my $success = 0;
     my $responses = $moby->getElementsByTagName('moby:queryResponse');
+    $responses ||= $moby->getElementsByTagName('queryResponse');
     foreach my $n(0..($responses->getLength - 1)){
         my $resp = $responses->item($n);
-        my $simples = $resp->getElementsByTagName('Simple');
-        $simples ||=$resp->getElementsByTagName('moby:Simple');
-        next unless $simples->item(0);
-        foreach my $Object($simples->item(0)->getChildNodes) {
-            next unless $Object->getNodeType == ELEMENT_NODE;
-            $success = 1;
-            my $Object_text = $Object->toString;
-            push @objects,$Object_text;
-            _LOG("Found response object $Object_text .\n");
+        foreach my $response_component($resp->getChildNodes){ 
+            next unless $response_component->getNodeType == ELEMENT_NODE;
+            if (($response_component->getTagName eq "Simple") || ($response_component->getTagName eq "moby:Simple")){
+
+                my $simples = $resp->getElementsByTagName('Simple');
+                $simples ||=$resp->getElementsByTagName('moby:Simple');
+                next unless $simples->item(0);
+                foreach my $Object($simples->item(0)->getChildNodes) {
+                    next unless $Object->getNodeType == ELEMENT_NODE;
+                    $success = 1;
+                    my $Object_text = $Object->toString;
+                    push @objects,$Object_text;
+                    _LOG("Found response object $Object_text .\n");
+                }
+            } elsif (($response_component->getTagName eq "Collection") || ($response_component->getTagName eq "moby:Collection")){
+                foreach my $simple($response_component->getChildNodes){
+                    next unless $simple->getNodeType == ELEMENT_NODE;
+                    next unless (($simple->getTagName eq "Simple") || ($simple->getTagName eq "moby:Simple"));
+                    foreach my $Object($simple->getChildNodes) {
+                        next unless $Object->getNodeType == ELEMENT_NODE;
+                        $success = 1;
+                        my $Object_text = $Object->toString;
+                        push @objects,$Object_text;
+                        _LOG("Found response object $Object_text .\n");
+                    }
+                }
+                push @collections, \@objects;    #I'm not using collections yet, so we just use Simples.
+            }
         }
     }
 
@@ -489,6 +527,21 @@
     return $response;
 }
 
+sub _what_am_i {
+    my ($ObjectDOM) = @_;
+    return "TEXT" unless $ObjectDOM;
+    my $OntologyTerm = $ObjectDOM->getTagName;
+    _LOG("Found type $OntologyTerm\n");
+    #my $MC = MOBY::Client::Central->new()
+    #$relationships = $MC->Relationships(objectType => $OntolgyTerm, Relationships => ["ISA"]);
+    # this SHOULD be done to traverse the ontology to check whether we have derived Image classes
+    # but to do this for every object would be painfully slow, so I am
+    # hard-coding the known image object types for now.  THIS IS NOT HOW IT SHOULD BE DONE!!!
+    return "b64gif" if $OntologyTerm =~ /b64_encoded_gif/;
+    return "b64jpeg" if $OntologyTerm =~ /b64_encoded_jpeg/;
+    return "TEXT";
+    
+}
 
 sub _sendError{
 	my ($mess) = @_;
@@ -503,7 +556,7 @@
 
 sub _LOG {
   return unless $debug;
-  open LOG, ">>/tmp/Client05LogOut.txt" or die "can't open logfile $!\n";
+  open LOG, ">>/tmp/Client051LogOut.txt" or die "can't open logfile $!\n";
   print LOG join "\n", @_;
   print LOG "\n---\n";
   close LOG;




More information about the MOBY-guts mailing list