Index: /main/trunk/greenstone2/perllib/plugins/WordPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/WordPlugin.pm	(revision 22427)
+++ /main/trunk/greenstone2/perllib/plugins/WordPlugin.pm	(revision 22428)
@@ -26,10 +26,11 @@
 
 use ConvertBinaryFile;
+
+
 use strict;
 no strict 'refs'; # allow filehandles to be variables and viceversa
 
-sub BEGIN {
-    @WordPlugin::ISA = ('ConvertBinaryFile');
-}
+
+# @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile
 
 my $arguments =
@@ -44,4 +45,45 @@
       ];
 
+
+my $opt_windows_args = [ { 'name' => "windows_scripting",
+			   'desc' => "{WordPlugin.windows_scripting}",
+			   'type' => "flag",
+			   'reqd' => "no" } ];
+
+my $opt_office_args = [ { 'name' => "metadata_fields",
+			  'desc' => "{WordPlugin.metadata_fields}",
+			  'type' => "string",
+			  'deft' => "Title" },
+			{ 'name' => "level1_header",
+			  'desc' => "{StructuredHTMLPlugin.level1_header}",
+			  'type' => "regexp",
+			  'reqd' => "no",
+			  'deft' => "" },
+			{ 'name' => "level2_header",
+			  'desc' => "{StructuredHTMLPlugin.level2_header}",
+			  'type' => "regexp",
+			  'reqd' => "no",
+			  'deft' => "" },
+			{ 'name' => "level3_header",
+			  'desc' => "{StructuredHTMLPlugin.level3_header}",
+			  'type' => "regexp",
+			  'reqd' => "no",
+			  'deft' => "" },
+			{ 'name' => "title_header",
+			  'desc' => "{StructuredHTMLPlugin.title_header}",
+			  'type' => "regexp",
+			  'reqd' => "no",
+			  'deft' => "" },
+			{ 'name' => "delete_toc",
+			  'desc' => "{StructuredHTMLPlugin.delete_toc}",
+			  'type' => "flag",
+			  'reqd' => "no" },
+			{ 'name' => "toc_header",
+			  'desc' => "{StructuredHTMLPlugin.toc_header}",
+			  'type' => "regexp",
+			  'reqd' => "no",
+			  'deft' => "" } ];
+
+
 my $options = { 'name'     => "WordPlugin",
 		'desc'     => "{WordPlugin.desc}",
@@ -56,49 +98,26 @@
     push(@$pluginlist, $class);
 
+    my $openoffice_ext_installed;
+    eval("require OpenOfficeConverter");
+    if ($@) {
+	# Useful debugging statement if there is a syntax error in OpenOfficeConverter	
+	print STDERR "$@\n";
+
+	push(@WordPlugin::ISA,"ConvertBinaryFile");
+	$openoffice_ext_installed = 0;
+    }
+    else {
+	# Successfully found
+	print STDERR "WordPlugin: OpenOffice Extension to Greenstone detected\n";
+	push(@WordPlugin::ISA,"OpenOfficeConverter");
+	$openoffice_ext_installed = 1;
+    }
+
     if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
-	my $ws_arg = [ { 'name' => "windows_scripting",
-			 'desc' => "{WordPlugin.windows_scripting}",
-			 'type' => "flag",
-		         'reqd' => "no" },
-		       { 'name' => "metadata_fields",
-			 'desc' => "{WordPlugin.metadata_fields}",
-			 'type' => "string",
-			 'deft' => "Title" },
-		       { 'name' => "metadata_field_separator",
-			 'desc' => "{HTMLPlugin.metadata_field_separator}",
-			 'type' => "string",
-			 'deft' => "" },
-		       { 'name' => "level1_header",
-			 'desc' => "{StructuredHTMLPlugin.level1_header}",
-			 'type' => "regexp",
-			 'reqd' => "no",
-			 'deft' => "" },
-		       { 'name' => "level2_header",
-			 'desc' => "{StructuredHTMLPlugin.level2_header}",
-			 'type' => "regexp",
-			 'reqd' => "no",
-			 'deft' => "" },
-		       { 'name' => "level3_header",
-			 'desc' => "{StructuredHTMLPlugin.level3_header}",
-			 'type' => "regexp",
-			 'reqd' => "no",
-			 'deft' => "" },
-		       { 'name' => "title_header",
-			 'desc' => "{StructuredHTMLPlugin.title_header}",
-			 'type' => "regexp",
-			 'reqd' => "no",
-			 'deft' => "" },
-		       { 'name' => "delete_toc",
-			 'desc' => "{StructuredHTMLPlugin.delete_toc}",
-			 'type' => "flag",
-			 'reqd' => "no" },
-		       { 'name' => "toc_header",
-			 'desc' => "{StructuredHTMLPlugin.toc_header}",
-			 'type' => "regexp",
-			 'reqd' => "no",
-			 'deft' => "" }
-		       ];
-	
-	push(@$arguments,@$ws_arg);
+	push(@$arguments,@$opt_windows_args);
+	push(@$arguments,@$opt_office_args);
+    }
+    elsif ($openoffice_ext_installed) {
+	push(@$arguments,@$opt_office_args);
     }
 
@@ -106,5 +125,30 @@
     push(@{$hashArgOptLists->{"OptList"}},$options);
 
-    my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
+    my $self = {};
+    my $outhandle;
+
+    if ($openoffice_ext_installed) {
+	$self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists);
+	$outhandle = $self->{'outhandle'};
+
+	if ($self->{'openoffice_conversion_available'}) {
+	    print $outhandle "WordPlugin: OpenOffice scripting functionality available\n";
+
+	    # Override default process expression
+	    $self->{'process_exp'} = q^(?i)\.(doc|dot|docx|odt)$^;
+
+	    if ($self->{'openoffice_scripting'}) {
+		print $outhandle "WordPlugin: Activating OpenOffice scripting functionality\n";
+	    }
+	}
+	else {
+	    print $outhandle "WordPlugin: Unable to run 'soffice'\n";
+	    print $outhandle "WordPlugin: Defaulting to ConvertBinaryFile inheritence\n";
+	}
+    }
+    else {
+	$self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
+	$outhandle = $self->{'outhandle'};
+    }
 
     if ($self->{'info_only'}) {
@@ -116,6 +160,18 @@
     $self->{'file_type'} = "Word";
 
-    #this is passed through to gsConvert.pl by ConvertBinaryFile.pm
-    $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
+    if ($self->{'windows_scripting'}) {
+	$self->{'convert_options'} = "-windows_scripting";
+	$self->{'office_scripting'} = 1;
+    }    
+    if ($self->{'openoffice_scripting'}) {
+	if ($self->{'windows_scripting'}) {
+	    print $outhandle "Warning: Cannot have -windows_scripting and -openoffice_scripting\n";
+	    print $outhandle "         on at the same time.  Defaulting to -windows_scripting\n";
+	}
+	else {
+	    $self->{'convert_options'} = "-openoffice_scripting";
+	    $self->{'office_scripting'} = 1;
+	}
+    }
 
     # we always save as utf-8
@@ -125,5 +181,5 @@
 
     my $secondary_plugin_options = $self->{'secondary_plugin_options'};
-    if (defined $self->{'windows_scripting'}) { 
+    if (defined $self->{'office_scripting'}) { 
 	if (!defined $secondary_plugin_options->{'StructuredHTMLPlugin'}){
 	    $secondary_plugin_options->{'StructuredHTMLPlugin'} = [];
@@ -134,5 +190,5 @@
 	    push (@$structhtml_options, "-metadata_fields","Title,GENERATOR,date,author<Creator>");
 	    push (@$structhtml_options, "-title_sub", '^(Page\s+\d+)?(\s*1\s+)?');
-	    push (@$structhtml_options, "-description_tags") if $self->{'windows_scripting'};
+	    push (@$structhtml_options, "-description_tags") if $self->{'windows_scripting'}; # What about openoffice???
 	    push (@$structhtml_options, "-extract_language") if $self->{'extract_language'};
 	    push (@$structhtml_options, "-delete_toc") if $self->{'delete_toc'};
@@ -187,4 +243,18 @@
 }
 
+sub init {
+    my $self = shift (@_);
+    my ($verbosity, $outhandle, $failhandle) = @_;
+    
+    $self->SUPER::init($verbosity,$outhandle,$failhandle);
+}
+
+sub deinit {
+    # called only once, after all plugin passes have been done
+    my ($self) = @_;
+    
+    $self->SUPER::deinit();
+}
+
 sub get_default_process_exp {
     my $self = shift (@_);
