Index: /gs3-extensions/pharos/trunk/perllib/plugins/PharosImageIndexer.pm
===================================================================
--- /gs3-extensions/pharos/trunk/perllib/plugins/PharosImageIndexer.pm	(revision 21294)
+++ /gs3-extensions/pharos/trunk/perllib/plugins/PharosImageIndexer.pm	(revision 21294)
@@ -0,0 +1,146 @@
+###########################################################################
+#
+# PharosImageIndexer - helper plugin that does image conversion using ImageMagick
+#
+# 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 PharosImageIndexer;
+
+use PrintInfo;
+
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and viceversa
+
+use gsprintf 'gsprintf';
+
+BEGIN {
+    @PharosImageIndexer::ISA = ('PrintInfo');
+}
+
+my $arguments = [
+		 { 'name' => "disable_pharos_imageis",
+		   'desc' => "{PharosImageIndexer.disable_pharos_imageis}",
+		   'type' => "flag",
+		   'reqd' => "no" },
+		 ];
+
+my $options = { 'name' => "PharosImageIndexer",
+		'desc' => "{PharosImageIndexer.desc}",
+		'abstract' => "yes",
+		'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 PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
+
+
+    return bless $self, $class;
+
+}
+
+# needs to be called after BasePlugin init, so that outhandle is set up.
+sub init {
+    my $self = shift(@_);
+    
+    return if ($self->{'disable_pharos_imageis'});
+
+    # Check that Pharos is installed and available on the path 
+    my $pharos_available = 1;
+    ## change for windows!
+    #my $result = `phraros-imageis-identify 2>&1`;
+    #my $return_value = $?;
+    #if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 256) || $return_value == -1) {  # Linux and Windows return different values for "program not found"
+    #    $pharos_available = 0;
+    #}
+    
+    $self->{'pharos_available'} = 1; #$pharos_available;
+    
+    if ($self->{'pharos_available'} == 0) {
+	my $outhandle = $self->{'outhandle'};
+	&gsprintf($outhandle, "PharosImageIndexer: Pharos not installed\n");
+    }
+
+}
+	
+sub begin {
+
+}
+
+sub removeold {
+    my $self = shift (@_);
+    my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
+    
+    print STDERR "removeold pharos plugin\n";
+    return if ($self->{'disable_pharos_imageis'});
+
+    if (!$self->{'pharos_available'}) {
+	print STDERR "pharos not available, not doing a removeold\n";
+	return;
+    }
+    # need to delete everything from the derby database.
+    my $collection = &util::get_current_collection_name();
+    my $cmd = "perl -S pharos-imageis-delete.pl $collection *.jpg 2>&1";
+    print STDERR "Running command $cmd\n";
+    my $result = `$cmd`;
+    my $return_value = $?;
+    my $outhandle = $self->{'outhandle'};
+    if ($return_value != 0) {
+	print $outhandle "Pharos Indexing failed to clear database for collection $collection\n";
+    }
+    print $outhandle "$result\n";
+    
+}
+
+sub pharos_index_image {
+    my $self = shift(@_);
+
+    return if ($self->{'disable_pharos_imageis'} || !$self->{'pharos_available'});
+    # pass in the jpg thumbnail, and the doc obj
+    my ($filename_full_path, $doc_obj) = @_;
+    print STDERR "pharos indexing $filename_full_path\n";
+
+    my $collection = &util::get_current_collection_name();
+    my $id = $doc_obj->get_OID();
+
+    my $cmd = "perl -S pharos-imageis-add.pl $collection $filename_full_path $id 2>&1";
+    print STDERR "Running command $cmd\n";
+    my $result = `$cmd`;
+
+    my $return_value = $?;
+    my $outhandle = $self->{'outhandle'};
+    if ($return_value != 0) {
+	print $outhandle "Pharos Indexing failed for $filename_full_path, $id\n";
+    }
+    print $outhandle "$result\n";
+    
+}
+
+
+1;	
Index: /gs3-extensions/pharos/trunk/perllib/plugins/PharosImagePlugin.pm
===================================================================
--- /gs3-extensions/pharos/trunk/perllib/plugins/PharosImagePlugin.pm	(revision 21294)
+++ /gs3-extensions/pharos/trunk/perllib/plugins/PharosImagePlugin.pm	(revision 21294)
@@ -0,0 +1,93 @@
+###########################################################################
+#
+# 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 removeold {
+    my $self = shift (@_);
+    my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
+    
+    $self->SUPER::removeold(@_);
+    $self->PharosImageIndexer::removeold(@_);
+   
+}
+
+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;	
