package AbstractPlugin;

use ReadTextFile;
use niupepautil;
use doc;

use strict;
no strict 'refs'; # allow filehandles to be variables and viceversa
no strict 'subs';

sub BEGIN {
    @AbstractPlugin::ISA = ('ReadTextFile');
}

my $arguments =
    [
     { 'name' => "process_exp",
        'desc' => "{BasePlugin.process_exp}",
        'type' => "regexp",
        'deft' => &get_default_process_exp(),
        'reqd' => "no" } ,

 ];

my $options = { 'name'     => "AbstractPlugin",
		'desc'     => "Simple plugin for processing abstracts in niupepa collection",
		'abstract' => "no",
		'inherits' => "yes",
		'args'     => $arguments };

sub new {
    my ($class) = shift (@_);
    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
    push(@$pluginlist, $class);

    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
    push(@{$hashArgOptLists->{"OptList"}},$options);

    my $self = new ReadTextFile($pluginlist, $inputargs, $hashArgOptLists);

    return bless $self, $class;
}

sub get_default_process_exp {
    my $self = shift (@_);

    return q^(?i)\.abstract$^;
}

# do plugin specific processing of doc_obj
sub process {
    my $self = shift (@_);
    my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
    my $outhandle = $self->{'outhandle'};
    
    my ($filename_full_path, $filename_no_path) =  &util::get_full_filenames($base_dir, $file); 
    # filename is like 01_1_1.abstract, OID is 01_1_1abstract
    my $OID = $filename_no_path;
    $OID =~ s/\.//;
    $doc_obj->set_OID ($OID);
    print STDERR "set oid $OID\n";
    my ($full_dir) = $filename_full_path =~ /^(.*?)([^\/\\]*)$/;
    # set metadata from meta.txt
    &niupepautil::set_main_metadata($doc_obj, $full_dir, $self->{'verbosity'});

    my $cursection = $doc_obj->get_top_section();
    #$doc_obj->set_utf8_metadata_element ($cursection, "doctype", "Description");

    my $paper_id = $OID;
    $paper_id =~ s/abstract//;
    $doc_obj->set_utf8_metadata_element ($cursection, 'Title', &niupepautil::get_title_string($paper_id));

    # just add the html text as is to the section
    
    $doc_obj->add_utf8_text($cursection, $$textref);

    return 1;
}

1;
    
