Annotation of loncom/interface/lonmeta.pm, revision 1.1

1.1     ! www         1: # The LearningOnline Network with CAPA
        !             2: #
        !             3: # Metadata display handler
        !             4: #
        !             5: # (TeX Content Handler
        !             6: #
        !             7: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
        !             8: #
        !             9: # 10/19,10/21 Gerd Kortemeyer
        !            10: 
        !            11: package Apache::lonmeta;
        !            12: 
        !            13: use strict;
        !            14: use Apache::File;
        !            15: use Apache::Constants qw(:common);
        !            16: use HTML::TokeParser;
        !            17: 
        !            18: 
        !            19: # ================================================= Unpack metadata into a hash
        !            20: 
        !            21: sub unpackagemeta {
        !            22:     my ($datastring,$fordisplay)=@_;
        !            23:     my %content=();
        !            24:     my $parser=HTML::TokeParser->new(\$datastring);
        !            25:     my $token;
        !            26:     while ($token=$parser->get_token) {
        !            27:        if ($token->[0] eq 'S') {
        !            28: 	   my $entry=$token->[1];
        !            29:            my $value=$parser->get_text('/'.$entry);
        !            30:            if (($token->[2]->{'display'}) && ($fordisplay)) {
        !            31: 	       $value.='__dis__'.$token->[2]->{'display'};
        !            32:            }
        !            33:            $content{$entry}=$value;
        !            34:        }
        !            35:     }
        !            36:     return %content;
        !            37: }
        !            38: 
        !            39: # ================================================================ Main Handler
        !            40: 
        !            41: sub handler {
        !            42:   my $r=shift;
        !            43:   my @metacontents;
        !            44:   my %content;
        !            45: 
        !            46: # ----------------------------------------------------------- Set document type
        !            47: 
        !            48:   $r->content_type('text/html');
        !            49:   $r->send_http_header;
        !            50: 
        !            51:   return OK if $r->header_only;
        !            52: 
        !            53: # ------------------------------------------------------------------- Read file
        !            54: 
        !            55:   {
        !            56:     my $fh=Apache::File->new($r->filename);
        !            57:     @metacontents=<$fh>;
        !            58:   }
        !            59: 
        !            60:   %content=&unpackagemeta(join("\n",@metacontents),1);
        !            61: 
        !            62: # --------------------------------------------------------------- Render Output
        !            63:   
        !            64:   $r->print(<<ENDHEAD);
        !            65: <html><head><title>Catalog Information</title></head>
        !            66: <body bgcolor="#FFFFFF">
        !            67: <h1>Catalog Information</h1>
        !            68: <h2>$content{'title'}</h2>
        !            69: <h3>Author(s): $content{'author'}</h3>
        !            70: <b>Subject:</b> $content{'subject'}<br>
        !            71: <b>Keyword(s):</b> $content{'keywords'}<br>
        !            72: <b>Notes:</b> $content{'notes'}<br>
        !            73: <b>Abstract:</b>
        !            74: <blockquote>$content{'abstract'}</blockquote>
        !            75: <hr>
        !            76: <b>MIME Type:</b> $content{'mime'}<br>
        !            77: <b>Language:</b> $content{'language'}<br>
        !            78: <b>Creation Date:</b> $content{'creationdate'}<br>
        !            79: <b>Last Revision Date:</b> $content{'lastrevisiondate'}<br>
        !            80: <b>Publisher/Owner:</b> $content{'owner'}<br>
        !            81: <b>Copyright/Distribution:</b> $content{'copyright'}
        !            82: <hr>
        !            83: ENDHEAD
        !            84:   delete($content{'title'});
        !            85:   delete($content{'author'});
        !            86:   delete($content{'subject'});
        !            87:   delete($content{'keywords'});
        !            88:   delete($content{'notes'});
        !            89:   delete($content{'abstract'});
        !            90:   delete($content{'mime'});
        !            91:   delete($content{'language'});
        !            92:   delete($content{'creationdate'});
        !            93:   delete($content{'lastrevisiondate'});
        !            94:   delete($content{'owner'});
        !            95:   delete($content{'copyright'});
        !            96:   map {
        !            97:       my ($value,$name)=split(/\_\_dis\_\_/,$content{$_});
        !            98:       unless ($name) { $name=$_; }
        !            99:       $r->print('<b>'.$name.':</b> '.$value.'<br>');
        !           100:   } sort keys %content;
        !           101:   $r->print('</body></html>');
        !           102:   return OK;
        !           103: }
        !           104: 
        !           105: 1;
        !           106: __END__
        !           107: 
        !           108: 
        !           109: 
        !           110: 
        !           111: 
        !           112: 
        !           113: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>