/// <summary> Gets the OAI-PMH m,etadata for a single digital resource, by identifier </summary> /// <param name="Output"> Stream to which to write the text for this main writer </param> /// <param name="Identifier"> Identifier for the record to retrieve the metadata for </param> /// <param name="MetadataPrefix"> Prefix for the metadata format to return the record </param> protected internal void GetRecord(TextWriter Output, string Identifier, string MetadataPrefix) { // Perform check that the identifier is valid bool valid = true; // Metadata prefix must be in the list of acceptable metadata prefixes if (!metadataPrefixes.Contains(MetadataPrefix)) { Write_Error(Output, "identifier=\"" + Identifier + "\" metadataPrefix=\"" + MetadataPrefix + "\" verb=\"GetRecord\"", "cannotDisseminateFormat", "Item " + Identifier + " does not have metadata for " + MetadataPrefix); return; } // Ensure the identifier is in basic correct form OAI_Record thisTitle = null; if (Identifier.IndexOf(oai_resource_identifier_base) != 0) { valid = false; } else { // Get the bib id and vid string bibid_vid = Identifier.Substring(oai_resource_identifier_base.Length); if (bibid_vid.Length != 16) { valid = false; } else { // Pull the information for this item string bibid = bibid_vid.Substring(0, 10); string vid = bibid_vid.Substring(11); thisTitle = SobekCM_Database.Get_OAI_Record(bibid, vid, MetadataPrefix); } } // Throw error if invalid if ((!valid) || (thisTitle == null)) { Write_Error(Output, "identifier=\"" + Identifier + "\" metadataPrefix=\"" + MetadataPrefix + "\" verb=\"GetRecord\"", "idDoesNotExist", "identifier is not valid URI: " + Identifier); return; } // Display the information Output.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "); Output.WriteLine("<?xml-stylesheet type=\"text/xsl\" href=\"oai2.xsl\" ?>"); Output.WriteLine("<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">"); Output.WriteLine("<responseDate>" + date_in_utc(DateTime.Now) + "</responseDate>"); Output.WriteLine("<request identifier=\"" + Identifier + "\" metadataPrefix=\"" + MetadataPrefix + "\" verb=\"GetRecord\">" + url + "</request>"); Output.WriteLine("<GetRecord>"); Output.Write("<record><header><identifier>" + oai_resource_identifier_base + thisTitle.BibID + "_" + thisTitle.VID + "</identifier><datestamp>" + thisTitle.Last_Modified_Date.Year + "-" + thisTitle.Last_Modified_Date.Month.ToString().PadLeft(2, '0') + "-" + thisTitle.Last_Modified_Date.Day.ToString().PadLeft(2, '0') + "</datestamp></header>"); Output.WriteLine("<metadata>" + thisTitle.Record + "</metadata></record>"); Output.WriteLine("</GetRecord>"); Output.WriteLine("</OAI-PMH>"); }
/// <summary> Gets the OAI-PMH m,etadata for a single digital resource, by identifier </summary> /// <param name="Output"> Stream to which to write the text for this main writer </param> /// <param name="identifier"> Identifier for the record to retrieve the metadata for </param> /// <param name="metadata_prefix"> Prefix for the metadata format to return the record </param> protected internal void GetRecord(TextWriter Output, string identifier, string metadata_prefix) { // Perform check that the identifier is valid bool valid = true; string record = String.Empty; // Metadata prefix must currently be oai_dc currently if (metadata_prefix != "oai_dc") { Write_Error(Output, "identifier=\"" + identifier + "\" metadataPrefix=\"" + metadata_prefix + "\" verb=\"GetRecord\"", "cannotDisseminateFormat", "Item " + identifier + " does not have metadata for " + metadata_prefix); return; } // Ensure the identifier is in basic correct form OAI_Record thisTitle = null; if (identifier.IndexOf(SobekCM_Library_Settings.OAI_Resource_Identifier_Base) != 0) { valid = false; } else { // Get the bib id and vid string bibid = identifier.Substring(SobekCM_Library_Settings.OAI_Resource_Identifier_Base.Length); if (bibid.Length != 10) { valid = false; } else { // Pull the information for this item thisTitle = SobekCM_Database.Get_OAI_Record(bibid, metadata_prefix); } } // Throw error if invalid if ((!valid) || (thisTitle == null)) { Write_Error(Output, "identifier=\"" + identifier + "\" metadataPrefix=\"" + metadata_prefix + "\" verb=\"GetRecord\"", "idDoesNotExist", "identifier is not valid URI: " + identifier); return; } // Display the information Output.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "); Output.WriteLine("<?xml-stylesheet type=\"text/xsl\" href=\"oai2.xsl\" ?>"); Output.WriteLine("<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">"); Output.WriteLine("<responseDate>" + date_in_utc(DateTime.Now) + "</responseDate>"); Output.WriteLine("<request identifier=\"" + identifier + "\" metadataPrefix=\"" + metadata_prefix + "\" verb=\"GetRecord\">" + url + "</request>"); Output.WriteLine("<GetRecord>"); Output.Write("<record><header><identifier>" + SobekCM_Library_Settings.OAI_Resource_Identifier_Base + thisTitle.BibID + "</identifier><datestamp>" + thisTitle.Last_Modified_Date.Year + "-" + thisTitle.Last_Modified_Date.Month.ToString().PadLeft(2, '0') + "-" + thisTitle.Last_Modified_Date.Day.ToString().PadLeft(2, '0') + "</datestamp></header>"); Output.WriteLine("<metadata><oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">" + thisTitle.Record + "</oai_dc:dc></metadata></record>"); Output.WriteLine("</GetRecord>"); Output.WriteLine("</OAI-PMH>"); }