###########################################################################
#
# PharosImagePlugin - an ImagePlugin that can also do pharos related tasks.
#
# A component of the Greenstone digital library software
# from the New Zealand Digital Library Project at the 
# University of Waikato, New Zealand.
#
# Copyright (C) 2008 New Zealand Digital Library Project
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###########################################################################
package PharosImagePlugin;

use ImagePlugin;
use PharosImageIndexer;

use strict;
no strict 'refs'; # allow filehandles to be variables and viceversa

use gsprintf 'gsprintf';

BEGIN {
    @PharosImagePlugin::ISA = ('ImagePlugin', 'PharosImageIndexer');
}

my $arguments = [
		 ];

my $options = { 'name' => "PharosImagePlugin",
		'desc' => "{PharosImagePlugin.desc}",
		'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);

    new PharosImageIndexer($pluginlist, $inputargs, $hashArgOptLists);
    my $self = new ImagePlugin($pluginlist, $inputargs, $hashArgOptLists);


    return bless $self, $class;

}

# needs to be called after BasePlugin init, so that outhandle is set up.
sub init {
    my $self = shift(@_);
    my ($verbosity, $outhandle, $failhandle) = @_;

    $self->SUPER::init(@_);
    $self->PharosImageIndexer::init();

}

sub remove_all {
    my $self = shift (@_);
    my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
    
    $self->SUPER::remove_all(@_);
    $self->PharosImageIndexer::remove_all(@_);
   
}

sub remove_one {
    my $self = shift (@_);
    my ($file, $oids) = @_;
    $self->SUPER::remove_one(@_);
    $self->PharosImageIndexer::remove_one(@_);
}

sub post_process_doc_obj {
    my $self = shift (@_);
    # options??
    my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
    $self->pharos_index_image(&util::filename_cat($base_dir, $file), $doc_obj);
}



1;	
