Ignore:
Timestamp:
2017-11-14T13:40:47+13:00 (6 years ago)
Author:
ak19
Message:

Committing unused and untested new subroutines, in case they may prove useful in future.

File:
1 edited

Legend:

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

    r32061 r32062  
    6767my $getmeta_action_table =
    6868{
     69    # unused and untested
     70    # when DocEdit=1, need to retrieve a doc's full text (or doc section's full text) from archives
     71    "get-archives-text" => {
     72    'compulsory-args' => [ "d" ] },
     73    #'compulsory-args' => [ "d" ],
     74    #'optional-args' => [ "section" ] },
     75   
    6976    #GET METHODS
    7077    "get-import-metadata" => {
     
    888895}
    889896
     897# unused and untested
     898sub get_archives_text
     899{
     900    my $self = shift @_;
     901
     902    my $username  = $self->{'username'};
     903    my $collect   = $self->{'collect'};
     904    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     905#   my $gsdlhome  = $self->{'gsdlhome'};
     906    my $infodbtype = $self->{'infodbtype'};
     907
     908    # Obtain the collect dir
     909    my $site = $self->{'site'};
     910    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     911   
     912    my $archive_dir = &util::filename_cat($collect_dir, $collect, "archives");
     913
     914    # look up additional args
     915    my ($docid, $docid_secnum) = ($self->{'d'} =~ m/^(.*?)(\..*)?$/);
     916    $docid_secnum = "" if (!defined $docid_secnum);
     917   
     918    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     919    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
     920
     921    # This now stores the full pathname
     922    my $doc_filename = $doc_rec->{'doc-file'}->[0];
     923   
     924    my $metaname = undef;
     925    my $metapos = -1;
     926   
     927    $gsdl_cgi->generate_ok_message($self->get_metadata_from_archive_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, $docid_secnum));
     928
     929}
     930
    890931sub get_metadata_from_archive_xml
    891932{
     
    935976}
    936977
     978# unused and untested
     979sub get_text_from_archive_xml
     980{
     981    my $self = shift @_;
     982    my ($gsdl_cgi, $doc_xml_filename, $secid) = @_;
     983
     984    # To monitor which section/subsection number we are in
     985    my @start_rules = ('Section' => \&dxml_start_section);
     986
     987    # set the callback functions for the elements in doc.xml we're interested in, <Content>
     988    my @rules =
     989    (
     990        _default => 'raw',
     991        'Content' => \&gfdxml_text # gfdxml = get from doc xml?
     992    );
     993       
     994    my $parser = XML::Rules->new
     995    (
     996        start_rules => \@start_rules,
     997        rules => \@rules,
     998        output_encoding => 'utf8'
     999    );
     1000   
     1001    my $xml_in = "";
     1002    if (!open(MIN,"<$doc_xml_filename"))
     1003    {
     1004        $gsdl_cgi->generate_error("Unable to read in $doc_xml_filename: $!");
     1005    }
     1006    else
     1007    {
     1008        # Read them in
     1009        my $line;
     1010        while (defined ($line=<MIN>)) {
     1011            $xml_in .= $line;
     1012        }
     1013        close(MIN);
     1014
     1015        $parser->parse($xml_in, {secid => $secid});
     1016       
     1017        if(defined $parser->{'pad'}->{'textcontent'})
     1018        {
     1019            return $parser->{'pad'}->{'textcontent'};
     1020        }
     1021        else
     1022        {
     1023            return "";
     1024        }
     1025    }
     1026}
     1027
    9371028sub gfdxml_metadata
    9381029{
     
    9621053}
    9631054
     1055# unused and untested - for get_archives_text
     1056sub gfdxml_text
     1057{
     1058    my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_;
     1059   
     1060    if($parser->{'parameters'}->{'secid'} eq $parser->{'parameters'}->{'curr_section_num'})
     1061    {
     1062        $parser->{'pad'}->{'textcontent'} = $attrHash->{'_content'}; # the textnode content
     1063
     1064    }
     1065    else {
     1066        return;
     1067    }
     1068}
    9641069
    9651070sub dxml_start_section
     
    9931098    }
    9941099    else {
    995     # back up to parent section => lopp off tail
     1100    # back up to parent section => lop off tail
    9961101    $new_secnum = $old_secnum;
    9971102    $new_secnum =~ s/\.\d+$//;
     
    10011106    $parser->{'parameters'}->{'curr_section_num'}   = $new_secnum;
    10021107   
    1003     1;
     1108    1;
    10041109}
    10051110
Note: See TracChangeset for help on using the changeset viewer.