Index: gsdl/trunk/bin/script/export.pl
===================================================================
--- gsdl/trunk/bin/script/export.pl	(revision 14925)
+++ gsdl/trunk/bin/script/export.pl	(revision 14935)
@@ -50,8 +50,9 @@
 use plugin;
 use plugout;
+use manifest;
 use util;
 use scriptutil;
 use FileHandle;
-use gsprintf;
+use gsprintf 'gsprintf';
 use printusage;
 use parse2;
@@ -61,8 +62,8 @@
     [ { 'name' => "hash",
         'desc' => "{import.OIDtype.hash}" },
+      { 'name' => "assigned",
+        'desc' => "{import.OIDtype.assigned}" },
       { 'name' => "incremental",
         'desc' => "{import.OIDtype.incremental}" },
-      { 'name' => "assigned",
-        'desc' => "{import.OIDtype.assigned}" },
       { 'name' => "dirname",
         'desc' => "{import.OIDtype.dirname}" } ];
@@ -72,6 +73,8 @@
     [ { 'name' => "DSpace",
         'desc' => "{export.saveas.DSpace}" },
-      { 'name' => "METS",
-        'desc' => "{export.saveas.METS}"},
+      { 'name' => "GreenstoneMETS",
+        'desc' => "{export.saveas.GreenstoneMETS}"},
+      { 'name' => "FedoraMETS",
+        'desc' => "{export.saveas.FedoraMETS}"},
       { 'name' => "GA",
         'desc' => "{export.saveas.GA}"},
@@ -89,5 +92,5 @@
 # modegli: The lowest detail mode this argument is visible at in GLI
 
-my $saveas_argument =       
+my $saveas_argument =
       { 'name' => "saveas",
 	'desc' => "{export.saveas}",
@@ -102,9 +105,4 @@
     [ 
       $saveas_argument,
-      { 'name' => "saveas_version",
-	'desc' => "{export.saveas_version}",
-	'type' => "string",
-	'reqd' => "no",
-       'deft' => "greenstone" },
       { 'name' => "exportdir",
 	'desc' => "{export.exportdir}",
@@ -128,5 +126,12 @@
 	# parsearg left "" as default
 	#'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
-        'reqd' => "no",
+	'deft' => "",
+	'reqd' => "no",
+	'hiddengli' => "yes" },
+      { 'name' => "manifest",
+	'desc' => "{import.manifest}",
+	'type' => "string",
+	'deft' => "",
+	'reqd' => "no",
         'hiddengli' => "yes" },
       { 'name' => "listall",
@@ -145,9 +150,13 @@
 	'reqd' => "no",
         'modegli' => "4" },
+      { 'name' => "incremental",
+	'desc' => "{import.incremental}",
+	'type' => "flag",
+	'hiddengli' => "yes" },
       { 'name' => "keepold",
 	'desc' => "{export.keepold}",
 	'type' => "flag",
 	'reqd' => "no",
-        'hiddengli' => "yes" },
+	'hiddengli' => "yes" },
       { 'name' => "removeold",
 	'desc' => "{export.removeold}",
@@ -207,4 +216,10 @@
 	'reqd' => "no",
         'hiddengli' => "no" },
+      { 'name' => "fedora_namespace",
+	'desc' => "{FedoraMETSPlugout.fedora_namespace}",
+	'type' => "string",
+	'deft' => "greenstone",
+	'reqd' => "no",
+        'hiddengli' => "no" },
       { 'name' => "mapping_file",
 	'desc' => "{MARCXMLPlugout.mapping_file}",
@@ -244,7 +259,44 @@
 		        'args' => [ $saveas_argument ] };
 
-sub gsprintf
+#sub gsprintf
+#{
+#    return &gsprintf::gsprintf(@_);
+#}
+
+
+sub store_collectionmeta
 {
-    return &gsprintf::gsprintf(@_);
+    my ($collectionmeta,$field,$doc_obj) = @_;
+
+    my $section = $doc_obj->get_top_section();
+
+    my $field_hash = $collectionmeta->{$field};
+
+    foreach my $k (keys %$field_hash) 
+    {
+	my $val = $field_hash->{$k};
+
+
+###	print STDERR "*** $k = $field_hash->{$k}\n";
+
+	my $md_label = "ex.$field";
+
+
+	if ($k =~ m/^\[l=(.*?)\]$/)
+	{
+
+	    my $md_suffix = $1;
+	    $md_label .= "^$md_suffix";
+	}
+
+
+	$doc_obj->add_utf8_metadata($section,$md_label, $val);
+	
+	if (($md_label eq "ex.collectionname^en") || ($md_label eq "ex.collectionname"))
+	{
+	    $doc_obj->add_utf8_metadata($section,"dc.Title", $val);
+	}
+
+    }
 }
 
@@ -254,12 +306,23 @@
 sub main {
     # params
-    my ($language, $verbosity, $importdir, $exportdir, $site, $keepold, $listall,
-	$removeold, $saveas, $saveas_version, $debug, $OIDtype, $OIDmetadata,
-	$maxdocs, $statsfile, $xsltfile, $mapping_file, $out, $faillog, $gs_mode, $collectcfg,
-	$collectdir, $gli,$xslt_mets,$xslt_txt,$group_marc);
+    my ($language, $verbosity, $debug,
+	$importdir, $manifest, $incremental, $keepold,
+	$exportdir, $site, $listall,
+	$removeold, $saveas,
+	$OIDtype, $OIDmetadata,
+	$out, $faillog, $collectdir, $gli,
+	$gs_mode, $collectcfg,
+	$maxdocs, $statsfile, 
+	$mapping_file,
+	$xsltfile, 
+	$xslt_mets, $xslt_txt, $fedora_namespace, $group_marc);
+
     my $xml = 0;
     
     # other vars
-    my ($configfilename, $collection, $export_info_filename, $export_info, $processor, $pluginfo);
+    my ($configfilename, $collection, 
+	$export_info_filename, $export_info, 
+	$processor, $pluginfo);
+
     my $service = "export";
 
@@ -341,5 +404,4 @@
 	eval {
 	    # get and check the collection name
-	    print STDERR "**** site = $site\n";
 	    if (($collection = &colcfg::use_collection($site, $collect_name, $collectdir)) eq "") {
 		&PrintUsage::print_txt_usage($options, "{export.params}");
@@ -372,8 +434,8 @@
 	    my $plugins = [];
 	    my @global_opts = ();
-	    
+
 	    # Read in the collection configuration file.
 	    ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
-	    
+
 	    if ($gs_mode eq "gs2") {
 		$collectcfg = &colcfg::read_collect_cfg ($configfilename);
@@ -381,4 +443,25 @@
 		$collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
 	    }
+
+	    if (defined $collectcfg->{'importdir'} && $importdir eq "") {
+		$importdir = $collectcfg->{'importdir'};
+	    }
+	    if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
+		$exportdir = $collectcfg->{'exportdir'};
+	    }
+
+	    # fill in the default import and export directories if none
+	    # were supplied, turn all \ into / and remove trailing /
+	    $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
+	    $importdir =~ s/[\\\/]+/\//g;
+	    $importdir =~ s/\/$//;
+	    if (!-e $importdir) {
+		&gsprintf($out, "{import.no_import_dir}\n\n", $importdir);
+		die "\n";
+	    }
+
+	    $exportdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export") if $exportdir eq "";
+	    $exportdir =~ s/[\\\/]+/\//g;
+	    $exportdir =~ s/\/$//;
 
 	    if (defined $collectcfg->{'plugin'}) {
@@ -392,10 +475,4 @@
 		    $verbosity = 2; # the default
 		}
-	    }
-	    if (defined $collectcfg->{'importdir'} && $importdir eq "") {
-		$importdir = $collectcfg->{'importdir'};
-	    }
-	    if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
-		$exportdir = $collectcfg->{'exportdir'};
 	    }
 
@@ -476,5 +553,5 @@
 	    if ($saveas eq "DSpace"){
 		$export_info_filename = &util::filename_cat ($exportdir, "contents");
-	    } elsif ($saveas eq "METS" || $saveas eq "GA" || $saveas eq "MARC" ) {
+	    } elsif ($saveas =~ m/^.*METS$/ || $saveas eq "GA" || $saveas eq "MARC" ) {
 		$export_info_filename = &util::filename_cat ($exportdir, "export.inf");
 	    }
@@ -488,5 +565,5 @@
 	    }
 	    else{
-		if ($saveas !~ /^(GA|METS|DSpace|MARCXML)$/) {
+		if ($saveas !~ /^(GA|.*METS|DSpace|MARCXML)$/) {
 		    push @$plugout,"GAPlugout";
 		}
@@ -505,9 +582,10 @@
 	    push @$plugout,("-output_handle",$out) if (defined $out);
 	    push @$plugout,("-xslt_file",$xsltfile) if (defined $xsltfile);
-	    push @$plugout,("-group") if ($group_marc && $plugout_name =~ /^MARCXMLPlugout$/);
-	    push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $plugout_name =~ /^MARCXMLPlugout$/);
-	    push @$plugout,("-saveas_version",$saveas_version) if (defined $saveas_version && $plugout_name =~ /^METSPlugout$/);
-	    push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $plugout_name =~ /^METSPlugout$/);
-	    push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $plugout_name =~ /^METSPlugout$/);
+	    push @$plugout,("-group") if ($group_marc && $plugout_name =~ m/^MARCXMLPlugout$/);
+	    push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $plugout_name =~ m/^MARCXMLPlugout$/);
+	    push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $plugout_name =~ m/^.*METSPlugout$/);
+	    push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $plugout_name =~ m/^.*METSPlugout$/);
+	    push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $plugout_name eq "FedoraMETSPlugout");
+
 	    $processor = &plugout::load_plugout($plugout);    
 	    
@@ -521,4 +599,24 @@
 	    # process the import directory
 	    &plugin::read ($pluginfo, $importdir, "", {}, $processor, $maxdocs,0, $gli);
+
+	    if ($saveas eq "FedoraMETS")
+	    {
+		# 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);
@@ -529,5 +627,5 @@
 	    $processor->close_file_output() if $groupsize > 1;
 	    $processor->close_group_output() if $processor->is_group();
-	    if ($saveas eq "METS") {
+	    if ($saveas =~ m/^.*METS$/) {
 		$export_info->save_info($export_info_filename);
 	    }
