Index: main/trunk/greenstone2/perllib/inexport.pm
===================================================================
--- main/trunk/greenstone2/perllib/inexport.pm	(revision 28701)
+++ main/trunk/greenstone2/perllib/inexport.pm	(revision 28705)
@@ -70,4 +70,5 @@
 	'type' => "string",
 	'reqd' => "no",
+	'deft' => "import",
         'hiddengli' => "yes" },
       { 'name' => "collectdir",
@@ -89,6 +90,5 @@
 	'type' => "enum",
 	'list' => $oidtype_list,
-	# parsearg left "" as default
-	#'deft' => "hash",
+	'deft' => "hash_on_full_filename",
 	'reqd' => "no",
 	'modegli' => "2" },
@@ -96,7 +96,5 @@
 	'desc' => "{import.OIDmetadata}",
 	'type' => "string",
-	 #'type' => "metadata", #doesn't work properly in GLI
-	# parsearg left "" as default
-	#'deft' => "dc.Identifier",
+	'deft' => "dc.Identifier",
 	'reqd' => "no",
 	'modegli' => "2" },
@@ -136,7 +134,6 @@
 	'type' => "int",
 	'reqd' => "no",
-	# parsearg left "" as default
-	#'deft' => "-1",
-	'range' => "1,",
+	'deft' => "-1",
+	'range' => "-1,",
 	'modegli' => "1" },
        { 'name' => "debug",
@@ -169,6 +166,5 @@
 	'type' => "int",
 	'range' => "0,",
-	# parsearg left "" as default
-	# 'deft' => "2",
+	'deft' => "2",
 	'reqd' => "no",
 	'modegli' => "3" },
@@ -239,5 +235,5 @@
     if ($intArgLeftinAfterParsing != 1 || (@$argv && $argv->[0] =~ /^\-+h/))
     {
-	## TODO if we had invalid arg, can we signla that to user???
+	## TODO if we had invalid arg, can we signal that to user???
 	&PrintUsage::print_txt_usage($options, "{import.params}");
 	die "\n";
@@ -356,8 +352,6 @@
     my $inexport_mode = $self->{'mode'};
 
-    my $verbosity  = $self->{'verbosity'};
-    my $debug      = $self->{'debug'};
     my $importdir  = $self->{'importdir'};
-    my $archivedir = $self->{'archivedir'} || $self->{'exportdir'} || "";
+    my $archivedir = $self->{'archivedir'} || $self->{'exportdir'};
     my $out        = $self->{'out'};
 
@@ -372,15 +366,23 @@
     }
 
-    if (defined $collectcfg->{'importdir'} && $importdir eq "") {
+    if (defined $self->{'default_importdir'} && defined $collectcfg->{'importdir'}) {
 	$importdir = $collectcfg->{'importdir'};
     }
-    if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
-	$archivedir = $collectcfg->{'archivedir'};
+
+    if ($inexport_mode eq "import") {
+	if ( defined $self->{'default_archivedir'} && defined $collectcfg->{'archivedir'}) {
+	    $archivedir = $collectcfg->{'archivedir'};
+	}
+    }
+    elsif ($inexport_mode eq "export") {
+	if (defined $self->{'default_exportdir'} && defined $collectcfg->{'exportdir'}) {
+	    $archivedir = $collectcfg->{'exportdir'};
+	}
     }
     # fill in the default import and archives directories if none
     # were supplied, turn all \ into / and remove trailing /
-    if ($importdir eq "")
+    if (!&FileUtils::isFilenameAbsolute($importdir))
     {
-      $importdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "import");
+      $importdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, $importdir);
     }
     else
@@ -399,32 +401,19 @@
     $self->{'importdir'} = $importdir;
 
-    if ($archivedir eq "") {
-	if ($inexport_mode eq "import") {
-	    $archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "archives");
-	}
-	elsif ($inexport_mode eq "export") {
-	    $archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "export");
-	}
-	else {
-	    print STDERR "Warning: Unrecognized import/export mode '$inexport_mode'\n";
-	    print STDERR "         Defaulting to 'archives' for file output\n";
-	    $archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "archives");
-	}
-    }
-
-    $archivedir = &FileUtils::sanitizePath($archivedir);
-    #$archivedir =~ s/[\\\/]+/\//g;
-    #$archivedir =~ s/\/$//;
+    if (!&FileUtils::isFilenameAbsolute($archivedir)) {
+	$archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, $archivedir);
+    }
+    else {
+	
+	$archivedir = &FileUtils::sanitizePath($archivedir);
+    }
     $self->{'archivedir'} = $archivedir;
 
-    if ($verbosity !~ /\d+/) {
+    if (defined $self->{'default_verbosity'}) {
 	if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
-	    $verbosity = $collectcfg->{'verbosity'};
-	} else {
-	    $verbosity = 2; # the default
-	}
-    }
-    $self->{'verbosity'} = $verbosity;
-
+	    $self->{'verbosity'} = $collectcfg->{'verbosity'};
+	} 
+    }
+ 
     if (defined $collectcfg->{'manifest'} && $self->{'manifest'} eq "") {
 	$self->{'manifest'} = $collectcfg->{'manifest'};
@@ -437,9 +426,7 @@
     }
 
-    if ($self->{'maxdocs'} !~ /\-?\d+/) {
+    if (defined $self->{'default_maxdocs'}) {
 	if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
 	    $self->{'maxdocs'} = $collectcfg->{'maxdocs'};
-	} else {
-	    $self->{'maxdocs'} = -1; # the default
 	}
     }
@@ -447,21 +434,15 @@
    
 
-    if (!defined $self->{'OIDtype'} 
-	|| ($self->{'OIDtype'} !~ /^(hash|hash_on_full_filename|incremental|assigned|filename|dirname|full_filename)$/ )) {
-	# OIDtype was either not defined on the command-line, or if it was not one of the recognized values
+    if (defined $self->{'default_OIDtype'} ) {
 	if (defined $collectcfg->{'OIDtype'} 
 	    && $collectcfg->{'OIDtype'} =~ /^(hash|hash_on_full_filename|incremental|assigned|filename|dirname|full_filename)$/) {
 	    $self->{'OIDtype'} = $collectcfg->{'OIDtype'};
-	} else {
-	    $self->{'OIDtype'} = "hash"; # the default
-	}
-    }
-
-    if ((!defined $self->{'OIDmetadata'}) || ($self->{'OIDmetadata'} eq "")) {
+	}
+    }
+
+    if (defined $self->{'default_OIDmetadata'}) {
 	if (defined $collectcfg->{'OIDmetadata'}) {
 	    $self->{'OIDmetadata'} = $collectcfg->{'OIDmetadata'};
-	} else {
-	    $self->{'OIDmetadata'} = "dc.Identifier"; # the default
-	}
+	} 
     }
 
@@ -638,34 +619,36 @@
     my $plugout; 
 
+    my $generate_auxiliary_files = 0;
+    if ($inexport_mode eq "import") {
+	$generate_auxiliary_files = 1;
+    }
+    elsif ($self->{'include_auxiliary_database_files'}) {
+	$generate_auxiliary_files = 1;
+    }
+    $self->{'generate_auxiliary_files'} = $generate_auxiliary_files;
+
+    # Option to use user defined plugout
     if ($inexport_mode eq "import") {
 	if (defined $collectcfg->{'plugout'}) {
 	    # If a plugout was specified in the collect.cfg file, assume it is sensible
 	    # We can't check the name because it could be anything, if it is a custom plugout
+	    print STDERR "Using plugout specified in collect.cfg: $collectcfg->{'plugout'}\n";
 	    $plugout = $collectcfg->{'plugout'};
 	}
-	else{
-	    if ($saveas !~ /^(GreenstoneXML|GreenstoneMETS)$/) {
-		push @$plugout,"GreenstoneXMLPlugout";
-	    }
-	    else{
-		push @$plugout,$saveas."Plugout";
-	    }
+	else {
+	    push @$plugout,$saveas."Plugout";
 	}
 
     }
     else {
-	if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
+	if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(GreenstoneXML|.*METS|DSpace|MARCXML)Plugout/) {
 	    $plugout = $collectcfg->{'plugout'};
-	}
-	else{
-	    if ($saveas !~ /^(GreenstoneMETS|FedoraMETS|DSpace|MARCXML)$/) {
-		push @$plugout,"GreenstoneMETSPlugout";
-	    }
-	    else{
-		push @$plugout,$saveas."Plugout";
-	    }
-	}
-    }
-    
+	    print STDERR "Using plugout specified in collect.cfg: $collectcfg->{'plugout'}\n";
+	}
+	else {
+	    push @$plugout,$saveas."Plugout";
+	}
+    }
+
     my $plugout_name = $plugout->[0];
 
@@ -681,5 +664,5 @@
 
     push @$plugout,("-xslt_file",$xsltfile)        if (defined $xsltfile && $xsltfile ne "");
-
+    push @$plugout, ("-no_auxiliary_databases") if ($generate_auxiliary_files == 0);
     if ($inexport_mode eq "import") {
 	if ($plugout_name =~ m/^GreenstoneXMLPlugout$/) {
@@ -687,27 +670,9 @@
 	}
     }
-    if ($plugout_name =~ m/^MARCXMLPlugout$/) {
-	push @$plugout,("-group")                      if ($group_marc);
-	push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $mapping_file ne "");
-    }
-    if ($plugout_name =~ m/^.*METSPlugout$/) {
-	push @$plugout,("-xslt_mets",$xslt_mets)       if (defined $xslt_mets && $xslt_mets ne "");
-	push @$plugout,("-xslt_txt",$xslt_txt)         if (defined $xslt_txt && $xslt_txt ne "");
-    }
-
-    if ($plugout_name eq "FedoraMETSPlugout") {
-	push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $fedora_namespace ne "");
-    }
-	
-	if ($plugout_name eq "DSpacePlugout") {
-	push @$plugout,("-metadata_prefix",$metadata_prefix) if (defined $metadata_prefix && $metadata_prefix ne "");	
-	}
-
     my $processor = &plugout::load_plugout($plugout);
     $processor->setoutputdir ($archivedir);
     $processor->set_sortmeta ($sortmeta, $removeprefix, $removesuffix) if defined $sortmeta;
-
     $processor->set_OIDtype ($OIDtype, $OIDmetadata);
-    
+    $processor->begin();
     &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
     
@@ -964,4 +929,5 @@
     # oailastmodified and oailastmodifieddate
     my $earliestDatestampFile = &FileUtils::filenameConcatenate($archivedir, "earliestDatestamp");
+    if ($self->{'generate_auxiliary_files'}) {
     if (!-f $earliestDatestampFile && -d $archivedir) {
 	my $current_time_in_seconds = time; # in seconds
@@ -977,5 +943,5 @@
 
     }
-
+    }
     
     $self->perform_process_files($manifest, $pluginfo, $importdir, '', $block_hash, $metadata, $processor, $maxdocs);
@@ -1014,4 +980,5 @@
 
 #    if ($inexport_mode eq "import") {
+    if ($self->{'generate_auxiliary_files'}) {
 	# write out the archive information file
 	# for backwards compatability with archvies.inf file
@@ -1022,5 +989,5 @@
 	    $archive_info->save_revinfo_db($arcinfo_src_filename);
 	}
-#    }
+    }
     return $pluginfo;
 }
