Index: /main/trunk/greenstone2/perllib/cgiactions/baseaction.pm
===================================================================
--- /main/trunk/greenstone2/perllib/cgiactions/baseaction.pm	(revision 25096)
+++ /main/trunk/greenstone2/perllib/cgiactions/baseaction.pm	(revision 25097)
@@ -67,5 +67,5 @@
 	$err_mess .= "  check-installation\n\n";
 
-	foreach my $a (keys %$action_table) {
+	foreach my $a (sort keys %$action_table) {
 	    $err_mess .= "  $a:\n";
 	    $err_mess .= "    Compulsory args: ";
Index: /main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
===================================================================
--- /main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm	(revision 25096)
+++ /main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm	(revision 25097)
@@ -41,54 +41,76 @@
 }
 
-
 @metadataaction::ISA = ('baseaction');
 
-
 my $action_table =
-{ 
-    "get-live-metadata"     => { 'compulsory-args' => [ "d", "metaname" ],
-			         'optional-args'   => [] }, 
-
-    "get-metadata"          => { 'compulsory-args' => [ "d", "metaname" ],
-			         'optional-args'   => [ "metapos" ] }, 
-
-    "set-live-metadata"     => { 'compulsory-args' => [ "d", "metaname", "metavalue" ],
-			         'optional-args'   => [ ] },
-
-    "set-metadata"          => { 'compulsory-args' => [ "d", "metaname", "metavalue" ],
-			         'optional-args'   => [ "metapos" ] },
-
-	"set-metadata-array"     => { 'compulsory-args' => [ "json" ],
-			         'optional-args'   => [ ] },
+{
+	#GET METHODS
+	"get-import-metadata" => { 
+		'compulsory-args' => [ "d", "metaname" ],
+		'optional-args'   => [ ] },
+
+	"get-archives-metadata" => { 
+		'compulsory-args' => [ "d", "metaname" ],
+		'optional-args'   => [ "metapos" ] },
+	
+	"get-metadata" => { 
+		'compulsory-args' => [ "d", "metaname" ],
+		'optional-args'   => [ "metapos" ] }, 
+
+	"get-live-metadata" => { 
+		'compulsory-args' => [ "d", "metaname" ],
+		'optional-args'   => [ ] }, 
+
+	#SET METHODS
+	"set-live-metadata" => { 
+		'compulsory-args' => [ "d", "metaname", "metavalue" ],
+		'optional-args'   => [ ] },
+
+	"set-metadata" => { 
+		'compulsory-args' => [ "d", "metaname", "metavalue" ],
+		'optional-args'   => [ "metapos" ] },
+
+	"set-archives-metadata" => { 
+		'compulsory-args' => [ "d", "metaname", "metavalue" ],
+		'optional-args'   => [ "metapos", "metamode", "prevmetavalue" ] }, # metamode can be "accumulate", "override",
+	
+	"set-import-metadata" => { 
+		'compulsory-args' => [ "metaname", "metavalue" ],
+		'optional-args'   => [ "d", "f", "metamode" ] }, # metamode can be "accumulate", "override", or "unique-id". Also need to add the ability to specify a previous metadata value to overwrite (because we can't use metapos)
+				 
+	#SET METHODS (ARRAY)
+	"set-metadata-array" => { 
+		'compulsory-args' => [ "json" ],
+		'optional-args'   => [ ] },
 					 
-    "set-archives-metadata" => { 'compulsory-args' => [ "d", "metaname", "metavalue" ],
-			         'optional-args'   => [ "metapos", "metamode" ]
-					  # metamode can be "accumulate", "override",
-				},
-
-    "set-archives-metadata-array" => { 'compulsory-args' => [ "json" ],
-			         'optional-args'   => [ "metamode" ]
-				},
-				
-    "set-import-metadata"   => { 'compulsory-args' => [ "metaname", "metavalue" ],
-			         'optional-args'   => [ "d", "f", "metamode" ] # Need to add the ability to specify a previous metadata value to overwrite (because we can't use metapos)
-				    # metamode can be "accumulate", "override", or "unique-id"
-				 },
-
-	"remove-import-metadata" => { 'compulsory-args' => [ "d", "metaname", "metavalue" ], #TODO: add f argument
-			         'optional-args'   => [ ] },
+	"set-archives-metadata-array" => { 
+		'compulsory-args' => [ "json" ],
+		'optional-args'   => [ ] },
+		
+	"set-import-metadata-array" => {
+		'compulsory-args' => [ "json" ],
+		'optional-args'   => [ ] },
+		
+	#REMOVE METHODS
+	"remove-import-metadata" => { 
+		'compulsory-args' => [ "d", "metaname", "metavalue" ], #TODO: add f argument
+		'optional-args'   => [ ] },
 					 
-	"remove-archives-metadata" => { 'compulsory-args' => [ "d", "metaname" ], #TODO: add f argument
-			         'optional-args'   => [ "metapos", "metavalue" ] },
-
-    "remove-live-metadata"  => { 'compulsory-args' => [ "d", "metaname" ],
-			         'optional-args'   => [ ] },
-
-    "remove-metadata"       => { 'compulsory-args' => [ "d", "metaname" ],
-			         'optional-args'   => [ "metapos", "metavalue" ] },
-
-    "insert-metadata"       => { 'compulsory-args' => [ "d", "metaname", "metavalue" ],
-			         'optional-args'   => [ ]
-			       }
+	"remove-archives-metadata" => { 
+		'compulsory-args' => [ "d", "metaname" ], #TODO: add f argument
+		'optional-args'   => [ "metapos", "metavalue" ] },
+
+	"remove-live-metadata" => {
+		'compulsory-args' => [ "d", "metaname" ],
+		'optional-args'   => [ ] },
+
+	"remove-metadata" => {
+		'compulsory-args' => [ "d", "metaname" ],
+		'optional-args'   => [ "metapos", "metavalue" ] },
+
+	#INSERT METHODS
+    "insert-metadata" => { 
+		'compulsory-args' => [ "d", "metaname", "metavalue" ],
+		'optional-args'   => [ ] }
 };
 
@@ -242,4 +264,235 @@
 
 
+sub get_import_metadata
+{
+	my $self = shift @_;
+
+	my $username  = $self->{'username'};
+	my $collect   = $self->{'collect'};
+	my $gsdl_cgi  = $self->{'gsdl_cgi'};
+	my $gsdlhome  = $self->{'gsdlhome'};
+
+	# Authenticate user if it is enabled
+	if ($baseaction::authentication_enabled) {
+		# Ensure the user is allowed to edit this collection
+		&authenticate_user($gsdl_cgi, $username, $collect);
+	}
+
+	# Obtain the collect dir
+	my $site = $self->{'site'};
+	my $collect_dir = $gsdl_cgi->get_collection_dir($site);
+	##my $collect_dir = &util::filename_cat($gsdlhome, "collect");
+
+	# Make sure the collection isn't locked by someone else
+	$self->lock_collection($username, $collect);
+
+	# look up additional args
+	my $docid     = $self->{'d'};
+	my $metaname  = $self->{'metaname'};
+	my $infodbtype = $self->{'infodbtype'};
+    if (!defined $docid) 
+	{
+		$gsdl_cgi->generate_error_message("No docid (d=...) specified.\n");
+	} 
+
+	# Obtain where the metadata.xml is from the archiveinfo-doc.gdb file
+	# If the doc oid is not specified, we assume the metadata.xml is next to the specified "f"
+	my $metadata_xml_file;
+	my $import_filename = undef;
+	
+
+	my $archive_dir = &util::filename_cat($collect_dir, $collect, "archives");
+	my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
+	my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
+
+	# This now stores the full pathname
+	$import_filename = $doc_rec->{'src-file'}->[0];
+
+	# figure out correct metadata.xml file [?]
+	# Assuming the metadata.xml file is next to the source file
+	# Note: This will not work if it is using the inherited metadata from the parent folder
+	my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename);
+	my $metadata_xml_filename = &util::filename_cat($import_dirname, "metadata.xml");
+
+	$gsdl_cgi->generate_ok_message($self->get_metadata_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $import_tailname));
+
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+}
+
+sub get_metadata_from_metadata_xml
+{
+	my $self = shift @_;
+	my ($gsdl_cgi, $metadata_xml_filename, $metaname, $src_file) = @_;
+	
+	my @rules = 
+	( 
+		_default => 'raw',
+		'Metadata' => \&gfmxml_metadata,
+		'FileName' => \&mxml_filename
+	);
+	    
+	my $parser = XML::Rules->new
+	(
+		rules => \@rules,
+		output_encoding => 'utf8'
+	);
+	
+	my $xml_in = "";
+	if (!open(MIN,"<$metadata_xml_filename")) 
+	{
+		$gsdl_cgi->generate_error("Unable to read in $metadata_xml_filename: $!");
+	}
+	else 
+	{
+		# Read them in
+		my $line;
+		while (defined ($line=<MIN>)) {
+			$xml_in .= $line;
+		}
+		close(MIN);	
+
+		$parser->parse($xml_in, {metaname => $metaname, src_file => $src_file});
+		
+		if(defined $parser->{'pad'}->{'metavalue'})
+		{
+			return $parser->{'pad'}->{'metavalue'};
+		}
+		else
+		{
+			return "";
+		}
+	}
+}
+
+sub gfmxml_metadata
+{
+	my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_;
+
+	if (($parser->{'parameters'}->{'src_file'} eq $parser->{'parameters'}->{'current_file'}) && ($attrHash->{'name'} eq $parser->{'parameters'}->{'metaname'}))
+	{
+		$parser->{'pad'}->{'metavalue'} = $attrHash->{'_content'};
+	}
+}
+
+sub get_archives_metadata
+{
+	my $self = shift @_;
+
+	my $username  = $self->{'username'};
+	my $collect   = $self->{'collect'};
+	my $gsdl_cgi  = $self->{'gsdl_cgi'};
+	my $gsdlhome  = $self->{'gsdlhome'};
+	my $infodbtype = $self->{'infodbtype'};
+
+	# Authenticate user if it is enabled
+	if ($baseaction::authentication_enabled) {
+		# Ensure the user is allowed to edit this collection
+		&authenticate_user($gsdl_cgi, $username, $collect);
+	}
+
+	# Obtain the collect dir
+	my $site = $self->{'site'};
+	my $collect_dir = $gsdl_cgi->get_collection_dir($site);
+	
+	my $archive_dir = &util::filename_cat($collect_dir, $collect, "archives");
+
+	# Make sure the collection isn't locked by someone else
+	$self->lock_collection($username, $collect);
+	
+	# look up additional args
+	my ($docid, $docid_secnum) = ($self->{'d'} =~ m/^(.*?)(\..*)?$/);
+	$docid_secnum = "" if (!defined $docid_secnum);
+	
+	my $metaname = $self->{'metaname'};
+	my $metapos = $self->{'metapos'};
+	$metapos = 0 if (!defined $metapos);
+	
+	my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
+	my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
+
+	# This now stores the full pathname
+	my $doc_filename = $doc_rec->{'doc-file'}->[0];	
+
+	$gsdl_cgi->generate_ok_message($self->get_metadata_from_archive_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, $docid_secnum));
+
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+}
+
+sub get_metadata_from_archive_xml
+{
+	my $self = shift @_;
+	my ($gsdl_cgi, $doc_xml_filename, $metaname, $metapos, $secid) = @_;
+	
+	my @start_rules = ('Section' => \&dxml_start_section);
+	
+	my @rules = 
+	( 
+		_default => 'raw',
+		'Metadata' => \&gfdxml_metadata
+	);
+	    
+	my $parser = XML::Rules->new
+	(
+		start_rules => \@start_rules,
+		rules => \@rules,
+		output_encoding => 'utf8'
+	);
+	
+	my $xml_in = "";
+	if (!open(MIN,"<$doc_xml_filename")) 
+	{
+		$gsdl_cgi->generate_error("Unable to read in $doc_xml_filename: $!");
+	}
+	else 
+	{
+		# Read them in
+		my $line;
+		while (defined ($line=<MIN>)) {
+			$xml_in .= $line;
+		}
+		close(MIN);	
+
+		$parser->parse($xml_in, {metaname => $metaname, metapos => $metapos, secid => $secid});
+		
+		if(defined $parser->{'pad'}->{'metavalue'})
+		{
+			return $parser->{'pad'}->{'metavalue'};
+		}
+		else
+		{
+			return "";
+		}
+	}
+}
+
+sub gfdxml_metadata
+{
+	my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_;
+	
+	if(!($parser->{'parameters'}->{'secid'} eq $parser->{'parameters'}->{'curr_section_num'}))
+	{
+		return;
+	}
+
+	if ($parser->{'parameters'}->{'metaname'} eq $attrHash->{'name'})
+	{
+		if (!defined $parser->{'parameters'}->{'poscount'})
+		{
+			$parser->{'parameters'}->{'poscount'} = 0;
+		}
+		else
+		{
+			$parser->{'parameters'}->{'poscount'}++;
+		}
+	}
+
+	if (($parser->{'parameters'}->{'metaname'} eq $attrHash->{'name'}) && ($parser->{'parameters'}->{'poscount'} == $parser->{'parameters'}->{'metapos'}))
+	{	
+		$parser->{'pad'}->{'metavalue'} = $attrHash->{'_content'};
+	}
+}
+
 sub set_live_metadata
 {
@@ -394,6 +647,4 @@
     $self->unlock_collection($username, $collect);
 }
-
-
 
 
@@ -471,5 +722,4 @@
 
 
-
 sub dxml_metadata
 {
@@ -491,15 +741,34 @@
 ##    print STDERR "**** metamode = $metamode\n";
     
-    if ((!defined $opt_doc_secnum) || ($opt_doc_secnum eq $curr_secnum)) {
-	my $name_attr = $attrHash->{'name'};
-	if (($name_attr eq $metaname) && ($metamode eq "override")) {
-##	    print STDERR "**** got match!!\n";
-	    # Get the value and override the current value
-	    my $metavalue = $parser->{'parameters'}->{'metavalue'};
-	    $attrHash->{'_content'} = $metavalue;
-	    
-	    # Don't want it to wipe out any other pieces of metadata
-	    $parser->{'parameters'}->{'metamode'} = "done";
-	}
+    if ((!defined $opt_doc_secnum) || ($opt_doc_secnum eq $curr_secnum)) 
+	{
+		my $name_attr = $attrHash->{'name'};
+		if (($name_attr eq $metaname) && ($metamode eq "override")) 
+		{
+			if (!defined $parser->{'parameters'}->{'poscount'}) 
+			{ 
+				$parser->{'parameters'}->{'poscount'} = 0; 
+			} 
+			else 
+			{ 
+				$parser->{'parameters'}->{'poscount'}++; 
+			} 
+			
+			if(defined $parser->{'parameters'}->{'metapos'} && $parser->{'parameters'}->{'poscount'} == $parser->{'parameters'}->{'metapos'})
+			{
+				##print STDERR "**** got match!!\n";
+				# Get the value and override the current value
+				my $metavalue = $parser->{'parameters'}->{'metavalue'};
+				$attrHash->{'_content'} = $metavalue;
+				
+				# Don't want it to wipe out any other pieces of metadata
+				$parser->{'parameters'}->{'metamode'} = "done";
+			}
+			else if(defined $parser->{'parameters'}->{'prevmetavalue'} && $parser->{'parameters'}->{'prevmetavalue'} == $attrHash->{'_content'})
+			{
+				$attrHash->{'_content'} = $metavalue;
+				$parser->{'parameters'}->{'metamode'} = "done";
+			}
+		}
     }
 
@@ -544,5 +813,4 @@
 
 
-
 sub dxml_start_section
 {
@@ -581,5 +849,5 @@
     $parser->{'parameters'}->{'curr_section_num'}   = $new_secnum;
 
-    print STDERR "*** In Section: $new_secnum\n";
+    ##print STDERR "*** In Section: $new_secnum\n";
 }
 
@@ -625,9 +893,8 @@
 }
 
-
 sub edit_doc_xml
 {
     my $self = shift @_;
-    my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos, $metamode, $opt_secnum) = @_;
+    my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos, $metamode, $opt_secnum, $prevmetavalue) = @_;
 
     # To monitor which section/subsection number we are in
@@ -646,5 +913,6 @@
 		    'metapos'   => $metapos,
 		    'metavalue' => $metavalue,
-		    'metamode'  => $metamode };
+		    'metamode'  => $metamode,
+			'prevmetavalue' => $prevmetavalue };
 			
     if (defined $opt_secnum) {
@@ -658,5 +926,5 @@
 {
   	my $self = shift @_;
-	my ($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid,$metaname,$metapos,$metavalue,$metamode) = @_;
+	my ($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid,$metaname,$metapos,$metavalue,$metamode,$prevmetavalue) = @_;
 	
     # Obtain the doc.xml path for the specified docID
@@ -676,10 +944,6 @@
     # Running import.pl -groupsize will cause this to have multiple sections in one doc.xml
 	
-	print STDERR "** away to call edit_doc_xml\n";
-	
     $self->edit_doc_xml($gsdl_cgi,$doc_xml_filename,
-			$metaname,$metavalue,$metapos,$metamode,$docid_secnum);
-			
-	print STDERR "*** finished edit_doc_xml\n";
+			$metaname,$metavalue,$metapos,$metamode,$docid_secnum,$prevmetavalue);
 	
 	return 0; # return 0 for now to indicate no error
@@ -717,4 +981,5 @@
     my $metaname   = $self->{'metaname'};
     my $metavalue  = $self->{'metavalue'};
+	my $prevmetavalue = $self->{'prevmetavalue'}
 	
     my $metapos    = $self->{'metapos'};
@@ -729,5 +994,5 @@
 	
 	my $status = $self->set_archives_metadata_entry($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid,
-				$metaname,$metapos,$metavalue,$metamode);
+				$metaname,$metapos,$metavalue,$metamode,$prevmetavalue);
    
     # Release the lock once it is done
@@ -876,7 +1141,7 @@
 
 	# This now stores the full pathname
-	my $import_filename = $doc_rec->{'doc-file'}->[0];	
-
-	my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $import_filename), $metaname, $metapos, undef, $docid_secnum);
+	my $doc_filename = $doc_rec->{'doc-file'}->[0];	
+
+	my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, undef, $docid_secnum);
 	
 	# Release the lock once it is done
@@ -1000,5 +1265,5 @@
 
     # Report error if we don't see FileName tag before this
-    die "Fatel Error: Unexpected metadata.xml structure. Undefind current_file, possiblely encountered Description before FileName" if (!defined($parser->{'parameters'}->{'current_file'}));
+    die "Fatal Error: Unexpected metadata.xml structure. Undefind current_file, possiblely encountered Description before FileName" if (!defined($parser->{'parameters'}->{'current_file'}));
     
     # Don't do anything if we are not in the right FileSet
@@ -1040,5 +1305,5 @@
 
     # Failed... Report error if we don't see FileName tag before this
-    die "Fatel Error: Unexpected metadata.xml structure. Undefind current_file, possiblely encountered Description before FileName" if (!defined($parser->{'parameters'}->{'current_file'}));
+    die "Fatal Error: Unexpected metadata.xml structure. Undefind current_file, possiblely encountered Description before FileName" if (!defined($parser->{'parameters'}->{'current_file'}));
 
     # Don't do anything if we are not in the right FileSet
@@ -1218,6 +1483,6 @@
 	
     if ($baseaction::authentication_enabled) {
-	# Ensure the user is allowed to edit this collection
-	$self->authenticate_user($username, $collect);
+		# Ensure the user is allowed to edit this collection
+		$self->authenticate_user($username, $collect);
     }
 
@@ -1297,4 +1562,82 @@
 }
 
+sub set_import_metadata_array
+{
+	my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdlhome  = $self->{'gsdlhome'};
+
+    if ($baseaction::authentication_enabled) {
+		# Ensure the user is allowed to edit this collection
+		&authenticate_user($gsdl_cgi, $username, $collect);
+    }
+
+	my $site = $self->{'site'};
+	my $collect_dir = $gsdl_cgi->get_collection_dir($site);
+	
+    $gsdl_cgi->checked_chdir($collect_dir);
+
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+    # look up additional args
+	
+	my $infodbtype = $self->{'infodbtype'};
+
+	my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
+	
+	my $json_str = $self->{'json'};
+	my $doc_array = decode_json $json_str;
+	
+	my $global_status = 0;
+	my $global_mess = "";
+	
+	my @all_docids = ();
+	
+	foreach my $doc_array_rec ( @$doc_array ) 
+	{	
+		my $docid = $doc_array_rec->{'docid'};
+		my $metaname = $doc_array_rec->{'metaname'};
+		my $metamode = $self->{'metamode'};
+		my $metavalue = $doc_array_rec->{'metavalue'};
+
+		if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
+			# make "accumulate" the default (less destructive, as won't actually 
+			# delete any existing values)
+			$metamode = "accumulate";
+		} 
+
+		push(@all_docids,$docid);
+
+		# Obtain where the metadata.xml is from the archiveinfo-doc.gdb file
+		# If the doc oid is not specified, we assume the metadata.xml is next to the specified "f"
+		my $metadata_xml_file;
+		my $import_filename = undef;
+
+		my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
+		my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
+
+		# This now stores the full pathname
+		$import_filename = $doc_rec->{'src-file'}->[0];	
+
+		# figure out correct metadata.xml file [?]
+		# Assuming the metadata.xml file is next to the source file
+		# Note: This will not work if it is using the inherited metadata from the parent folder
+		my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename);
+		my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml");
+
+		$self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $metamode, $import_tailname);
+	}
+
+	my $mess = "set-archives-metadata-array successful: Keys[ ".join(", ",@all_docids)."]\n";
+	$gsdl_cgi->generate_ok_message($mess);
+    
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+}
+
 sub remove_import_metadata
 {
@@ -1328,5 +1671,5 @@
 	if ((!defined $docid) || ($docid =~ m/^\s*$/)) 
 	{
-		die "No docid (d=...) specified.\n";
+		$gsdl_cgi->generate_error_message("No docid (d=...) specified.\n");
 	}
 	
@@ -1350,5 +1693,5 @@
 	if((!defined $import_filename) || ($import_filename =~ m/^\s*$/))
 	{
-		die "There is no metadata\n";
+		$gsdl_cgi->generate_error_message("There is no metadata\n");
 	}
 	
