Index: /gsdl/trunk/perllib/plugins/OAIPlugin.pm
===================================================================
--- /gsdl/trunk/perllib/plugins/OAIPlugin.pm	(revision 19212)
+++ /gsdl/trunk/perllib/plugins/OAIPlugin.pm	(revision 19213)
@@ -41,4 +41,10 @@
 }
 
+my $set_list =
+    [ { 'name' => "auto",
+	'desc' => "{OAIPlugin.metadata_set.auto}" },
+      { 'name' => "dc",
+	'desc' => "{OAIPlugin.metadata_set.dc}" } 
+      ];
 
 my $arguments = 
@@ -48,4 +54,10 @@
 	'reqd' => "no",
 	'deft' => &get_default_process_exp() },
+      { 'name' => "metadata_set",
+	'desc' => "{OAIPlugin.metadata_set}",
+	'type' => "enumstring",
+	'reqd' => "no",
+	'list' => $set_list,
+	'deft' => "dc" },
       { 'name' => "document_field",
 	'desc' => "{OAIPlugin.document_field}",
@@ -369,41 +381,34 @@
 }
 
-
-sub remap_dcterms_metadata
-{
-    my $self = shift(@_);
-
-    my ($metaname) = @_;
-
-    my $dcterm_mapping = {
-	"alternative" => "dc.title",
-	"tableOfContents" => "dc.description",
-	"abstract" => "dc.description",
-	"created" => "dc.date",
-	"valid" => "dc.date",
-	"available" => "dc.date",
-	"issued" => "dc.date",
-	"modified" => "dc.date",
-	"dateAccepted" => "dc.date",
-	"dateCopyrighted" => "dc.date",
-	"dateSubmitted" => "dc.date",
-	"extent" => "dc.format",
-	"medium" => "dc.format",
-	"isVersionOf" => "dc.relation",
-	"hasVersion" => "dc.relation",
-	"isReplacedBy" => "dc.relation",
-	"replaces" => "dc.relation",
-	"isRequiredBy" => "dc.relation",
-	"requires" => "dc.relation",
-	"isPartOf" => "dc.relation",
-	"hasPart" => "dc.relation",
-	"isReferencedBy" => "dc.relation",
-	"references" => "dc.relation",
-	"isFormatOf" => "dc.relation",
-	"hasFormat" => "dc.relation",
-	"conformsTo" => "dc.relation",
-	"spatial" => "dc.coverage",
-	"temporal" => "dc.coverage",
-# these are top level elements in our qualified dc metadata set
+my $qualified_dc_mapping = {
+    "alternative" => "dc.title",
+    "tableOfContents" => "dc.description",
+    "abstract" => "dc.description",
+    "created" => "dc.date",
+    "valid" => "dc.date",
+    "available" => "dc.date",
+    "issued" => "dc.date",
+    "modified" => "dc.date",
+    "dateAccepted" => "dc.date",
+    "dateCopyrighted" => "dc.date",
+    "dateSubmitted" => "dc.date",
+    "extent" => "dc.format",
+    "medium" => "dc.format",
+    "isVersionOf" => "dc.relation",
+    "hasVersion" => "dc.relation",
+    "isReplacedBy" => "dc.relation",
+    "replaces" => "dc.relation",
+    "isRequiredBy" => "dc.relation",
+    "requires" => "dc.relation",
+    "isPartOf" => "dc.relation",
+    "hasPart" => "dc.relation",
+    "isReferencedBy" => "dc.relation",
+    "references" => "dc.relation",
+    "isFormatOf" => "dc.relation",
+    "hasFormat" => "dc.relation",
+    "conformsTo" => "dc.relation",
+    "spatial" => "dc.coverage",
+    "temporal" => "dc.coverage",
+# these are now top level elements in our qualified dc metadata set
 #	"audience" => "dc.any",
 #	"accrualMethod" => "dc.any",
@@ -413,21 +418,25 @@
 #	"provenance" => "dc.any",
 #	"rightsHolder" => "dc.any",
-	"mediator" => "dc.audience",
-	"educationLevel" => "dc.audience",
-	"accessRights" => "dc.rights",
-	"license" => "dc.rights",
-	"bibliographicCitation" => "dc.identifier"
-	};
+    "mediator" => "dc.audience",
+    "educationLevel" => "dc.audience",
+    "accessRights" => "dc.rights",
+    "license" => "dc.rights",
+    "bibliographicCitation" => "dc.identifier"
+    };
+
+sub remap_dc_metadata
+{
+    my $self = shift(@_);
+
+    my ($metaname) = @_;
 
     my ($prefix,$name) = ($metaname =~ m/^(.*?)\.(.*?)$/);
     
-    if ($prefix eq "dcterms" || $prefix eq "dc")
-    {
-	if (defined $dcterm_mapping->{$name}) 
-	{
-	    return $dcterm_mapping->{$name}."^".$name;
-	}
-
-    }
+    if (defined $qualified_dc_mapping->{$name}) {
+	
+	return $qualified_dc_mapping->{$name}."^".$name;
+    }
+    
+    
     return $metaname; # didn't get a match, return param passed in unchanged
 }
@@ -439,6 +448,4 @@
     my $outhandle = $self->{'outhandle'};
 
-    # Only handles DC metadata
-
     $self->open_prettyprint_metadata_table();
 
@@ -448,22 +455,18 @@
 
 	# locate and remove outermost tag (ignoring any attribute information in top-level tag)
-	my ($wrapper_metadata_xml,$inner_metadata_text) = ($metadata_text =~ m/<([^ >]+).*?>(.*?)<\/\1>/s);
+	my ($outer_tagname,$inner_metadata_text) = ($metadata_text =~ m/<([^ >]+).*?>(.*?)<\/\1>/s);
 	# split tag into namespace and tag name
-	my($namespace,$top_level_prefix) = ($wrapper_metadata_xml =~ m/^(.*?):(.*?)$/);
+	my($namespace,$top_level_prefix) = ($outer_tagname =~ m/^(.*?):(.*?)$/);
 	# sometimes, the dc namespace is not specified as the prefix in each element (like <dc:title>)
 	# but is rather defined in the wrapper element containing the various dc meta elements,
 	# like <dc><title></title><creator></creator></dc>.
 	# In such a case, we use this wrapper element as the top_level_prefix
-	if(!defined $top_level_prefix && defined $wrapper_metadata_xml && $wrapper_metadata_xml =~ m/dc$/) {
-	    $top_level_prefix = $wrapper_metadata_xml;
+	
+	# if there was no prefix, then the tag itself becomes the top_level_prefix
+	if(!defined $top_level_prefix && defined $outer_tagname) {
+	    $top_level_prefix = $outer_tagname;
 	}
 
-	if ($top_level_prefix !~ m/dc$/) {
-	    print $outhandle "Warning: OAIPlugin currently only designed for Dublin Core (or variant) metadata\n";
-	    print $outhandle "         This recorded metadata section '$top_level_prefix' does not appear to match.\n";
-	    print $outhandle "         Metadata assumed to be in form: <prefix:tag>value</prefix:tag> and will be converted\n";
-	    print $outhandle "         into Greenstone metadata as prefix.tag = value\n";
-	}
-
+	#process each element one by one
 	while ($inner_metadata_text =~ m/<([^ >]+).*?>(.*?)<\/\1>(.*)/s)
 	{
@@ -473,12 +476,23 @@
 	    $inner_metadata_text = $3;
 
-	    # $metaname =~ s/^(dc:)?(.)/\u$2/; # strip off optional prefix and uppercase first letter
+	    # greenstone uses . for namespace, while oai uses :
 	    $metaname =~ s/:/\./;
+	    # if there is no namespace, then we use the outer tag name or 
+	    # namespace for this element
 	    if ($metaname !~ m/\./)
 	    {
 		$metaname = "$top_level_prefix.$metaname";
 	    }
-
-	    $metaname = $self->remap_dcterms_metadata($metaname);
+	    
+	    # if metadata set is auto, leave as is, otherwise convert to 
+	    # specified namespace
+	    if ($self->{'metadata_set'} ne "auto") {
+		$metaname =~ s/^([^\.]*)\./$self->{'metadata_set'}\./;
+		if ($self->{'metadata_set'} eq "dc") {
+		    # convert qualified dc terms to gs version, e.g.
+		    # spatial becomes coverage^spatial
+		    $metaname = $self->remap_dc_metadata($metaname);
+		}
+	    }
 
 	    # uppercase the first char of the name
