Changeset 27007

Show
Ignore:
Timestamp:
05.03.2013 12:04:19 (7 years ago)
Author:
davidb
Message:

Additional case for storing metadata now handled: that of when the mode is set to 'override' but when no exising metadata exits. The code now spots that no existing value was found and switches to treating it effectively like an "accumulate" request.

Some code type up performed also (tweaks to some debugging output), and the concatenation of strings before printing them out through the GSDLcgi module (before it was calling the GSDLcgi module function each time, which added MIME header information each time).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm

    r25891 r27007  
    726726    my $metamode = $parser->{'parameters'}->{'metamode'}; 
    727727     
    728     print STDERR "**** IN METADATA \n"; 
     728    print STDERR "**** Processing closing </Metadata> tag\n"; 
    729729     
    730730    my $opt_doc_secnum = $parser->{'parameters'}->{'secnum'}; 
     
    784784    my $metamode = $parser->{'parameters'}->{'metamode'}; 
    785785 
    786     print STDERR "**** IN DESCRIPTION! \n"; 
     786    print STDERR "**** Processing a closing </Description> tag \n"; 
    787787     
    788788    # Accumulate the metadata 
    789     # NOTE: This appends new metadata element to all description fields. 
    790     # If there are multiple Sections/SubSections, the new metadata block will get appended to all of them 
    791     if (($metamode eq "accumulate")) { 
    792         print STDERR "**** ACCUMULATE! \n"; 
    793         # If get to here and metamode is override, the this means there  
    794         # was no existing value to overide => treat as an append operation 
    795  
    796         # Tack a new metadata tag on to the end of the <Metadata>+ block 
    797         my $metaname = $parser->{'parameters'}->{'metaname'}; 
    798         my $metavalue = $parser->{'parameters'}->{'metavalue'}; 
    799      
    800         my $metadata_attr = {  
    801             '_content' => $metavalue,  
    802             'name' => $metaname,  
    803             'mode' => "accumulate"  
    804         }; 
    805  
    806         my $append_metadata = [ "Metadata" => $metadata_attr ]; 
    807         my $description_content = $attrHash->{'_content'}; 
    808      
    809         print STDERR "**** appending to doc.xml\n"; 
    810  
    811         if (ref($description_content)) { 
    812             # got some existing interesting nested content 
    813             push(@$description_content, "    ", $append_metadata ,"\n        "); 
    814         } 
    815         else { 
    816             #description_content is most likely a string such as "\n" 
    817             $attrHash->{'_content'} = [$description_content, "    ", $append_metadata ,"\n" ]; 
    818         } 
    819          
    820         $parser->{'parameters'}->{'metamode'} = "done"; 
    821     } 
     789 
     790    if (($metamode eq "accumulate") || ($metamode eq "override")) { 
     791        if ($metamode eq "override") { 
     792        print "No metadata value to override.  Switching 'metamode' to accumulate\n"; 
     793        } 
     794 
     795        # If get to here and metamode is override, the this means there  
     796        # was no existing value to overide => treat as an append operation 
     797         
     798        # Tack a new metadata tag on to the end of the <Metadata>+ block 
     799        my $metaname = $parser->{'parameters'}->{'metaname'}; 
     800        my $metavalue = $parser->{'parameters'}->{'metavalue'}; 
     801         
     802        my $metadata_attr = {  
     803        '_content' => $metavalue,  
     804        'name' => $metaname,  
     805        'mode' => "accumulate"  
     806        }; 
     807         
     808        my $append_metadata = [ "Metadata" => $metadata_attr ]; 
     809        my $description_content = $attrHash->{'_content'}; 
     810         
     811        print "Appending metadata to doc.xml\n"; 
     812         
     813        if (ref($description_content)) { 
     814        # got some existing interesting nested content 
     815        push(@$description_content, "    ", $append_metadata ,"\n        "); 
     816        } 
     817        else { 
     818        #description_content is most likely a string such as "\n" 
     819        $attrHash->{'_content'} = [$description_content, "    ", $append_metadata ,"\n" ]; 
     820        } 
     821         
     822        $parser->{'parameters'}->{'metamode'} = "done"; 
     823    }        
    822824    else { 
    823         print STDERR "**** NOT ACCUMULATE?!? \n"; 
     825        # metamode most likely "done" signifying that it has already found a position to add the metadata to.  
     826##      print STDERR "**** NOT ACCUMULATE?!? \n"; 
    824827    } 
    825828 
     
    916919    my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos, $metamode, $opt_secnum, $prevmetavalue) = @_; 
    917920 
    918     $gsdl_cgi->generate_ok_message("IN EDIT DOC XML\n****************************\n"); 
    919     $gsdl_cgi->generate_ok_message("doc_xml_filename = $doc_xml_filename\n"); 
    920     $gsdl_cgi->generate_ok_message("metaname = $metaname\n"); 
    921     $gsdl_cgi->generate_ok_message("metavalue = $metavalue\n"); 
    922     $gsdl_cgi->generate_ok_message("metapos = $metapos\n"); 
    923     $gsdl_cgi->generate_ok_message("metamode = $metamode\n"); 
    924     $gsdl_cgi->generate_ok_message("opt_secnum = $opt_secnum\n"); 
    925     $gsdl_cgi->generate_ok_message("prevmetavalue = $prevmetavalue\n"); 
     921    my $info_mess = <<RAWEND; 
     922**************************** 
     923  edit_doc_xml() 
     924**************************** 
     925doc_xml_filename = $doc_xml_filename 
     926metaname = $metaname 
     927metavalue = $metavalue 
     928metapos = $metapos 
     929metamode = $metamode 
     930opt_secnum = $opt_secnum 
     931prevmetavalue = $prevmetavalue 
     932**************************** 
     933RAWEND 
     934 
     935    $gsdl_cgi->generate_message($info_mess); 
    926936     
    927937    # To monitor which section/subsection number we are in 
     
    955965    my ($gsdl_cgi, $archive_dir, $collect_dir, $collect, $infodbtype, $docid, $metaname, $metapos, $metavalue, $metamode, $prevmetavalue) = @_; 
    956966     
    957     $gsdl_cgi->generate_ok_message("IN SET ARCHIVES METADATA ENTRY\n****************************\n"); 
    958     $gsdl_cgi->generate_ok_message("archive_dir = $archive_dir\n"); 
    959     $gsdl_cgi->generate_ok_message("collect_dir = $collect_dir\n"); 
    960     $gsdl_cgi->generate_ok_message("collect = $collect\n"); 
    961     $gsdl_cgi->generate_ok_message("infodbtype = $infodbtype\n"); 
    962     $gsdl_cgi->generate_ok_message("docid = $docid\n"); 
    963     $gsdl_cgi->generate_ok_message("metaname = $metaname\n"); 
    964     $gsdl_cgi->generate_ok_message("metapos = $metapos\n"); 
    965     $gsdl_cgi->generate_ok_message("metavalue = $metavalue\n"); 
    966     $gsdl_cgi->generate_ok_message("metamode = $metamode\n"); 
    967     $gsdl_cgi->generate_ok_message("prevmetavalue = $prevmetavalue\n"); 
     967    my $info_mess = <<RAWEND; 
     968**************************** 
     969  set_archives_metadata_entry() 
     970**************************** 
     971archive_dir = $archive_dir 
     972collect_dir = $collect_dir 
     973collect = $collect 
     974infodbtype = $infodbtype 
     975docid = $docid 
     976metaname = $metaname 
     977metapos = $metapos 
     978metavalue = $metavalue 
     979metamode = $metamode 
     980prevmetavalue = $prevmetavalue 
     981**************************** 
     982RAWEND 
     983 
     984    $gsdl_cgi->generate_message($info_mess); 
    968985     
    969986    # Obtain the doc.xml path for the specified docID