Index: gsdl/trunk/perllib/doc.pm
===================================================================
--- gsdl/trunk/perllib/doc.pm	(revision 18313)
+++ gsdl/trunk/perllib/doc.pm	(revision 18319)
@@ -49,5 +49,5 @@
 sub new {
     my $class = shift (@_);
-    my ($source_filename, $doc_type) = @_;
+    my ($source_filename, $doc_type, $rename_method) = @_;
 
 
@@ -67,5 +67,6 @@
     if (defined $source_filename) {
 	$source_filename = &util::filename_within_collection($source_filename);
-	$self->set_source_filename ($source_filename);
+	print STDERR "******doc.pm::new(): no file rename method provided\n" unless $rename_method;
+	$self->set_source_filename ($source_filename, $rename_method);
     }
 
@@ -144,22 +145,22 @@
 sub set_source_filename {
     my $self = shift (@_);
-    my ($source_filename) = @_;
+    my ($source_filename, $rename_method) = @_;
 
     # Since the gsdlsourcefilename element goes into the doc.xml it has 
     # to be utf8. However, it should also *represent* the source filename 
     # (in the import directory) which may not be utf8 at all. 
-    # For instance, if this meta element (gsdlsourcefilename) will be 
-    # used by other applications that parse doc.xml in order to locate 
-    # gsdlsourcefilename. Therefore, the solution is to URLencode the real
-    # filename as this is a binary-to-text encoding meaning that the 
-    # resulting string is ASCII (utf8).
-    
-#    print STDERR "******URLencoding the gsdl_source_filename $source_filename ";
-    
+    # For instance, if this meta element (gsdlsourcefilename) will be used 
+    # by other applications that parse doc.xml in order to locate 
+    # gsdlsourcefilename. Therefore, the solution is to URLencode or base64 
+    # encode the real filename as this is a binary-to-text encoding meaning
+    # that the resulting string is ASCII (utf8). Decoding will give the original.
+    
+#    print STDERR "******URL/base64 encoding the gsdl_source_filename $source_filename ";
+
     # URLencode just the gsdl_source_filename, not the directory. Then prepend dir 
     my ($srcfilename,$dirname,$suffix) 
 	= &File::Basename::fileparse($source_filename, "\\.[^\\.]+\$");
 #    print STDERR "-> $srcfilename -> ";
-    $srcfilename = &unicode::url_encode($srcfilename.$suffix);
+    $srcfilename = &util::rename_file($srcfilename.$suffix, $rename_method);
     $source_filename = &util::filename_cat($dirname, $srcfilename);
 #    print STDERR "$source_filename\n";
Index: gsdl/trunk/perllib/strings.properties
===================================================================
--- gsdl/trunk/perllib/strings.properties	(revision 18313)
+++ gsdl/trunk/perllib/strings.properties	(revision 18319)
@@ -716,4 +716,10 @@
 BasePlugin.stems:stems
 
+BasePlugin.file_rename_method:The method to be used in renaming the copy of the imported file and associated files.
+
+BasePlugin.rename_method.url:Use url encoding in renaming files and associated files.
+
+BasePlugin.rename_method.base64:Use base64 encoding in renaming imported files and associated files.
+
 BibTexPlugin.desc:BibTexPlugin reads bibliography files in BibTex format. BibTexPlugin creates a document object for every reference in the file. It is a subclass of SplitTextFile, so if there are multiple records, all are read.
 
Index: gsdl/trunk/perllib/unicode.pm
===================================================================
--- gsdl/trunk/perllib/unicode.pm	(revision 18313)
+++ gsdl/trunk/perllib/unicode.pm	(revision 18319)
@@ -600,5 +600,5 @@
 
 # When a filename on the filesystem is already URL-encoded, the
-# URL to it will have %25s in in place of every % sign, so that 
+# URL to it will have %25s in place of every % sign, so that 
 # URLs in html pages can refer to the URL-encoded filename.
 # This method changes the URL reference back into the actual 
@@ -606,5 +606,5 @@
 sub url_to_filename {
     my ($text) =@_;
-    $text =~ s/%25/%/g;
+    $text =~ s/%25/%/g if is_url_encoded($text);
     return $text;
 }
@@ -619,8 +619,10 @@
 # a url more than once this way.
 sub filename_to_url {
-    my ($text) =@_;
-    
-    if($text !~ m/%25/) {
-	$text =~ s/%/%25/g;
+    my ($text, $rename_method) = @_;
+    
+    if(!defined $rename_method || $rename_method eq "url") {
+	if($text !~ m/%25/) {
+	    $text =~ s/%/%25/g;
+	}
     }
     return $text;
Index: gsdl/trunk/perllib/util.pm
===================================================================
--- gsdl/trunk/perllib/util.pm	(revision 18313)
+++ gsdl/trunk/perllib/util.pm	(revision 18319)
@@ -28,4 +28,5 @@
 use File::Copy;
 use File::Basename;
+use MIME::Base64; # for base64 encoding
 
 use strict;
@@ -994,3 +995,31 @@
 }
 
+# returns the given filename converted using either URL encoding or 
+# base64 encoding, as specified by $rename_method
+sub rename_file {
+    my ($filename, $rename_method)  = @_;
+    
+    my ($tailname,$dirname,$suffix) = File::Basename::fileparse($filename, "\\.[^\\.]+\$");
+
+    if (!$rename_method) {
+	print STDERR "WARNING: no file renaming method specified. Defaulting to using URL encoding...\n";
+	# Debugging information
+	my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(1);
+	print STDERR "Calling method; $cfilename:$cline $cpackage->$csubr\n";
+    }
+
+    if (!$rename_method || $rename_method eq "url") {
+	$tailname = &unicode::url_encode($tailname);
+    }
+    elsif ($rename_method eq "base64") {
+	$tailname = &MIME::Base64::encode_base64($tailname);
+	$tailname =~ s/\s*//sg;      # for some reason it adds spaces not just at end but also in middle
+    }
+        
+    $filename = "$tailname$suffix";
+    $filename = "$dirname$filename" if ($dirname ne "./");
+
+    return $filename;
+}
+
 1;
