Index: /trunk/gsdl/bin/script/explode_metadata_database.pl
===================================================================
--- /trunk/gsdl/bin/script/explode_metadata_database.pl	(revision 10337)
+++ /trunk/gsdl/bin/script/explode_metadata_database.pl	(revision 10338)
@@ -8,7 +8,10 @@
 }
 
-
-use parsargv;
+use strict;
+no strict 'subs'; # allow barewords (eg STDERR) as function arguments
+no strict 'refs'; # allow filehandles to be variables and vice versa
 use printusage;
+use parse2;
+
 my $unicode_list =
     [ { 'name' => "auto",
@@ -22,5 +25,11 @@
 
 my $arguments = 
-    [ { 'name' => "input_encoding",
+    [ 
+      { 'name' => "plugin",
+	'desc' => "{explode.plugin}",
+	'type' => "string",
+	'reqd' => "yes",
+	'hiddengli' => "yes"},
+      { 'name' => "input_encoding",
 	'desc' => "{explode.encoding}",
 	'type' => "enum",
@@ -33,9 +42,4 @@
 	'reqd' => "no",
 	'hiddengli' => "yes"},
-      { 'name' => "plugin",
-	'desc' => "{explode.plugin}",
-	'type' => "string",
-	'reqd' => "yes",
-	'hiddengli' => "yes"},
       { 'name' => "document_field",
 	'desc' => "{explode.document_field}",
@@ -53,5 +57,17 @@
 	'desc' => "{explode.filename_field}",
 	'type' => "string",
-	'reqd' => "no"}     
+	'reqd' => "no"},
+      { 'name' => "verbosity",
+	'desc' => "{import.verbosity}",
+	'type' => "int",
+	'range' => "0,",
+	'deft' => "1",
+	'reqd' => "no",
+	'modegli' => "4" },
+      { 'name' => "xml",
+	'desc' => "",
+	'type' => "flag",
+	'reqd' => "no",
+	'hiddengli' => "yes" }
       ];
 	
@@ -63,26 +79,28 @@
 sub main
 {
-    my ($encoding, $metadata_set, $plugin, $filename_field, 
-	$document_field, $document_prefix, $document_suffix);
+    my ($language, $input_encoding, $metadata_set, $plugin, $filename_field, 
+	$document_field, $document_prefix, $document_suffix, $verbosity);
 
     my $xml = 0;
-    # Parse command line arguments
-    if (!parsargv::parse(\@ARGV, 
-			 'language/.*/', \$language,
-			 'input_encoding/.*/auto', \$encoding,
-			 'metadata_set/.*/', \$metadata_set,
-			 'plugin/.*/', \$plugin,
-			 'filename_field/.*/', \$filename_field,
-			 'document_field/.*/', \$document_field,
-			 'document_prefix/.*/', \$document_prefix,
-			 'document_suffix/.*/', \$document_suffix,
-			 q^xml^, \$xml)) {
+
+    my $hashParsingResult = {};
+    my $blnParseFailed = "false";
+    # parse the options
+    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
+    # There should one arg left after parsing
+    if($intArgLeftinAfterParsing > 1)
+    {
 	&PrintUsage::print_txt_usage($options, "{explode.params}");
 	die "\n";
     }
-    
+
+    foreach my $strVariable (keys %$hashParsingResult)
+    {
+	eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
+    }
+        
     # If $language has been specified, load the appropriate resource bundle
     # (Otherwise, the default resource bundle will be loaded automatically)
-    if ($language) {
+    if ($language && $language =~ /\S/) {
 	&gsprintf::load_language_specific_resource_bundle($language);
     }
@@ -121,5 +139,5 @@
 
     #check filename field
-    if (defined $fileanme_field && $filenmae_field eq "") {
+    if (defined $filename_field && $filename_field eq "") {
 	undef $filename_field;
     }
@@ -132,10 +150,11 @@
     $plugobj->init(1, "STDERR", "STDERR");
     
-    if ($encoding eq "auto") {
-	$plugobj->{'input_encoding'} = $encoding;   
-	(my $language, $encoding) = $plugobj->textcat_get_language_encoding ($filename);
-    }
+    if ($input_encoding eq "auto") {
+	$plugobj->{'input_encoding'} = $input_encoding;   
+	($language, $input_encoding) = $plugobj->textcat_get_language_encoding ($filename);
+    }
+    my $text = "";
     # Use the plugin's read_file function to avoid duplicating code
-    $plugobj->read_file($filename, $encoding, undef, \$text);
+    $plugobj->read_file($filename, $input_encoding, undef, \$text);
 
     # Create a directory to store the document files...
@@ -147,5 +166,5 @@
 
     # ...and a metadata.xml file for the document metadata (extracted from the database)
-    $documents_metadata_xml_file = &util::filename_cat($documents_directory, "metadata.xml");
+    my $documents_metadata_xml_file = &util::filename_cat($documents_directory, "metadata.xml");
     if (-e $documents_metadata_xml_file) {
 	die "Error: document metadata.xml file $documents_metadata_xml_file already exists (bailing).\n";
@@ -166,5 +185,5 @@
     # Write the metadata from each record to the metadata.xml file
     my $record_number = 0;
-    foreach $record_text (@metadata_records) {
+    foreach my $record_text (@metadata_records) {
 	
 	# Use the plugin's process function to avoid duplicating code
@@ -183,5 +202,5 @@
 		if ($field eq $document_field) {
 		    my $document_file_full = $document_prefix . $value . $document_suffix;
-		    $document_file = &obtain_document($self, $document_file_full, $documents_directory);
+		    $document_file = &obtain_document($document_file_full, $documents_directory, $verbosity);
 		}
 	    }
@@ -191,4 +210,5 @@
 	    # try to get a file name
 	    if (defined $filename_field) {
+		
 		my $meta = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $filename_field);
 		if (defined $meta) {
@@ -284,11 +304,9 @@
 sub obtain_document
 {
-    my $self = shift(@_);
     my $document_file_full = shift(@_);
     my $documents_directory = shift(@_);
-
-    my $outhandle = $self->{'outhandle'};
-    print $outhandle "Obtaining document file $document_file_full...\n"
-	if ($self->{'verbosity'} > 1);
+    my $verbosity = shift(@_);
+    
+    print STDERR "Obtaining document file $document_file_full...\n" if ($verbosity > 1);
 
     my $document_file_name;
@@ -302,5 +320,5 @@
 
 	my $wget_options = "--quiet";
-	$wget_options = "--verbose" if ($self->{'verbosity'} > 2);
+	$wget_options = "--verbose" if ($verbosity > 2);
 	$wget_options .= " --timestamping";  # Only re-download files if they're newer
 	`wget $wget_options $document_file_full --output-document $local_document_file`;
