Index: /gs2-extensions/parallel-building/trunk/src/perllib/plugins/DirectoryPlugin.pm
===================================================================
--- /gs2-extensions/parallel-building/trunk/src/perllib/plugins/DirectoryPlugin.pm	(revision 27376)
+++ /gs2-extensions/parallel-building/trunk/src/perllib/plugins/DirectoryPlugin.pm	(revision 27377)
@@ -181,5 +181,5 @@
 
     # replace -d with function in util library
-    return undef unless (&util::dir_exists($dirname));
+    return undef unless (&FileUtils::directoryExists($dirname));
 
     return 0 if ($self->{'block_exp'} ne "" && $dirname =~ /$self->{'block_exp'}/);
@@ -308,18 +308,17 @@
     $block_hash->{'shared_fileroot'} = {} unless defined $block_hash->{'shared_fileroot'};
 
-     # Recur over directory contents.
-    my (@dir, $subfile);
-    #my $count = 0;
-    
+    # Recur over directory contents.
     print $outhandle "DirectoryPlugin block: getting directory $dirname\n" if ($verbosity > 2);
-    
+
     # find all the files in the directory
-    my $dir_read = &util::file_readdir($dirname, \@dir);
-    if (!$dir_read) {
-	if ($gli) {
-	    print STDERR "<ProcessingError n='$file' r='Could not read directory $dirname'>\n";
-	}
-	print $outhandle "DirectoryPlugin: WARNING - couldn't read directory $dirname\n";
-	return -1; # error in processing
+    my @dir = @{&FileUtils::readDirectory($dirname)};
+    if (scalar(@dir) == 0)
+    {
+      if ($gli)
+      {
+        print STDERR "<ProcessingError n='$file' r='Could not read directory $dirname'>\n";
+      }
+      print $outhandle "DirectoryPlugin: WARNING - couldn't read directory $dirname\n";
+      return -1; # error in processing
     }
 
@@ -394,10 +393,9 @@
 
     # Recur over directory contents.
-    my (@dir, $subfile);
     print $outhandle "DirectoryPlugin read: getting directory $dirname\n" if ($verbosity > 2);
 
     # find all the files in the directory
-    my $dir_read = &util::file_readdir($dirname, \@dir);
-    if (!$dir_read)
+    my @dir = @{&FileUtils::readDirectory($dirname)};
+    if (scalar(@dir) == 0)
     {
       if ($gli)
Index: /gs2-extensions/parallel-building/trunk/src/perllib/plugins/ReadTextFile.pm
===================================================================
--- /gs2-extensions/parallel-building/trunk/src/perllib/plugins/ReadTextFile.pm	(revision 27376)
+++ /gs2-extensions/parallel-building/trunk/src/perllib/plugins/ReadTextFile.pm	(revision 27377)
@@ -39,4 +39,6 @@
 use ghtml;
 use gsprintf 'gsprintf';
+use util;
+use FileUtils;
 
 use AutoExtractMetadata;
@@ -140,5 +142,5 @@
     # this should look at the plugin option too...
     $doc_obj->add_utf8_metadata($top_section, "Plugin", "$self->{'plugin_type'}");
-    $doc_obj->add_utf8_metadata($top_section, "FileSize", &util::file_size($filename_full_path));
+    $doc_obj->add_utf8_metadata($top_section, "FileSize", &FileUtils::fileSize($filename_full_path));
 
     my $plugin_filename_encoding = $self->{'filename_encoding'};
@@ -202,5 +204,5 @@
     my ($filename, $encoding, $language, $textref) = @_;
 
-    if (!&util::file_canread($filename))
+    if (!&FileUtils::canRead($filename))
     {
 	my $outhandle = $self->{'outhandle'};
@@ -213,5 +215,6 @@
     # use the util::file_* functions to provide some extra smarts to the open
     # command in order to support protocols like http: or hdfs:
-    if (!open (FILE, &util::file_openfdcommand($filename, '<')))
+    my $fh;
+    if (!&FileUtils::openFileHandle($filename, '<', \$fh))
     {
       gsprintf(STDERR, "ReadTextFile::read_file {ReadTextFile.could_not_open_for_reading} ($!)\n", $filename);
@@ -222,5 +225,5 @@
     {
       # fast file 'slurp' implementation
-      sysread(FILE, $$textref, &util::file_size($filename));
+      sysread($fh, $$textref, &FileUtils::fileSize($filename));
       # the old slow way of reading in a file
       #undef $/;
@@ -231,5 +234,5 @@
     {
       my $reader = new multiread();
-      $reader->set_handle ('ReadTextFile::FILE');
+      $reader->set_handle ($fh);
       $reader->set_encoding ($encoding);
       $reader->read_file ($textref);
@@ -243,5 +246,5 @@
     $$textref = decode("utf8", $$textref);
 
-    close FILE;
+    &FileUtils::closeFileHandle($filename, \$fh);
 }
 
@@ -368,18 +371,19 @@
     my $best_language = "";
     my $best_encoding = "";
-    
 
     # read in file
-    if (!open (FILE, &util::file_openfdcommand($filename, '<'))) {
-	gsprintf(STDERR, "ReadTextFile::get_language_encoding {ReadTextFile.could_not_open_for_reading} ($!)\n", $filename);
-	# this is a pretty bad error, but try to continue anyway
-	return ($self->{'default_language'}, $self->{'input_encoding'});
+    my $fh;
+    if (!&FileUtils::openFileHandle($filename, '<', \$fh))
+    {
+      gsprintf(STDERR, "ReadTextFile::get_language_encoding {ReadTextFile.could_not_open_for_reading} ($!)\n", $filename);
+      # this is a pretty bad error, but try to continue anyway
+      return ($self->{'default_language'}, $self->{'input_encoding'});
     }
     my $text;
-    sysread(FILE, $text, &util::file_size($filename));
+    sysread($fh, $text, &FileUtils::fileSize($filename));
     #undef $/;
     #my $text = <FILE>;
     #$/ = "\n";
-    close FILE;
+    close $fh;
 
     # check if first few bytes have a Byte Order Marker
Index: /gs2-extensions/parallel-building/trunk/src/perllib/plugouts/BasePlugout.pm
===================================================================
--- /gs2-extensions/parallel-building/trunk/src/perllib/plugouts/BasePlugout.pm	(revision 27376)
+++ /gs2-extensions/parallel-building/trunk/src/perllib/plugouts/BasePlugout.pm	(revision 27377)
@@ -3,5 +3,5 @@
 # BasePlugout.pm -- base class for all the plugout modules
 # A component of the Greenstone digital library software
-# from the New Zealand Digital Library Project at the 
+# from the New Zealand Digital Library Project at the
 # University of Waikato, New Zealand.
 #
@@ -36,4 +36,6 @@
 use printusage;
 use parse2;
+use util;
+use FileUtils;
 
 
@@ -349,8 +351,7 @@
 
     my ($output_file_name) = @_;
-     
-    open(*OUTPUT, ">$output_file_name") or die "Can not open a file handler for  $output_file_name\n";
-
-    return *OUTPUT;            
+    my $fh;
+    &FileUtils::openFileHandle($output_file_name, '>', \$fh) or die "Can not open a file handler for  $output_file_name\n";
+    return $fh;
 }
 
@@ -508,7 +509,7 @@
             # only if opening new file
 	    my $output_dir = $self->get_output_dir();
-	    &util::mk_all_dir ($output_dir) unless &util::dir_exists($output_dir);
-	    my $doc_file = &util::filename_cat ($output_dir, $doc_dir, "doc.xml");
-	    my $short_doc_file = &util::filename_cat ($doc_dir, "doc.xml");
+	    &FileUtils::makeAllDirectories ($output_dir) unless &FileUtils::directoryExists($output_dir);
+	    my $doc_file = &FileUtils::filenameConcatenate ($output_dir, $doc_dir, "doc.xml");
+	    my $short_doc_file = &FileUtils::filenameConcatenate ($doc_dir, "doc.xml");
 	    
 	    if ($gs_count>0)
@@ -590,5 +591,5 @@
 
     if (!defined $self->{'group'} || !$self->{'group'}){
-	&util::mk_all_dir (&util::filename_cat ($working_dir, $doc_dir));
+	&FileUtils::makeAllDirectories(&FileUtils::filenameConcatenate($working_dir, $doc_dir));
     }
 
@@ -619,9 +620,9 @@
 	   $doc_dir_num++;
        }
-   } while ($doc_dir_rest ne "" && ((&util::dir_exists(&util::filename_cat($working_dir, "$doc_dir.dir"))) || ($working_info->size() >= 1024 && $doc_dir_num < 2)));
+   } while ($doc_dir_rest ne "" && ((&FileUtils::directoryExists(&FileUtils::filenameConcatenate($working_dir, "$doc_dir.dir"))) || ($working_info->size() >= 1024 && $doc_dir_num < 2)));
    my $i = 1;
    my $doc_dir_base = $doc_dir;
    #rint "!! - ensure path is unique by adding numeric suffix if necessary\n";
-   while (&util::dir_exists(&util::filename_cat($working_dir, "$doc_dir.dir"))) {
+   while (&FileUtils::directoryExists(&FileUtils::filenameConcatenate($working_dir, "$doc_dir.dir"))) {
        $doc_dir = "$doc_dir_base-$i";
        $i++;
@@ -640,8 +641,8 @@
     return if (!defined $output_dir);
 
-    &util::mk_all_dir ($output_dir) unless &util::dir_exists($output_dir);
+    &FileUtils::makeAllDirectories($output_dir) unless &FileUtils::directoryExists($output_dir);
       
-    my $working_dir = &util::filename_cat($output_dir, $doc_dir);
-    &util::mk_all_dir ($working_dir) unless &util::dir_exists($working_dir);
+    my $working_dir = &FileUtils::filenameConcatenate($output_dir, $doc_dir);
+    &FileUtils::makeAllDirectories($working_dir) unless &FileUtils::directoryExists($working_dir);
 
     my @assoc_files = ();
@@ -662,5 +663,5 @@
      
 	if ($source_filename !~ /^$dirsep_regexp/) {
-	    $source_filename = &util::filename_cat($collect_dir, $source_filename);
+	    $source_filename = &FileUtils::filenameConcatenate($collect_dir, $source_filename);
 	}
     }
@@ -684,9 +685,9 @@
 	$real_filename = &util::downgrade_if_dos_filename($real_filename);
 
-	if (&util::file_exists($real_filename)) {
-
-	    $filename = &util::filename_cat($working_dir, $afile);
-
-	    &util::hard_link ($real_filename, $filename, $self->{'verbosity'});
+	if (&FileUtils::fileExists($real_filename)) {
+
+	    $filename = &FileUtils::filenameConcatenate($working_dir, $afile);
+
+	    &FileUtils::hardLink($real_filename, $filename, $self->{'verbosity'});
 	    
 	    $doc_obj->add_utf8_metadata ($doc_obj->get_top_section(),
@@ -731,5 +732,5 @@
 	my $raw_filename = &util::downgrade_if_dos_filename($real_filename);
 
-	if (&util::file_exists($raw_filename)) {
+	if (&FileUtils::fileExists($raw_filename)) {
 
 #	    if (defined $collect_dir) {
@@ -819,12 +820,14 @@
         $dc_title .= " (Updated)";
       }
-      my $rss_filename = &util::filename_cat($output_dir,"rss-items.rdf");
-      if (open(RSSOUT, &util::file_openfdcommand($rss_filename, '>>')))
+      my $rss_filename = &FileUtils::filenameConcatenate($output_dir,"rss-items.rdf");
+      my $rssout_fh;
+      
+      if (&FileUtils::openFileHandle($rss_filename, '>>', \$rssout_fh))
       {
-        print RSSOUT "<item>\n";
-        print RSSOUT "   <title>" . $dc_title . "</title>\n";
-        print RSSOUT "   <link>_httpdomain__httpcollection_/document/" . $doc_obj->get_OID() . "</link>\n";
-        print RSSOUT "</item>\n";
-        close(RSSOUT);
+        print $rssout_fh "<item>\n";
+        print $rssout_fh "   <title>" . $dc_title . "</title>\n";
+        print $rssout_fh "   <link>_httpdomain__httpcollection_/document/" . $doc_obj->get_OID() . "</link>\n";
+        print $rssout_fh "</item>\n";
+        &FileUtils::closeFileHandle($rss_filename, $rssout_fh);
       }
       else
@@ -887,12 +890,12 @@
     my ($output_file_name, $xslt_file)=@_;
 
-    return unless defined $xslt_file and $xslt_file ne "" and &util::file_exists($xslt_file);
-    
-    my $java_class_path =  &util::filename_cat ($ENV{'GSDLHOME'},"bin","java","ApplyXSLT.jar");
+    return unless defined $xslt_file and $xslt_file ne "" and &FileUtils::fileExists($xslt_file);
+    
+    my $java_class_path =  &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"bin","java","ApplyXSLT.jar");
 
     my $mapping_file_path = "";
 
     if ($ENV{'GSDLOS'} eq "windows"){
-	$java_class_path .=";".&util::filename_cat ($ENV{'GSDLHOME'},"bin","java","xalan.jar");
+	$java_class_path .=";".&FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"bin","java","xalan.jar");
 	# this file:/// bit didn't work for me on windows XP
 	#$xslt_file = "\"file:///".$xslt_file."\"";
@@ -900,5 +903,5 @@
     }
     else{
-	$java_class_path .=":".&util::filename_cat ($ENV{'GSDLHOME'},"bin","java","xalan.jar");
+	$java_class_path .=":".&FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"bin","java","xalan.jar");
     }
 
@@ -961,5 +964,5 @@
 	$doc_file .= ".gz";
 	$short_doc_file .= ".gz";
-	if (!&util::file_exists($doc_file)) {
+	if (!&FileUtils::fileExists($doc_file)) {
 	     my $outhandle = $self->{'output_handle'};
 	    print $outhandle "error while gzipping: $doc_file doesn't exist\n";
Index: /gs2-extensions/parallel-building/trunk/src/perllib/plugouts/GreenstoneXMLPlugout.pm
===================================================================
--- /gs2-extensions/parallel-building/trunk/src/perllib/plugouts/GreenstoneXMLPlugout.pm	(revision 27376)
+++ /gs2-extensions/parallel-building/trunk/src/perllib/plugouts/GreenstoneXMLPlugout.pm	(revision 27377)
@@ -32,4 +32,5 @@
 eval {require bytes};
 use util;
+use FileUtils;
 use BasePlugout;
 use docprint;
@@ -73,12 +74,12 @@
   {
     my $output_dir = $self->get_output_dir();
-    my $working_dir = &util::filename_cat($output_dir, $doc_dir);
-    if (!&util::dir_exists($working_dir))
+    my $working_dir = &FileUtils::filenameConcatenate($output_dir, $doc_dir);
+    if (!&FileUtils::directoryExists($working_dir))
     {
-      &util::mk_all_dir($working_dir);
+      &FileUtils::makeAllDirectories($working_dir);
     }
     $self->process_assoc_files ($doc_obj, $doc_dir, '');
     $self->process_metafiles_metadata ($doc_obj);
-    my $output_file = &util::filename_cat($working_dir, "doc.xml");
+    my $output_file = &FileUtils::filenameConcatenate($working_dir, "doc.xml");
     $self->open_xslt_pipe($output_file, $self->{'xslt_file'});
     if (defined $self->{'xslt_writer'})
@@ -110,5 +111,5 @@
     }
 
-    $self->{'short_doc_file'} = util::filename_cat($doc_dir, "doc.xml");
+    $self->{'short_doc_file'} = FileUtils::filenameConcatenate($doc_dir, "doc.xml");
 
     $self->store_output_info_reference($doc_obj);
@@ -116,20 +117,4 @@
 }
 # /** saveas() **/
-
-# Overriden for HDFS support
-sub get_output_handler
-{
-  my $self = shift (@_);
-  my ($output_file_name) = @_;
-  if (&util::isHDFS($output_file_name))
-  {
-    open(*OUTPUT, &util::file_openfdcommand($output_file_name, '>'));
-    return *OUTPUT;
-  }
-  else
-  {
-    return $self->SUPER::get_output_handler($output_file_name);
-  }
-}
 
 sub get_new_doc_dir
@@ -159,7 +144,7 @@
       $doc_dir_num++;
     }
-    ###rint "!! - testing Path: " . $doc_dir . "\n";
-    $created_directory = &util::mk_all_dir(&util::filename_cat($working_dir, $doc_dir . '.dir'));
-    ###rint "-> result: |" . $created_directory . "|\n";
+    #rint "!! - testing Path: " . $doc_dir . "\n";
+    $created_directory = &FileUtils::makeAllDirectories(&FileUtils::filenameConcatenate($working_dir, $doc_dir . '.dir'));
+    #rint "-> result: |" . $created_directory . "|\n";
   }
   while ($doc_dir_rest ne "" && $doc_dir_num < 32 && !$created_directory);
@@ -170,7 +155,7 @@
     $i++;
     $doc_dir = $doc_dir_base . '-' . $i;
-    ###rint "!! - testing Path: " . $doc_dir . "\n";
-    $created_directory = &util::mk_all_dir(&util::filename_cat($working_dir, $doc_dir . '.dir'));
-    ###rint "-> result: |" . $created_directory . "|\n";
+    #rint "!! - testing Path: " . $doc_dir . "\n";
+    $created_directory = &FileUtils::makeAllDirectories(&FileUtils::filenameConcatenate($working_dir, $doc_dir . '.dir'));
+    #rint "-> result: |" . $created_directory . "|\n";
   }
   if (!$created_directory)
@@ -178,5 +163,5 @@
     die("Error! Failed to create directory for document: " . $doc_dir_base . "\n");
   }
-  ###rint "!! Final Path: " . $doc_dir . ".dir\n";
+  #rint "!! Final Path: " . $doc_dir . ".dir\n";
   return $doc_dir . '.dir';
 }
