Index: /gsdl/trunk/bin/script/import.pl
===================================================================
--- /gsdl/trunk/bin/script/import.pl	(revision 14956)
+++ /gsdl/trunk/bin/script/import.pl	(revision 14957)
@@ -39,5 +39,19 @@
     unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
     unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
+
+    if (defined $ENV{'GSDLEXTS'}) {
+	my @extensions = split(/:/,$ENV{'GSDLEXTS'});
+	foreach my $e (@extensions) {
+	    my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
+
+	    unshift (@INC, "$ext_prefix/perllib");
+	    unshift (@INC, "$ext_prefix/perllib/cpan");
+	}
+    }
 }
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and vice versa
+no strict 'subs'; # allow barewords (eg STDERR) as function arguments
 
 use arcinfo;
@@ -55,8 +69,4 @@
 
 
-use strict;
-no strict 'refs'; # allow filehandles to be variables and vice versa
-no strict 'subs'; # allow barewords (eg STDERR) as function arguments
-
 my $oidtype_list = 
     [ { 'name' => "hash",
@@ -69,10 +79,18 @@
         'desc' => "{import.OIDtype.dirname}" } ];
 
-#** define to use the original GA format or METS format
+
+# used to control output file format
 my $saveas_list = 
-    [ { 'name' => "GA",
-        'desc' => "{import.saveas.GA}" },
-      { 'name' => "METS",
-        'desc' => "{import.saveas.METS}" } ];
+    [ { 'name' => "DSpace",
+        'desc' => "{export.saveas.DSpace}" },
+      { 'name' => "GreenstoneMETS",
+        'desc' => "{export.saveas.GreenstoneMETS}"},
+      { 'name' => "FedoraMETS",
+        'desc' => "{export.saveas.FedoraMETS}"},
+      { 'name' => "GA",
+        'desc' => "{export.saveas.GA}"},
+      { 'name' => "MARCXML",
+        'desc' => "{export.saveas.MARCXML}"}
+     ];
 
 
@@ -85,7 +103,24 @@
 # modegli: The lowest detail mode this argument is visible at in GLI
 
+my $saveas_argument
+    = { 'name' => "saveas",
+	'desc' => "{import.saveas}",
+	'type' => "enum",
+	'list' => $saveas_list,
+	'deft' => "GA",
+	'reqd' => "no",
+	'modegli' => "3" };
+
+
 my $arguments = 
-    [ { 'name' => "archivedir",
+    [ 
+      $saveas_argument,
+      { 'name' => "archivedir",
 	'desc' => "{import.archivedir}",
+	'type' => "string",
+	'reqd' => "no",
+        'hiddengli' => "yes" },
+      { 'name' => "importdir",
+	'desc' => "{import.importdir}",
 	'type' => "string",
 	'reqd' => "no",
@@ -124,9 +159,4 @@
 	'reqd' => "no",
         'modegli' => "4" },
-      { 'name' => "importdir",
-	'desc' => "{import.importdir}",
-	'type' => "string",
-	'reqd' => "no",
-        'hiddengli' => "yes" },
       { 'name' => "incremental",
 	'desc' => "{import.incremental}",
@@ -176,11 +206,4 @@
 	'reqd' => "no",
         'hiddengli' => "yes" },
-      { 'name' => "saveas",
-	'desc' => "{import.saveas}",
-	'type' => "enum",
-	'list' => $saveas_list,
-	'deft' => "GA",
-	'reqd' => "no",
-	'modegli' => "3" },      
       { 'name' => "sortmeta",
 	'desc' => "{import.sortmeta}",
@@ -245,13 +268,24 @@
 
 sub main {
-    my ($verbosity, $importdir, $archivedir, $site, $manifest, $incremental, $keepold, 
-	$removeold, $saveas, $version,
-	$gzip, $groupsize, $OIDtype, $OIDmetadata, $debug, 
-	$maxdocs, $collection, $configfilename, $collectcfg, $gs_mode,
-	$pluginfo, $sortmeta, $removeprefix, $removesuffix, 
-	$archive_info_filename, $statsfile,
-	$archive_info, $processor, $out, $faillog, $collectdir, $gli, $language);
+    # params
+    my ($language, $verbosity, $debug,
+	$importdir, $site, $manifest, $incremental, $keepold, 
+	$removeold, $saveas,
+	$OIDtype, $OIDmetadata, 
+	$maxdocs, $statsfile,
+	$out, $faillog, $collectdir, $gli,
+
+	$archivedir, 
+	$gzip, $groupsize, 
+	$sortmeta, $removeprefix, $removesuffix, 
+	);
 
     my $xml = 0;
+
+    # other vars
+    my ($configfilename, $collectcfg, $collection, 
+	$archive_info_filename, $archive_info, 
+	$gs_mode,
+	$processor, $pluginfo);
 
     my $service = "import";
@@ -261,5 +295,5 @@
     my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
     # Parse returns -1 if something has gone wrong
-    if($intArgLeftinAfterParsing == -1)
+    if ($intArgLeftinAfterParsing == -1)
     {
 	&PrintUsage::print_txt_usage($options, "{import.params}");
@@ -408,5 +442,5 @@
     }
     else{
-	if ($saveas !~ /^(GA|METS)$/) {
+	if ($saveas !~ /^(GA|.*METS|DSpace|MARCXML)$/) {
 	    push @$plugout,"GAPlugout";
 	}
@@ -493,5 +527,14 @@
 
     # read the archive information file
-    $archive_info_filename = &util::filename_cat ($archivedir, "archives.inf");
+
+    # If saveas=DSpace, a "contents" file will be created, otherwise "archives.inf"
+    
+    # the plugouts should be doing this!!
+    if ($saveas eq "DSpace"){
+	$archive_info_filename = &util::filename_cat ($archivedir, "contents");
+    } elsif ($saveas =~ m/^.*METS$/ || $saveas eq "GA" || $saveas eq "MARC" ) {
+	$archive_info_filename = &util::filename_cat ($archivedir, "archives.inf");
+    }
+
     $archive_info = new arcinfo ();
     $archive_info->load_info ($archive_info_filename);
@@ -531,4 +574,27 @@
     }
 
+    if ($saveas eq "FedoraMETS")
+    {
+	# This would be better (should?!) be done in Plugout!!
+
+	# create collection "doc obj" for Fedora that contains
+	# collection-level metadata
+	
+	my $doc_obj = new doc($configfilename,"nonindexed_doc");
+	$doc_obj->set_OID("collection");
+	
+	my $col_name = undef;
+	my $col_meta = $collectcfg->{'collectionmeta'};
+	if (defined $col_meta)
+	{
+	    store_collectionmeta($col_meta,"collectionname",$doc_obj);
+	    store_collectionmeta($col_meta,"collectioextra",$doc_obj);
+	    
+	}
+	
+	$processor->process($doc_obj);
+    }
+
+
     &plugin::end($pluginfo, $processor);
 
@@ -538,6 +604,12 @@
     $processor->close_file_output() if $groupsize > 1;
     $processor->close_group_output() if $processor->is_group();
-    # should we still do this in debug mode??
-    $archive_info->save_info($archive_info_filename);
+
+# The following 'if' statement is in the export.pl version of the script,
+# but not (so far) the import.pl version.  Why is this?
+##    if ($saveas =~ m/^.*METS$/) {
+	# should we still do this in debug mode??
+
+	$archive_info->save_info($archive_info_filename);
+##    }
     
     # write out import stats
