Index: /gsdl/trunk/perllib/doc.pm
===================================================================
--- /gsdl/trunk/perllib/doc.pm	(revision 19493)
+++ /gsdl/trunk/perllib/doc.pm	(revision 19494)
@@ -999,4 +999,19 @@
 }
 
+
+sub metadata_file {
+    my $self = shift (@_);
+    my ($real_filename, $filename) = @_;
+    
+    push (@{$self->{'metadata_files'}}, 
+	  [$real_filename, $filename]);
+}
+
+sub get_meta_files {
+    my $self = shift (@_);
+
+    return $self->{'metadata_files'};
+}
+
 sub delete_section_assoc_files {
     my $self = shift (@_);
Index: /gsdl/trunk/perllib/plugouts/BasePlugout.pm
===================================================================
--- /gsdl/trunk/perllib/plugouts/BasePlugout.pm	(revision 19493)
+++ /gsdl/trunk/perllib/plugouts/BasePlugout.pm	(revision 19494)
@@ -493,4 +493,8 @@
         print $outhandle "Writing associated files to $doc_dir\n";
 	$self->process_assoc_files ($doc_obj, $doc_dir);
+
+	# look up 'gsdlmetafile' metadata and store that information
+	# explicitly in $doc_obj
+	$self->process_metafiles_metadata ($doc_obj);
     }
 
@@ -643,38 +647,29 @@
 
 
-sub archiveinf_gdbm
+sub process_metafiles_metadata 
 {
     my $self = shift (@_);
     my ($doc_obj) = @_;
 
-    my $verbosity = $self->{'verbosity'};
-
-    my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
-    if (defined $collect_dir) {
-	my $dirsep_regexp = &util::get_os_dirsep();
-
-	if ($collect_dir !~ /$dirsep_regexp$/) {
-	    # ensure there is a slash at the end
-	    $collect_dir .= &util::get_dirsep(); 
-	}
-    }
-
-    my $oid = $doc_obj->get_OID();
-    my $source_filename = $doc_obj->get_source_filename();
-
-    my $working_info = $self->{'output_info'}; 
-    my $doc_info = $working_info->get_info($oid);
-    my ($doc_file,$index_status) = @$doc_info;
-
-    my $oid_files = { 'doc-file' => $doc_file,
-		      'index-status' => $index_status,
-		      'src-file' => $source_filename,
-		      'assoc-files' => [] };
-    
-    my %reverse_lookups = ( $source_filename => "1" );
-
-    foreach my $assoc_file_rec (@{$doc_obj->get_assoc_files()}) {
-	my $real_filename = $assoc_file_rec->[0];
-	my $full_afile = $assoc_file_rec->[1];
+    my $top_section = $doc_obj->get_top_section();
+    my $metafiles = $doc_obj->get_metadata($top_section,"gsdlmetafile");
+
+    foreach my $metafile_pair (@$metafiles) {
+	my ($full_metafile,$metafile) = split(/:/,$metafile_pair);
+
+	$doc_obj->metadata_file($full_metafile,$metafile);
+    }
+
+    $doc_obj->delete_metadata($top_section,"gsdlmetafile");
+}
+
+sub archiveinf_files_to_field
+{
+    my $self = shift(@_);
+    my ($files,$field,$collect_dir,$oid_files,$reverse_lookups) = @_;
+
+    foreach my $file_rec (@$files) {
+	my $real_filename = $file_rec->[0];
+	my $full_file = $file_rec->[1];
 
 	# for some reasons the image associate file has / before the full path
@@ -690,8 +685,7 @@
 	    }
 
-	    $reverse_lookups{$real_filename} = 1;
-
-	    push(@{$oid_files->{'assoc-files'}},$full_afile);
-
+	    $reverse_lookups->{$real_filename} = 1;
+
+	    push(@{$oid_files->{$field}},$full_file);
 	}
 	else {
@@ -699,4 +693,70 @@
 	}
     }
+}
+
+sub archiveinf_gdbm
+{
+    my $self = shift (@_);
+    my ($doc_obj) = @_;
+
+    my $verbosity = $self->{'verbosity'};
+
+    my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
+    if (defined $collect_dir) {
+	my $dirsep_regexp = &util::get_os_dirsep();
+
+	if ($collect_dir !~ /$dirsep_regexp$/) {
+	    # ensure there is a slash at the end
+	    $collect_dir .= &util::get_dirsep(); 
+	}
+    }
+
+    my $oid = $doc_obj->get_OID();
+    my $source_filename = $doc_obj->get_source_filename();
+
+    my $working_info = $self->{'output_info'}; 
+    my $doc_info = $working_info->get_info($oid);
+    my ($doc_file,$index_status) = @$doc_info;
+
+    my $oid_files = { 'doc-file' => $doc_file,
+		      'index-status' => $index_status,
+		      'src-file' => $source_filename,
+		      'assoc-files' => [],
+		      'meta-files'  => [] };
+    
+    my $reverse_lookups = { $source_filename => "1" };
+
+
+    $self->archiveinf_files_to_field($doc_obj->get_assoc_files(),"assoc-files",
+				     $collect_dir,$oid_files,$reverse_lookups);
+
+#    foreach my $assoc_file_rec (@{$doc_obj->get_assoc_files()}) {
+#	my $real_filename = $assoc_file_rec->[0];
+#	my $full_afile = $assoc_file_rec->[1];
+#
+#	# for some reasons the image associate file has / before the full path
+#	$real_filename =~ s/^\\(.*)/$1/i;
+#	if (-e $real_filename) {
+#
+#	    if (defined $collect_dir) {
+#		my $collect_dir_re_safe = $collect_dir;
+#		$collect_dir_re_safe =~ s/\\/\\\\/g;
+#		$collect_dir_re_safe =~ s/\./\\./g;
+#
+#		$real_filename =~ s/^$collect_dir_re_safe//;
+#	    }
+#
+#	    $reverse_lookups->{$real_filename} = 1;
+#
+#	    push(@{$oid_files->{'assoc-files'}},$full_afile);
+#	}
+#	else {
+#	    print STDERR "Warning: archiveinf_gdbm()\n  $real_filename does not appear to be on the file system\n";
+#	}
+#    }
+
+    $self->archiveinf_files_to_field($doc_obj->get_meta_files(),"meta-files",
+				     $collect_dir,$oid_files,$reverse_lookups);
+
 
     # better not to commit to a particular db implementation, but
@@ -712,7 +772,13 @@
     $doc_db_text .= "<index-status>$oid_files->{'index-status'}\n";
     $doc_db_text .= "<src-file>$oid_files->{'src-file'}\n";
+
     foreach my $af (@{$oid_files->{'assoc-files'}}) {
 	$doc_db_text .= "<assoc-file>$af\n";
     }
+
+    foreach my $mf (@{$oid_files->{'meta-files'}}) {
+	$doc_db_text .= "<meta-file>$mf\n";
+    }
+
     chomp($doc_db_text); # remove trailing \n
 
@@ -720,5 +786,5 @@
     &GDBMUtils::gdbmDatabaseSet($doc_db,$oid,$doc_db_text);
 
-    foreach my $rl (keys %reverse_lookups) {
+    foreach my $rl (keys %$reverse_lookups) {
 	&GDBMUtils::gdbmDatabaseAppend($src_db,$rl,"<oid>$oid\n");
     }
Index: /gsdl/trunk/perllib/plugouts/GreenstoneXMLPlugout.pm
===================================================================
--- /gsdl/trunk/perllib/plugouts/GreenstoneXMLPlugout.pm	(revision 19493)
+++ /gsdl/trunk/perllib/plugouts/GreenstoneXMLPlugout.pm	(revision 19494)
@@ -77,4 +77,6 @@
 	$self->process_assoc_files ($doc_obj, $doc_dir, '');
 	
+	$self->process_metafiles_metadata ($doc_obj);
+
 	my $output_file = util::filename_cat ($working_dir, "doc.xml");
 	
