Index: main/trunk/greenstone2/perllib/plugins/WordPlugin.pm
===================================================================
--- main/trunk/greenstone2/perllib/plugins/WordPlugin.pm	(revision 22514)
+++ main/trunk/greenstone2/perllib/plugins/WordPlugin.pm	(revision 22597)
@@ -41,5 +41,5 @@
     eval("require OpenOfficeConverter");
     if ($@) {
-	# Useful debugging statement if there is a syntax error in OpenOfficeConverter	
+	# Useful debugging statement if there is a syntax error in OpenOfficeConverter:
 	#print STDERR "$@\n";
 	@WordPlugin::ISA = ('ConvertBinaryFile');
@@ -174,7 +174,8 @@
     }
 
-    my $outhandle = $self->{'outhandle'};
     $self->{'filename_extension'} = "doc";
     $self->{'file_type'} = "Word";
+
+    my $outhandle = $self->{'outhandle'};
 
     if ($self->{'windows_scripting'}) {
@@ -193,65 +194,62 @@
     }
 
-    # we always save as utf-8
-#    if ($self->{'input_encoding'} eq "auto") {
-#	$self->{'input_encoding'} = "utf8";
-#    }
-
+    # check convert_to
+    if ($self->{'convert_to'} eq "auto") {
+	$self->{'convert_to'} = "html";
+    }
+    # windows or open office scripting, outputs structuredHTML
+    if (defined $self->{'office_scripting'}) {
+	$self->{'convert_to'} = "structuredhtml";
+    } 
+
+    # set convert_to_plugin and convert_to_ext
+    $self->ConvertBinaryFile::set_standard_convert_settings();
+ 
+    my $secondary_plugin_name = $self->{'convert_to_plugin'};
     my $secondary_plugin_options = $self->{'secondary_plugin_options'};
-    if (defined $self->{'office_scripting'}) { 
-	if (!defined $secondary_plugin_options->{'StructuredHTMLPlugin'}){
-	    $secondary_plugin_options->{'StructuredHTMLPlugin'} = [];
-	    my $structhtml_options = $secondary_plugin_options->{'StructuredHTMLPlugin'};
-	    
-	    # Instruct HTMLPlugin (when eventually accessed through read_into_doc_obj)
-	    # to extract these metadata fields from the HEAD META fields
-	    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->{'office_scripting'}; 
-	    push (@$structhtml_options, "-extract_language") if $self->{'extract_language'};
-	    push (@$structhtml_options, "-delete_toc") if $self->{'delete_toc'};
-	    push (@$structhtml_options, "-toc_header", $self->{'toc_header'}) if $self->{'toc_header'};
-	    push (@$structhtml_options, "-title_header", $self->{'title_header'}) if $self->{'title_header'};
-	    push (@$structhtml_options, "-level1_header", $self->{'level1_header'}) if $self->{'level1_header'};
-	    push (@$structhtml_options, "-level2_header", $self->{'level2_header'})if $self->{'level2_header'};
-	    push (@$structhtml_options, "-level3_header", $self->{'level3_header'}) if $self->{'level3_header'};
-	    push (@$structhtml_options, "-metadata_fields", $self->{'metadata_fields'}) if $self->{'metadata_fields'};
-	    push (@$structhtml_options, "-metadata_field_separator", $self->{'metadata_field_separator'}) if $self->{'metadata_field_separator'};
-	}
-    }
-    if (!defined $secondary_plugin_options->{'HTMLPlugin'}) {
-	$secondary_plugin_options->{'HTMLPlugin'} = [];
-    }
-    if (!defined $secondary_plugin_options->{'TextPlugin'}) {
-	$secondary_plugin_options->{'TextPlugin'} = [];
-    }
-
-    my $html_options = $secondary_plugin_options->{'HTMLPlugin'};
-    my $text_options = $secondary_plugin_options->{'TextPlugin'};
-    my $structhtml_options = $secondary_plugin_options->{'StructuredHTMLPlugin'};    
-    # tell the secondary plugins that they are processing tmp files
-    push(@$html_options, "-processing_tmp_files");
-    push(@$structhtml_options, "-processing_tmp_files");
-    
-    # wvWare will always produce html files encoded as utf-8, so make sure the secondary HTMLPlugin knows this
-    push(@$html_options,"-input_encoding", "utf8");
-    push(@$html_options,"-extract_language") if $self->{'extract_language'};
-    push(@$html_options, "-description_tags") if $self->{'description_tags'};
-
-    # Instruct HTMLPlugin (when eventually accessed through read_into_doc_obj)
-    # to extract these metadata fields from the HEAD META fields
-    push(@$html_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
-    push(@$html_options , "-title_sub", '^(Page\s+\d+)?(\s*1\s+)?');
+
+    if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
+	$secondary_plugin_options->{$secondary_plugin_name} = [];
+    }
+    my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
+
+    # following title_sub removes "Page 1" and a leading
+    # "1", which is often the page number at the top of the page. Bad Luck
+    # if your document title actually starts with "1 " - is there a better way?
+    push(@$specific_options , "-title_sub", '^(Page\s+\d+)?(\s*1\s+)?');
 
     my $associate_tail_re = $self->{'associate_tail_re'};
     if ((defined $associate_tail_re) && ($associate_tail_re ne "")) {
-	push(@$html_options, "-associate_tail_re", $associate_tail_re);
-	push(@$text_options, "-associate_tail_re", $associate_tail_re);
-	push(@$structhtml_options, "-associate_tail_re", $associate_tail_re) if defined $structhtml_options;
-    }
-
-    push(@$html_options, "-file_rename_method", "none");
-    push(@$text_options, "-file_rename_method", "none");
-    push(@$structhtml_options, "-file_rename_method", "none") if defined $structhtml_options;
+	push(@$specific_options, "-associate_tail_re", $associate_tail_re);
+    }
+    push(@$specific_options, "-file_rename_method", "none");
+
+    if ($secondary_plugin_name eq "StructuredHTMLPlugin") {
+	# Instruct HTMLPlugin (when eventually accessed through read_into_doc_obj)
+	# to extract these metadata fields from the HEAD META fields
+	push (@$specific_options, "-metadata_fields","Title,GENERATOR,date,author<Creator>");
+	push (@$specific_options, "-description_tags") if $self->{'office_scripting'}; 
+	push (@$specific_options, "-extract_language") if $self->{'extract_language'};
+	push (@$specific_options, "-delete_toc") if $self->{'delete_toc'};
+	push (@$specific_options, "-toc_header", $self->{'toc_header'}) if $self->{'toc_header'};
+	push (@$specific_options, "-title_header", $self->{'title_header'}) if $self->{'title_header'};
+	push (@$specific_options, "-level1_header", $self->{'level1_header'}) if $self->{'level1_header'};
+	push (@$specific_options, "-level2_header", $self->{'level2_header'})if $self->{'level2_header'};
+	push (@$specific_options, "-level3_header", $self->{'level3_header'}) if $self->{'level3_header'};
+	push (@$specific_options, "-metadata_fields", $self->{'metadata_fields'}) if $self->{'metadata_fields'};
+	push (@$specific_options, "-metadata_field_separator", $self->{'metadata_field_separator'}) if $self->{'metadata_field_separator'};
+	push(@$specific_options, "-processing_tmp_files");
+	
+    }
+	
+    elsif ($secondary_plugin_name eq "HTMLPlugin") {
+	push(@$specific_options, "-processing_tmp_files");
+	push(@$specific_options,"-input_encoding", "utf8");
+	push(@$specific_options,"-extract_language") if $self->{'extract_language'};
+	push(@$specific_options, "-description_tags") if $self->{'description_tags'};
+	# Instruct HTMLPlugin (when eventually accessed through read_into_doc_obj)
+	# to extract these metadata fields from the HEAD META fields
+	push(@$specific_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
+    }
 
     $self = bless $self, $class;
