Index: /main/trunk/greenstone2/perllib/plugins/EncodingUtil.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/EncodingUtil.pm	(revision 31477)
+++ /main/trunk/greenstone2/perllib/plugins/EncodingUtil.pm	(revision 31478)
@@ -34,5 +34,5 @@
 
 use PrintInfo;
-
+use Encode;
 
 BEGIN {
@@ -74,11 +74,20 @@
 
 my $arguments =
-     [ { 'name' => "filename_encoding",
-	'desc' => "{BasePlugin.filename_encoding}",
-	'type' => "enum",
-	'deft' => "auto",
-	'list' => $encoding_plus_auto_list,
-	'reqd' => "no" }
-     ];
+    [  { 'name' => "block_exp",
+	 'desc' => "{BasePlugin.block_exp}",
+	 'type' => "regexp",
+	 'deft' => "",
+	 'reqd' => "no" },
+       { 'name' => "no_blocking",
+	 'desc' => "{BasePlugin.no_blocking}",
+	 'type' => "flag",
+	 'reqd' => "no"},
+       { 'name' => "filename_encoding",
+	 'desc' => "{BasePlugin.filename_encoding}",
+	 'type' => "enum",
+	 'deft' => "auto",
+	 'list' => $encoding_plus_auto_list,
+	 'reqd' => "no" }
+    ];
 
 my $options = { 'name'     => "EncodingUtil",
@@ -120,5 +129,25 @@
 }
 
-
+# converts raw filesystem filename to perl unicode format
+sub raw_filename_to_unicode {
+    my $self = shift (@_);
+    my ($file) = @_;
+
+    my $unicode_file = "";
+    ### need it in perl unicode, not raw filesystem
+    my $filename_encoding =  $self->guess_filesystem_encoding();  
+		
+    # copied this from set_Source_metadata in BasePlugin
+    if ((defined $filename_encoding) && ($filename_encoding ne "ascii")) {
+	# Use filename_encoding to map raw filename to a Perl unicode-aware string 
+	$unicode_file = decode($filename_encoding,$file);		
+    }
+    else {
+	# otherwise generate %xx encoded version of filename for char > 127
+	$unicode_file = &unicode::raw_filename_to_url_encoded($file);
+    }
+    return $unicode_file;
+
+}
 # just converts path as is to utf8.
 sub filepath_to_utf8 {
@@ -544,4 +573,86 @@
 }
 
+sub block_raw_filename {
+
+    my $self = shift (@_);
+    my ($block_hash,$filename_full_path) = @_;
+
+    my $unicode_filename = $self->raw_filename_to_unicode($filename_full_path);
+    return $self->block_filename($block_hash, $unicode_filename);
+}
+
+# block unicode string filename
+sub block_filename
+{
+    my $self = shift (@_);
+    my ($block_hash,$filename_full_path) = @_;
+    print STDERR "in block filename $filename_full_path\n";
+    print STDERR &unicode::debug_unicode_string($filename_full_path)."\n";
+     
+    if (($ENV{'GSDLOS'} =~ m/^windows$/) && ($^O ne "cygwin")) {
+	   # block hash contains long names, lets make sure that we were passed a long name
+	   $filename_full_path = &util::upgrade_if_dos_filename($filename_full_path);
+	   # lower case the entire thing, eg for cover.jpg when its actually cover.JPG
+	   my $lower_filename_full_path = lc($filename_full_path);
+	   $block_hash->{'file_blocks'}->{$lower_filename_full_path} = 1;
+	
+    }
+    elsif ($ENV{'GSDLOS'} =~ m/^darwin$/) {
+	# we need to normalize the filenames
+        my $composed_filename_full_path = normalize('C', $filename_full_path);
+        print STDERR "darwin, composed filename =". &unicode::debug_unicode_string($composed_filename_full_path)."\n";
+        $block_hash->{'file_blocks'}->{$composed_filename_full_path} = 1;
+   }
+ 
+    else {
+	$block_hash->{'file_blocks'}->{$filename_full_path} = 1;
+    }
+}
+
+
+# filename is raw filesystem name
+sub raw_file_is_blocked {
+     my $self = shift (@_);
+     my ($block_hash, $filename_full_path) = @_;
+
+     my $unicode_filename_full_path = $self->raw_filename_to_unicode($filename_full_path);
+     return $self->file_is_blocked($block_hash, $unicode_filename_full_path);
+}
+
+# filename must be perl unicode string
+sub file_is_blocked {
+    my $self = shift (@_);
+    my ($block_hash, $filename_full_path) = @_;
+
+    # 
+    print STDERR "in file is blocked $filename_full_path\n";
+    print STDERR &unicode::debug_unicode_string($filename_full_path)."\n";
+    if (($ENV{'GSDLOS'} =~ m/^windows$/) && ($^O ne "cygwin")) {
+	# convert to long filenames if needed
+	$filename_full_path = &util::upgrade_if_dos_filename($filename_full_path);
+	# all block paths are lowercased.
+	my $lower_filename = lc ($filename_full_path);
+	if (defined $block_hash->{'file_blocks'}->{$lower_filename}) {
+	    $self->{'num_blocked'} ++;
+	    return 1;
+	}
+    }
+    else {
+	if (defined $block_hash->{'file_blocks'}->{$filename_full_path}) {
+	    $self->{'num_blocked'} ++;
+	    print STDERR "BLOCKED\n";
+	    return 1;
+	}
+    }
+    # check Directory plugin's own block_exp 
+    if ($self->{'block_exp'} ne "" && $filename_full_path =~ /$self->{'block_exp'}/) {
+	$self->{'num_blocked'} ++;
+	return 1; # blocked
+    }
+    print STDERR "NOT BLOCKED\n";
+    return 0;
+}
+
+
 1;
 
