Index: /main/trunk/greenstone2/perllib/plugins/BasePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/BasePlugin.pm	(revision 23346)
+++ /main/trunk/greenstone2/perllib/plugins/BasePlugin.pm	(revision 23347)
@@ -530,9 +530,9 @@
     # check if the filename is already in UTF8. If it is, then we're done.
     if($filename_encoding =~ m/auto/) {
-	if(&unicode::check_is_utf8($filemeta)) 
-	{
-	    $filename_encoding = "utf8";
-	    return $filemeta;
-	} 
+		if(&unicode::check_is_utf8($filemeta)) 
+		{
+			$filename_encoding = "utf8";
+			return $filemeta;
+		} 
     }
     
@@ -540,15 +540,15 @@
     if ($filename_encoding eq "auto") 
     {
-	# try textcat
-	$filename_encoding = $self->textcat_encoding($filemeta);
+		# try textcat
+		$filename_encoding = $self->textcat_encoding($filemeta);
 	
-	# check the locale next
-	$filename_encoding = $self->locale_encoding() if $filename_encoding eq "undefined";
+		# check the locale next
+		$filename_encoding = $self->locale_encoding() if $filename_encoding eq "undefined";
 	
-
-	# now try the encoding of the document, if available
-	if ($filename_encoding eq "undefined" && defined $file_encoding) {
-	    $filename_encoding = $file_encoding;
-	}
+		
+		# now try the encoding of the document, if available
+		if ($filename_encoding eq "undefined" && defined $file_encoding) {
+			$filename_encoding = $file_encoding;
+		}
 
     }
@@ -633,4 +633,9 @@
 
     my $outhandle = $self->{'outhandle'};
+
+	print $outhandle "****!!!!**** BasePlugin::filename_to_utf8_metadata now deprecated\n";
+	my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(0);
+	print $outhandle "Calling method: $cfilename:$cline $cpackage->$csubr\n";
+
 
     my ($filemeta) = $file =~ /([^\\\/]+)$/; # getting the tail of the filepath (skips all string parts containing slashes upto the end)
@@ -791,5 +796,5 @@
 {
     my $self = shift (@_);  
-    my ($file,$metadata) = @_;
+    my ($file,$metadata,$plugin_filename_encoding) = @_;
 
     my $gs_filename_encoding = $metadata->{"gs.filename_encoding"};
@@ -798,44 +803,72 @@
     # Start by looking for manually assigned metadata
     if (defined $gs_filename_encoding) {
-	if (ref ($gs_filename_encoding) eq "ARRAY") {
-	    my $outhandle = $self->{'outhandle'};
-	    
-	    $deduced_filename_encoding = $gs_filename_encoding->[0];
-	    
-	    my $num_vals = scalar(@$gs_filename_encoding);
-	    if ($num_vals>1) {
-		print $outhandle "Warning: gs.filename_encoding multiply defined for $file\n";
-		print $outhandle "         Selecting first value: $deduced_filename_encoding\n";
-	    }
-	} 
-	else {
-	    $deduced_filename_encoding = $gs_filename_encoding;
-	}
-    }
-    
-#	binmode(STDERR,":utf8");
-    
-#	print STDERR "**** file = $file\n";
-#	print STDERR "**** debug file = ", &unicode::debug_unicode_string($file),"\n";;
-    
-#	print STDERR "******* dfe = $deduced_filename_encoding\n";
-    
+		if (ref ($gs_filename_encoding) eq "ARRAY") {
+			my $outhandle = $self->{'outhandle'};
+			
+			$deduced_filename_encoding = $gs_filename_encoding->[0];
+			
+			my $num_vals = scalar(@$gs_filename_encoding);
+			if ($num_vals>1) {
+				print $outhandle "Warning: gs.filename_encoding multiply defined for $file\n";
+				print $outhandle "         Selecting first value: $deduced_filename_encoding\n";
+			}
+		} 
+		else {
+			$deduced_filename_encoding = $gs_filename_encoding;
+		}
+    }
+        
     if (!defined $deduced_filename_encoding || ($deduced_filename_encoding =~ m/^\s*$/)) {
-	# Look to see if plugin specifies this value
+		# Look to see if plugin specifies this value
+
+		if (defined $plugin_filename_encoding) {
+			# First look to see if we're using any of the "older" (i.e. deprecated auto-... plugin options)
+			if ($plugin_filename_encoding =~ m/^auto-.*$/) {
+				my $outhandle = $self->{'outhandle'};
+				print $outhandle "Warning: $plugin_filename_encoding is no longer supported\n";
+				print $outhandle "         default to 'auto'\n";
+				$self->{'filename_encoding'} = $plugin_filename_encoding = "auto";
+			}
+			
+			if ($plugin_filename_encoding ne "auto") {
+				# We've been given a specific filenamne encoding
+				# => so use it!
+				$deduced_filename_encoding = $plugin_filename_encoding;
+			}
+		}
     }
     
     if (!defined $deduced_filename_encoding || ($deduced_filename_encoding =~ m/^\s*$/)) {
-	# See if we can determine the file system encoding through locale
-	# Unix only ?
+		# See if we can determine the file system encoding through locale
+		$deduced_filename_encoding = $self->locale_encoding();
+
+		# if locale shows us filesystem is utf8, check to see filename is consistent
+		# => if not, then we have an "alien" filename on our hands
+
+		if ($deduced_filename_encoding =~ m/^utf-?8$/i) {
+			if (!&unicode::check_is_utf8($file)) {
+				# "alien" filename, so revert
+				$deduced_filename_encoding = undef;
+			}
+		}
+    }
+    
+    
+#    if (!defined $deduced_filename_encoding || ($deduced_filename_encoding =~ m/^\s*$/)) {
+#		# Last chance, apply textcat to deduce filename encoding
+#		$deduced_filename_encoding = $self->textcat_encoding($file);
+#    }
+
+	if ($self->{'verbosity'}>3) {
+		my $outhandle = $self->{'outhandle'};
+
+		if (defined $deduced_filename_encoding) {
+			print $outhandle "  Deduced filename encoding as: $deduced_filename_encoding\n";
+		}
+		else {
+			print $outhandle "  No filename encoding deduced\n";
+		}
+	}
 	
-	# if locale shows us filesystem is utf8, check to see filename is consistent
-	# => if not, then we have an "alien" filename on our hands
-    }
-    
-    
-    if (!defined $deduced_filename_encoding || ($deduced_filename_encoding =~ m/^\s*$/)) {
-	# Last chance, apply textcat to deduce filename encoding
-    }
-    
     return $deduced_filename_encoding;
 }
@@ -861,23 +894,23 @@
     
     # UTF-8 version of filename
-    print STDERR "**** setting Source Metadata given: $raw_file\n";
-
-##    my $filemeta = $self->filename_to_utf8_metadata($raw_file, $filename_encoding);
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "****** Setting Source Metadata given: $raw_file\n";
+	}
 
     my $url_encoded_filename;
     if (defined $filename_encoding) {
-	# => Generate a pretty print version of filename that is mapped to Unicode
-
-	# Use filename_encoding to map raw filename to a Perl unicode-aware string 
-	$url_encoded_filename = decode($filename_encoding,$raw_file);
-
-	print STDERR "@@@@ pretty print using $filename_encoding: ", encode("utf8",$url_encoded_filename),"\n";
+		# => Generate a pretty print version of filename that is mapped to Unicode
+		
+		# Use filename_encoding to map raw filename to a Perl unicode-aware string 
+		$url_encoded_filename = decode($filename_encoding,$raw_file);		
     }
     else {
-	# otherwise generate %xx encoded version of filename for char > 127
-	$url_encoded_filename = &unicode::raw_filename_to_url_encoded($raw_file);
-    }
-
-    print STDERR "***** saving Source as:             $url_encoded_filename\n";
+		# otherwise generate %xx encoded version of filename for char > 127
+		$url_encoded_filename = &unicode::raw_filename_to_url_encoded($raw_file);
+    }
+	
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "***** saving Source as:             $url_encoded_filename\n";
+	}
 
     
@@ -893,5 +926,7 @@
 					$renamed_raw_url);
 
-    print STDERR "***** saving SourceFile as:         $renamed_raw_url\n";
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "***** saving SourceFile as:         $renamed_raw_url\n";
+	}
 }
    
@@ -953,5 +988,6 @@
  
 
-    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
     $self->set_Source_metadata($doc_obj,$filename_no_path,$filename_encoding);
 
Index: /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm	(revision 23346)
+++ /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm	(revision 23347)
@@ -379,9 +379,14 @@
 
     my ($tailname,$dirname) = &File::Basename::fileparse($file);
-    print STDERR "***!! file = $file\n";
+
 #    my $utf8_file = $self->filename_to_utf8_metadata($file);
 #    $utf8_file =~ s/&\#095;/_/g;
     my $utf8_file = &unicode::raw_filename_to_url_encoded($tailname);
-    print STDERR "***!! utf8_file = $utf8_file\n";
+
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "***!! file = $file\n";
+		print STDERR "***!! utf8_file = $utf8_file\n";
+	}
+
 
     my $web_url = "http://";
@@ -758,5 +763,8 @@
 
 	# If web page didn't give encoding, then default to utf8
-	print "*************** looking up $file\n";
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "*** Web page didn't give encoding, defaulting to UTF8!\n";
+		print STDERR "*****  looking up $file\n";
+	}
 
 	my $content_encoding= $self->{'content_encoding'} || "utf8";
@@ -767,5 +775,8 @@
 
 	&ghtml::urlsafe ($href);
-	print STDERR "***!!! href=$href\n";    
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "***!!! href=$href\n";    
+	}
+
 
 	return $front . "_httpextlink_&amp;rl=" . $rl . "&amp;href=" . $href . $hash_part . $back;
@@ -818,12 +829,18 @@
     if (!-e $filename) {
 	# try the original filename stored in map
-	print STDERR "***###!! orig filename did not exist: $filename\n";
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "***###!! orig filename did not exist: $filename\n";
+	}
 
 	my $original_filename = $self->{'utf8_to_original_filename'}->{$utf8_filename};
 
-	print STDERR "**** Trying for $original_filename\n";
+	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+		print STDERR "**** Trying for $original_filename\n";
+	}
 
 	if (defined $original_filename && -e $original_filename) {
-	    print STDERR "*** found match\n";
+		if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+			print STDERR "*** found match\n";
+		}
 	    $filename = $original_filename;
 	}
@@ -1164,5 +1181,4 @@
 	$title =~ s/^$self->{'title_sub'}// if ($self->{'title_sub'});
 	$title =~ s/^\s+//s; # in case title_sub introduced any...
-	print STDERR "**** adding Title: ", Encode::encode("utf8",$title), "\n";
 	$doc_obj->add_utf8_metadata ($section, "Title", $title);
 	print $outhandle " extracted Title metadata \"$title\" from $from\n" 
Index: /main/trunk/greenstone2/perllib/plugins/ImagePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ImagePlugin.pm	(revision 23346)
+++ /main/trunk/greenstone2/perllib/plugins/ImagePlugin.pm	(revision 23347)
@@ -112,45 +112,40 @@
     my $outhandle = $self->{'outhandle'};
     my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
-
+	
     if ($self->{'image_conversion_available'} == 1)
     {
-	my $filename_encoding = $self->deduce_filename_encoding($file,$metadata);
-
-#	my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
-#	my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
-
-#	$self->generate_images($filename_full_path, $url_encoded_filename, 
-#			       $doc_obj, $doc_obj->get_top_section()); # should we check the return value?
-
-	$filename_no_path = &unicode::raw_filename_to_url_encoded($filename_no_path);
-
-	# should we check the return value?
-	$self->generate_images($filename_full_path, $filename_no_path, 
-			       $doc_obj, $doc_obj->get_top_section(),$filename_encoding); 
-
+		my $plugin_filename_encoding = $self->{'filename_encoding'};
+		my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+		
+		my $url_encoded_filename = &unicode::raw_filename_to_url_encoded($filename_no_path);
+		
+		# should we check the return value?
+		$self->generate_images($filename_full_path, $url_encoded_filename, 
+							   $doc_obj, $doc_obj->get_top_section(),$filename_encoding); 
+		
     }
     else
     {
-	if ($gli) {
-	    &gsprintf(STDERR, "<Warning p='ImagePlugin' r='{ImageConverter.noconversionavailable}: {ImageConverter.".$self->{'no_image_conversion_reason'}."}'>");
-	}
-	# all we do is add the original image as an associated file, and set up srclink etc
-	my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
-	my $section = $doc_obj->get_top_section();
-
-	$doc_obj->associate_file($filename_full_path, $assoc_file, "", $section);
-
-	$doc_obj->add_metadata ($section, "srclink_file", $doc_obj->get_sourcefile()); 
-	# We don't know the size of the image, but the browser should display it at full size
-	$doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[srclink_file]\">");
-
-	# Add a fake thumbnail icon with the full-sized image scaled down by the browser
-	$doc_obj->add_metadata ($section, "thumbicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[srclink_file]\" width=\"" . $self->{'thumbnailsize'} . "\">");
+		if ($gli) {
+			&gsprintf(STDERR, "<Warning p='ImagePlugin' r='{ImageConverter.noconversionavailable}: {ImageConverter.".$self->{'no_image_conversion_reason'}."}'>");
+		}
+		# all we do is add the original image as an associated file, and set up srclink etc
+		my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
+		my $section = $doc_obj->get_top_section();
+		
+		$doc_obj->associate_file($filename_full_path, $assoc_file, "", $section);
+		
+		$doc_obj->add_metadata ($section, "srclink_file", $doc_obj->get_sourcefile()); 
+		# We don't know the size of the image, but the browser should display it at full size
+		$doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[srclink_file]\">");
+		
+		# Add a fake thumbnail icon with the full-sized image scaled down by the browser
+		$doc_obj->add_metadata ($section, "thumbicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[srclink_file]\" width=\"" . $self->{'thumbnailsize'} . "\">");
     }
     #we have no text - adds dummy text and NoText metadata
     $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
-
+	
     return 1;
-
+	
 }
 
