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

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: #
1.2     ! www         9: # 10/19,10/21,10/23 Gerd Kortemeyer
1.1       www        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
1.2     ! www        63: 
        !            64: my $creationdate=localtime($content{'creationdate'});
        !            65: my $lastrevisiondate=localtime($content{'lastrevisiondate'});
1.1       www        66:   
                     67:   $r->print(<<ENDHEAD);
                     68: <html><head><title>Catalog Information</title></head>
                     69: <body bgcolor="#FFFFFF">
                     70: <h1>Catalog Information</h1>
                     71: <h2>$content{'title'}</h2>
                     72: <h3>Author(s): $content{'author'}</h3>
                     73: <b>Subject:</b> $content{'subject'}<br>
                     74: <b>Keyword(s):</b> $content{'keywords'}<br>
                     75: <b>Notes:</b> $content{'notes'}<br>
                     76: <b>Abstract:</b>
                     77: <blockquote>$content{'abstract'}</blockquote>
                     78: <hr>
                     79: <b>MIME Type:</b> $content{'mime'}<br>
                     80: <b>Language:</b> $content{'language'}<br>
1.2     ! www        81: <b>Creation Date:</b> $creationdate<br>
        !            82: <b>Last Revision Date:</b> $lastrevisiondate<br>
1.1       www        83: <b>Publisher/Owner:</b> $content{'owner'}<br>
                     84: <b>Copyright/Distribution:</b> $content{'copyright'}
                     85: <hr>
                     86: ENDHEAD
                     87:   delete($content{'title'});
                     88:   delete($content{'author'});
                     89:   delete($content{'subject'});
                     90:   delete($content{'keywords'});
                     91:   delete($content{'notes'});
                     92:   delete($content{'abstract'});
                     93:   delete($content{'mime'});
                     94:   delete($content{'language'});
                     95:   delete($content{'creationdate'});
                     96:   delete($content{'lastrevisiondate'});
                     97:   delete($content{'owner'});
                     98:   delete($content{'copyright'});
                     99:   map {
                    100:       my ($value,$name)=split(/\_\_dis\_\_/,$content{$_});
                    101:       unless ($name) { $name=$_; }
                    102:       $r->print('<b>'.$name.':</b> '.$value.'<br>');
                    103:   } sort keys %content;
                    104:   $r->print('</body></html>');
                    105:   return OK;
                    106: }
                    107: 
                    108: 1;
                    109: __END__
                    110: 
                    111: 
                    112: 
                    113: 
                    114: 
                    115: 
                    116: 

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