Index: /trunk/gsdl/perllib/doc.pm
===================================================================
--- /trunk/gsdl/perllib/doc.pm	(revision 9952)
+++ /trunk/gsdl/perllib/doc.pm	(revision 9953)
@@ -283,5 +283,5 @@
 sub buffer_mets_fileSection_section_xml() {
     my $self = shift(@_);
-    my ($section) = @_;
+    my ($section,$version) = @_;
 
     #$section="" unless defined $section;
@@ -292,24 +292,25 @@
  
 
-    #**output fileSection by sections
+    # output fileSection by sections
     my $section_num ="1". $section;
-  
-    
-    #my $filePath = $doc_Dir . '/doctxt.xml';
-
+      
     my $filePath = 'doctxt.xml';
 
-    #**output the fileSection details
+    my $opt_owner_id = "";
+    if ($version eq "fedora") {
+	$opt_owner_id = "OWNERID=\"M\"";
+    }
+
+    # output the fileSection details
     my $all_text = '  <mets:fileGrp ID="FILEGROUP_PRELUDE' . $section_num . '">'. "\n";
-    $all_text .= '    <mets:file MIMETYPE="text/xml" ID="FILE'.$section_num. '">'. "\n";
+    $all_text .= "    <mets:file MIMETYPE=\"text/xml\" ID=\"FILE$section_num\" $opt_owner_id >\n";
     $all_text .= '      <mets:FLocat LOCTYPE="URL" xlink:href="file:'.$filePath.'#xpointer(/Section[';
     
     my $xpath = "1".$section;
- 
     $xpath =~ s/\./]\/Section[/g;
    
     $all_text .=  $xpath;
 
-    $all_text .= ']/text())" />' . "\n";
+    $all_text .= ']/text())" xlink:title="Hierarchical Document Structure"/>' . "\n";
     $all_text .= "    </mets:file>\n";
     $all_text .= "  </mets:fileGrp>\n";
@@ -317,5 +318,5 @@
 
     foreach my $subsection (@{$section_ptr->{'subsection_order'}}){
-	$all_text .= $self->buffer_mets_fileSection_section_xml("$section.$subsection");
+	$all_text .= $self->buffer_mets_fileSection_section_xml("$section.$subsection",$version);
     }
     
@@ -327,5 +328,5 @@
 sub buffer_mets_fileWhole_section_xml(){
     my $self = shift(@_);
-    my ($section) = @_;
+    my ($section,$version,$working_dir) = @_;
 
     my $section_ptr = $self-> _lookup_section($section);
@@ -334,18 +335,31 @@
     my $all_text="" unless defined $all_txt;
 
-    my ($dirPath)="" unless defined $dirPath;
     my $fileID=0;
 
-    #** output the fileSection for the whole section
-    #*** get the sourcefile and associative file
+    # Output the fileSection for the whole section
+    #  => get the sourcefile and associative file
+
+    my $id_root = "";
+    my $opt_owner_id = "";    
+
+    if ($version eq "fedora") {
+	$opt_owner_id = "OWNERID=\"M\"";
+    }
+    else {
+	$id_root = "default";
+    }
+
+    if ($version ne "fedora") {
+	$all_text .= "  <mets:fileGrp ID=\"$id_root\">\n";
+    }
 
     foreach my $data (@{$section_ptr->{'metadata'}}){
        my $escaped_value = &_escape_text($data->[1]);
-       if ($data->[0] eq "gsdlsourcefilename") { 
-          ($dirPath) = $escaped_value =~ m/^(.*)[\/\\][^\/\\]*$/;
-	  
-	  $all_text .= '  <mets:fileGrp ID="default">'."\n";
-          ++$fileID;
-          $all_text .= '    <mets:file MIMETYPE="text/xml" ID="default.'.$fileID.'">'. "\n";
+
+       if (($data->[0] eq "gsdlsourcefilename") && ($version ne "fedora")) { 
+          my ($dirPath) = $escaped_value =~ m/^(.*)[\/\\][^\/\\]*$/;
+
+          ++$fileID;	  
+          $all_text .= "    <mets:file MIMETYPE=\"text/xml\" ID=\"$id_root.$fileID\" $opt_owner_id >\n";
         
 	  $all_text .= '      <mets:FLocat LOCTYPE="URL" xlink:href="file:'.$data->[1].'" />'."\n";
@@ -355,22 +369,71 @@
        
        if ($data->[0] eq "gsdlassocfile"){
-
+	   
 	   $escaped_value =~ m/^(.*?):(.*):(.*)$/;
 	   my $assoc_file = $1;
 	   my $mime_type  = $2;
 	   my $assoc_dir  = $3;
-
-	  my $assfilePath = $dirPath . '/'. $assoc_file;
-          ++$fileID;
-
-	  $all_text .= '    <mets:file MIMETYPE="'.$mime_type.'" ID="default.'.$fileID. '">'. "\n";
-	  $all_text .= '      <mets:FLocat LOCTYPE="URL" xlink:href="file:'.$assfilePath.'" />'."\n";
-          
-	  $all_text .= "    </mets:file>\n";
+	   
+	   if ($version eq "fedora") {
+	       $id_root = $assoc_file;
+	       $id_root =~ s/\//_/g;
+	       $all_text .= "  <mets:fileGrp ID=\"$id_root\">\n";
+	   }
+	   
+	   my $assfilePath = ($assoc_dir eq "") ? $assoc_file : "$assoc_dir/$assoc_file";
+	   ++$fileID;
+	   
+	   my $mime_attr   = "MIMETYPE=\"$mime_type\"";
+	   my $xlink_title = "xlink:title=\"$assoc_file\"";
+
+	   my $id_attr;
+	   my $xlink_href;
+
+	   if ($version eq "fedora") {
+	       $id_attr = "ID=\"$id_root.0\"";
+
+	       my $fedora_prefix = $ENV{'FEDORA_PREFIX'};
+	       if (!defined $fedora_prefix) {
+		   $xlink_href  = "xlink:href=\"$assfilePath\"";
+	       }
+	       else
+	       {
+		   my $gsdlhome = $ENV{'GSDLHOME'};
+		   my $gsdl_href = "$working_dir/$assfilePath";
+
+		   $gsdl_href =~ s/^$gsdlhome(\/)?//;
+		   $gsdl_href = "/gsdl/$gsdl_href";
+
+		   my $fserver = $ENV{'FEDORA_HOSTNAME'};
+		   my $fport = $ENV{'FEDORA_SERVER_PORT'};
+
+		   my $fdomain = "http://$fserver:$fport";
+		   $xlink_href  = "xlink:href=\"$fdomain$gsdl_href\"";
+	       }
+
+	       my $top_section = $self->get_top_section();
+	       my $id = $self->get_metadata_element($top_section,"Identifier");
+	   }
+	   else {
+	       $id_attr = "ID=\"$id_root.$fileID\"";
+	       $xlink_href  = "xlink:href=\"$assfilePath\"";
+	   }
+
+	   $all_text .= "    <mets:file $mime_attr $id_attr $opt_owner_id >\n";
+	   $all_text .= "      <mets:FLocat LOCTYPE=\"URL\" $xlink_href $xlink_title />\n";
+	   
+	   $all_text .= "    </mets:file>\n";
+	   
+	   if ($version eq "fedora") {
+	       $all_text .= "  </mets:fileGrp>\n";
+	   }
+	   
        }
-    }
-    $all_text .= "  </mets:fileGrp>\n";
-                                            
-                                      
+   }
+    
+    if ($version ne "fedora") {
+	$all_text .= "  </mets:fileGrp>\n";
+    }         
+    
     $all_text =~ s/[\x00-\x09\x0B\x0C\x0E-\x1F]//g;
     
@@ -378,5 +441,5 @@
 }
 
-sub buffer_mets_StruMapSection_section_xml(){
+sub buffer_mets_StructMapSection_section_xml(){
     my $self = shift(@_);
     my ($section, $order_numref) = @_;
@@ -389,5 +452,5 @@
 
 
-    #***output fileSection by Sections
+    # output fileSection by Sections
     my $section_num ="1". $section;
     my $dmd_num = $section_num;
@@ -398,9 +461,11 @@
     #}
 
-    #**output the StruMap details
+    #**output the StructMap details
  
-    my $all_text = '  <mets:div ID="DS'. $section_num .'" TYPE="Section" ORDER="'.$$order_numref++.'" ORDERLABEL="'. $section_num .'" LABEL="';
-
-    $all_text .= $section_num . '" DMDID="DM'.$dmd_num.'">'. "\n";
+    my $dmdid_attr = "DM$dmd_num";
+
+    my $all_text = "  <mets:div ID=\"DS$section_num\" TYPE=\"Section\" \n";
+    $all_text .= '      ORDER="'.$$order_numref++.'" ORDERLABEL="'. $section_num .'" '."\n";
+    $all_text .= "      LABEL=\"$section_num\" DMDID=\"$dmdid_attr\">\n";
    
     $all_text .= '    <mets:fptr FILEID="FILEGROUP_PRELUDE'.$section_num.'" />'. "\n";
@@ -408,5 +473,5 @@
 
     foreach my $subsection (@{$section_ptr->{'subsection_order'}}){
-       $all_text .= $self->buffer_mets_StruMapSection_section_xml("$section.$subsection", $order_numref);
+       $all_text .= $self->buffer_mets_StructMapSection_section_xml("$section.$subsection", $order_numref);
     }
     
@@ -419,5 +484,5 @@
 
 
-sub buffer_mets_StruMapWhole_section_xml(){
+sub buffer_mets_StructMapWhole_section_xml(){
     my $self = shift(@_);
     my ($section) = @_;
@@ -430,10 +495,8 @@
     my $order_num = 0;
 
-    $all_text .= '<mets:structMap ID="All" TYPE="Whole Document" LABEL="All">'."\n";
     $all_text .= '  <mets:div ID="DSAll" TYPE="Document" ORDER="'.$order_num.'" ORDERLABEL="All" LABEL="Whole Documemt" DMDID="DM1">' . "\n";
   
-
-    #** output the StruMapSection for the whole section
-    #*** get the sourcefile and associative file
+    #** output the StructMapSection for the whole section
+    #  get the sourcefile and associative file
 
     foreach my $data (@{$section_ptr->{'metadata'}}){
@@ -460,5 +523,5 @@
 sub buffer_mets_dmdSection_section_xml(){
     my $self = shift(@_);
-    my ($section) = @_;
+    my ($section,$version) = @_;
    
     $section="" unless defined $section;
@@ -467,5 +530,5 @@
     return "" unless defined $section_ptr;
 
-    #***convert section number
+    # convert section number
     my $section_num ="1". $section;
     my $dmd_num = $section_num;
@@ -475,21 +538,60 @@
     #	$dmd_num = "0";
     # }
-    my $all_text = '<mets:dmdSec ID="DM'.$dmd_num.'" GROUPID="'.$section_num.'">'. "\n";
-    $all_text .= '  <mets:mdWrap MDTYPE="OTHER" OTHERMDTYPE="gsdl3" ID="gsdl'.$section_num.'">'."\n";
+
+
+    my $all_text = "";
+
+    my $label_attr = "";
+    if ($version eq "fedora") {
+	$all_text .= "<mets:amdSec ID=\"DC\" >\n";
+	$all_text .= "  <mets:techMD ID=\"DC.0\">\n"; # .0 fedora version number?
+
+	$label_attr = "LABEL=\"Dublin Core Metadata\"";
+    }
+    else {
+	print STDERR "***** Check that GROUPID in dmdSec is valid!!!\n";
+	print STDERR "***** Check to see if <techMD> required\n";
+	# if it isn't allowed, go back and set $mdTag = dmdSec/amdSec
+
+	$all_text .= "<mets:dmdSec ID=\"DM$dmd_num\" GROUPID=\"$section_num\">\n";
+    }
+
+    $all_text .= "  <mets:mdWrap $label_attr MDTYPE=\"OTHER\" OTHERMDTYPE=\"gsdl3\" ID=\"gsdl$section_num\">\n";
     $all_text .= "    <mets:xmlData>\n";
-    foreach my $data (@{$section_ptr->{'metadata'}}){
-       my $escaped_value = &_escape_text($data->[1]);
-       $all_text .= '      <gsdl3:Metadata name="'. $data->[0].'">'. $escaped_value. "</gsdl3:Metadata>\n";
-       if ($data->[0] eq "dc.Title") {
-	   $all_text .= '      <gsdl3:Metadata name="Title">'. $escaped_value."</gsdl3:Metadata>\n";
-       }
+
+    if ($version eq "fedora") {
+	my $dc_namespace = "";
+	$dc_namespace .= "xmlns:dc=\"http://purl.org/dc/elements/1.1/\"";
+	$dc_namespace .= " xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\">\n";
+
+	$all_text .= "  <oai_dc:dc $dc_namespace>\n";
+
+	$all_text .= $self->buffer_dc_section($section,"oai_dc");
+	$all_text .= "  </oai_dc:dc>\n";
+    }
+    else {
+	foreach my $data (@{$section_ptr->{'metadata'}}){
+	    my $escaped_value = &_escape_text($data->[1]);
+	    $all_text .= '      <gsdl3:Metadata name="'. $data->[0].'">'. $escaped_value. "</gsdl3:Metadata>\n";
+	    if ($data->[0] eq "dc.Title") {
+		$all_text .= '      <gsdl3:Metadata name="Title">'. $escaped_value."</gsdl3:Metadata>\n";
+	    }
+	}
     }
    
     $all_text .= "    </mets:xmlData>\n";
     $all_text .= "  </mets:mdWrap>\n";
-    $all_text .= "</mets:dmdSec>\n";
+    
+    if ($version eq "fedora") {
+	$all_text .= "  </mets:techMD>\n";
+	$all_text .= "</mets:amdSec>\n";
+    }
+    else {
+	$all_text .= "</mets:dmdSec>\n";    
+    }
+
 
     foreach my $subsection (@{$section_ptr->{'subsection_order'}}){
-       $all_text .= $self->buffer_mets_dmdSection_section_xml("$section.$subsection");
+       $all_text .= $self->buffer_mets_dmdSection_section_xml("$section.$subsection",$version);
     }
     
@@ -506,5 +608,5 @@
 }
 
-#*** print out DSpace dublin_core metadata section
+#  print out DSpace dublin_core metadata section
 sub output_dspace_section {
     my $self = shift (@_);
@@ -534,5 +636,5 @@
 }
 
-#*** print out doctxt.xml file
+#  print out doctxt.xml file
 sub output_txt_section {
     my $self = shift (@_);
@@ -542,27 +644,49 @@
 }
 
-#*** print out docmets.xml file
+#  print out docmets.xml file
 sub output_mets_section {
     my $self = shift(@_);
-    my ($handle, $section) = @_;
-
-    #***print out the dmdSection
-    print $handle $self->buffer_mets_dmdSection_section_xml($section);
-
-    #***print out the fileSection by sections
+    my ($handle, $section, $version, $working_dir) = @_;
+
+    # print out the dmdSection
+    print $handle $self->buffer_mets_dmdSection_section_xml($section, $version);
+
     print $handle "<mets:fileSec>\n";
-    print $handle $self->buffer_mets_fileSection_section_xml($section);
-
-    #***print out the whole fileSection
-    print $handle $self->buffer_mets_fileWhole_section_xml($section); 
+    if ($version eq "fedora") {
+	print $handle "  <mets:fileGrp ID=\"DATASTREAMS\">\n";
+    }
+
+    # print out the fileSection by sections
+    print $handle $self->buffer_mets_fileSection_section_xml($section,$version);
+
+    # print out the whole fileSection
+    print $handle $self->buffer_mets_fileWhole_section_xml($section,$version,$working_dir); 
+
+    if ($version eq "fedora") {
+	print $handle "  </mets:fileGrp>\n";
+    }
     print $handle "</mets:fileSec>\n";
-    
-    #***print out the StruMapSection by sections
-    print $handle '<mets:structMap ID="Section" TYPE="Section" LABEL="Section">' . "\n";
-    my $order_num=0;
-    print $handle $self->buffer_mets_StruMapSection_section_xml($section, \$order_num);
-    print $handle "</mets:structMap>\n";
-    print $handle $self->buffer_mets_StruMapWhole_section_xml($section);
-    print $handle "</mets:structMap>\n";
+  
+    # print out the StructMapSection by sections
+
+    my $struct_type;
+    if ($version eq "fedora") {
+	$struct_type = "fedora:dsBindingMap";
+    }
+    else {
+	$struct_type = "Section";
+    }
+
+    if ($version ne "fedora") {
+	print $handle "<mets:structMap ID=\"Section\" TYPE=\"$struct_type\" LABEL=\"Section\">\n";
+	my $order_num=0;
+	print $handle $self->buffer_mets_StructMapSection_section_xml($section, \$order_num);
+	print $handle "</mets:structMap>\n";
+
+	print $handle '<mets:structMap ID="All" TYPE="Whole Document" LABEL="All">'."\n";
+	print $handle $self->buffer_mets_StructMapWhole_section_xml($section);
+	print $handle "</mets:structMap>\n";
+    }
+  
 }
 
@@ -585,10 +709,12 @@
 
 
-#*** print out dublin_core.xml file
-sub output_dc_section {
+
+# Build up dublin_core metadata.  Priority given to dc.* over ex.*
+
+sub buffer_dc_section {
     my $self = shift(@_);
-    my ($handle, $section, $doc_Dir) = @_;
-    
-    #***print out the dublin_core 
+    my ($section, $version) = @_;
+    
+    # build up string of dublin core metadata
     $section="" unless defined $section;
     
@@ -614,5 +740,11 @@
 
 	    #$all_text .= '   <dcvalue element="'. $data->[0].'" qualifier="#####">'. $escaped_value. "</dcvalue>\n";
-	    $all_text .= '   <dcvalue element="'. $dc_element.'">'. $escaped_value. "</dcvalue>\n";
+	    if (defined $version && ($version eq "oai_dc")) {
+		$all_text .= "   <dc:$dc_element>$escaped_value</dc:$dc_element>\n";
+	    }
+	    else {
+		$all_text .= '   <dcvalue element="'. $dc_element.'">'. $escaped_value. "</dcvalue>\n";
+	    }
+
 	} 
 	elsif (($data->[0] =~ m/^ex\./) || ($data->[0] !~ m/\./)) {
@@ -642,5 +774,10 @@
 		    my $escaped_value = $v;
 
-		    $all_text .= '   <dcvalue element="'. $dc_element.'">'. $escaped_value. "</dcvalue>\n";
+		    if (defined $version && ($version eq "oai_dc")) {
+			$all_text .= "   <dc:$dc_element>$escaped_value</dc:$dc_element>\n";
+		    }
+		    else {
+			$all_text .= '   <dcvalue element="'. $dc_element.'">'. $escaped_value. "</dcvalue>\n";
+		    }
 		    
 		}
@@ -654,6 +791,18 @@
     $all_text =~ s/[\x00-\x09\x0B\x0C\x0E-\x1F]//g;
 
+    return $all_text;
+}
+
+
+# Print out dublin_core metadata
+sub output_dc_section {
+    my $self = shift(@_);
+    my ($handle, $section, $version) = @_;
+    
+    my $all_text = $self->buffer_dc_section($section,$version);
+
     print $handle $all_text;
 }
+
 
 # look up the reference to the a particular section
Index: /trunk/gsdl/perllib/docproc.pm
===================================================================
--- /trunk/gsdl/perllib/docproc.pm	(revision 9952)
+++ /trunk/gsdl/perllib/docproc.pm	(revision 9953)
@@ -34,4 +34,5 @@
 
     $self->{'OIDtype'} = "hash";
+    $self->{'saveas'} = "GA";  # default
 
     return bless $self, $class;
@@ -65,4 +66,12 @@
 }
 
+sub set_saveas_version {
+    my $self = shift (@_);
+    my ($saveas_version) = @_;
+
+    $self->{'saveas_version'} = $saveas_version;
+
+}
+
 
 1;
