Changeset 23167


Ignore:
Timestamp:
2010-10-19T14:14:18+13:00 (14 years ago)
Author:
davidb
Message:

GreenstoneXMLPlugin used to (or at least in theory used to) to be able to process files without them needing to be fed down the pipeline from ArchiveInfPlugin; however, this has not been tested for a long time. A very long time. It's certainly the case its not working now. For some new work, we need GreenstoneXMLPlugin to work correctly when processing doc.xml (and associated files all in the same folder) directly. For this new use, this occurs when it is placed in the *import* folder (part of the DL talkback scheme). The mods being commited here to the plugin give this capability back to the plugin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/GreenstoneXMLPlugin.pm

    r22841 r23167  
    3333
    3434use Encode;
     35use File::Basename;
    3536
    3637use ReadXMLFile;
     
    8081    $self->{'metadata_value'} = "";
    8182    $self->{'content'} = "";
     83    $self->{'metadata_read_store'} = {};
    8284
    8385#    # Currently used to store information for previous values controls. In
     
    8789    return bless $self, $class;
    8890}
     91
     92
     93
     94
     95sub metadata_read {
     96    my $self = shift (@_);
     97    my ($pluginfo, $base_dir, $file, $block_hash,
     98    $extrametakeys, $extrametadata, $extrametafile,
     99    $processor, $maxdocs, $gli) = @_;
     100
     101    my $outhandle = $self->{'outhandle'};
     102
     103    # can we process this file??
     104    my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
     105    return undef unless $self->can_process_this_file($filename_full_path);
     106
     107    $file =~ s/^[\/\\]+//; # $file often begins with / so we'll tidy it up
     108   
     109    print $outhandle "GreenstoneXMLlugin: setting up block list for $file\n"
     110    if $self->{'verbosity'} > 1;
     111
     112    my $line;
     113    if (open(GIN,"<:utf8",$filename_full_path)) {
     114
     115    while (defined($line=<GIN>)) {
     116        if ($line =~ m@<Metadata\s+name="gsdlassocfile">([^:]*):(?:[^:]*):(?:[^:]*)</Metadata>@) {
     117        my $gsdl_assoc_file = $1;
     118
     119        my $dirname = dirname($filename_full_path);
     120        my $full_gsdl_assoc_filename = &util::filename_cat($dirname,$gsdl_assoc_file);
     121        if ($self->{'verbosity'}>2) {
     122            print $outhandle "  Storing block list item: $full_gsdl_assoc_filename\n";
     123        }
     124
     125        $block_hash->{'file_blocks'}->{$full_gsdl_assoc_filename} = 1;
     126        }
     127    }
     128
     129    close(GIN);
     130    }
     131    else {
     132   
     133    print $outhandle "Error: Failed to open $file in GreenstoneXMLPlugin::metadata_read()\n";
     134    print $outhandle "       $!\n";
     135    }
     136
     137
     138    $self->{'metadata_read_store'}->{$filename_full_path} = 1;
     139
     140    return 1;
     141}
     142
    89143
    90144sub xml_start_document {
     
    221275    my $self = shift(@_);
    222276
     277    my $filename = $self->{'filename'};
     278
    223279    # create a new document
    224     $self->{'doc_obj'} = new doc ();
     280    if (defined $self->{'metadata_read_store'}->{$filename}) {
     281    # Being processed as part of *import* phase
     282    # (i.e. was in import directory)
     283    $self->SUPER::open_document(@_);
     284    delete $self->{'metadata_read_store'}->{$filename};
     285    }
     286    else {
     287    # Otherwise being processed as part of the *buildcol* phase
     288    # (i.e. named directly by ArchiveInf plugin)
     289    $self->{'doc_obj'} = new doc();
     290    }
     291
    225292    $self->{'section'} = "";
    226293}
Note: See TracChangeset for help on using the changeset viewer.