protected bool save_to_mets(SobekCM_Item bibPackage, string destination_folder) { bibPackage.METS_Header.RecordStatus_Enum = METS_Record_Status.COMPLETE; // Saves the data members in the SobekCM.Resource_Object to a METS file try { // Set some values bibPackage.METS_Header.Creator_Organization = bibPackage.Bib_Info.Source.Code + "," + bibPackage.Bib_Info.Source.Statement; if (MetaTemplate_UserSettings.AddOns_Enabled.Contains("FCLA")) { PALMM_Info palmmInfo = bibPackage.Get_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY) as PALMM_Info; if (palmmInfo == null) { palmmInfo = new PALMM_Info(); bibPackage.Add_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY, palmmInfo); } if ((palmmInfo.toPALMM) && (palmmInfo.PALMM_Project.Length > 0)) { string creator_org_to_remove = String.Empty; foreach (string thisString in bibPackage.METS_Header.Creator_Org_Notes) { if (thisString.IndexOf("projects=") >= 0) { creator_org_to_remove = thisString; break; } } if (creator_org_to_remove.Length > 0) { bibPackage.METS_Header.Replace_Creator_Org_Notes(creator_org_to_remove, "projects=" + palmmInfo.PALMM_Project); } else { bibPackage.METS_Header.Add_Creator_Org_Notes("projects=" + palmmInfo.PALMM_Project); } } } // Determine the filename string mets_file = destination_folder + "\\" + bibPackage.BibID + "_" + bibPackage.VID + MetaTemplate_UserSettings.METS_File_Extension; // Save the actual file METS_File_ReaderWriter metsWriter = new METS_File_ReaderWriter(); string writing_error = String.Empty; metsWriter.Write_Metadata(mets_file, bibPackage, null, out writing_error); return(true); } catch (Exception e) { ErrorMessageBox.Show("Error encountered while creating METS file!\n\n" + e.Message, "METS Editor Batch Import Error", e); return(false); } }
private void show_preview(TextWriter Output, string Preview_Mode, Custom_Tracer Tracer) { Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.show_preview", String.Empty); Output.WriteLine("<script language=\"JavaScript\">"); // Get the URL to use for forwarding string current_submode = RequestSpecificValues.Current_Mode.My_Sobek_SubMode; RequestSpecificValues.Current_Mode.My_Sobek_SubMode = "ZZZZZ"; string redirect_url = UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode); RequestSpecificValues.Current_Mode.My_Sobek_SubMode = current_submode; Output.WriteLine(" function preview1() {if (document.itemNavForm.pickme) location='" + redirect_url.Replace("ZZZZZ", "preview") + "#CompleteTemplate'}"); Output.WriteLine(" function preview2() {if (document.itemNavForm.pickme) location='" + redirect_url.Replace("ZZZZZ", "marc") + "#CompleteTemplate'}"); Output.WriteLine(" function preview3() {if (document.itemNavForm.pickme) location='" + redirect_url.Replace("ZZZZZ", "mets") + "#CompleteTemplate'}"); Output.WriteLine("</script>"); Output.WriteLine("<center>"); Output.WriteLine(Preview_Mode == "preview" ? "<input type=\"radio\" name=\"sbkPreviewType\" id=\"sbkTypeOfPreview\" checked=\"checked\" /><label for=\"sbkTypeOfPreview\">Standard View</label> " : "<input type=\"radio\" name=\"sbkPreviewType\" id=\"sbkTypeOfPreview\" onchange=\"location='" + redirect_url.Replace("ZZZZZ", "preview") + "#CompleteTemplate';\" /><label for=\"sbkTypeOfPreview\">Standard View</label> "); Output.WriteLine(Preview_Mode == "marc" ? "<input type=\"radio\" name=\"sbkPreviewType\" id=\"sbkTypeOfMarc\" checked=\"checked\" /><label for=\"sbkTypeOfMarc\">MARC View</label> " : "<input TYPE=\"radio\" name=\"sbkPreviewType\" id=\"sbkTypeOfMarc\" onchange=\"location='" + redirect_url.Replace("ZZZZZ", "marc") + "#CompleteTemplate';\" /><label for=\"sbkTypeOfMarc\">MARC View</label> "); Output.WriteLine(Preview_Mode == "mets" ? "<input type=\"radio\" name=\"sbkPreviewType\" id=\"sbkTypeOfMets\" checked=\"checked\" /><label for=\"sbkTypeOfMets\">METS View</label>" : "<input type=\"radio\" name=\"sbkPreviewType\" id=\"sbkTypeOfMets\" onchange=\"location='" + redirect_url.Replace("ZZZZZ", "mets") + "#CompleteTemplate';\" /><label for=\"sbkTypeOfMets\">METS View</label>"); Output.WriteLine("</center>"); Output.WriteLine("<br />"); switch (Preview_Mode) { case "marc": Output.WriteLine("<div class=\"sbkEimv_Citation\">"); //Citation_ItemViewer marcViewer = new Citation_ItemViewer(UI_ApplicationCache_Gateway.Translation, UI_ApplicationCache_Gateway.Aggregations, false) // {CurrentItem = currentItem, CurrentMode = RequestSpecificValues.Current_Mode}; //Output.WriteLine(marcViewer.MARC_String("735px", Tracer)); break; case "mets": Output.WriteLine("<div class=\"sbkEimv_Citation\" >"); // Output.WriteLine("<table width=\"950px\"><tr><td width=\"950px\">"); StringBuilder mets_builder = new StringBuilder(2000); StringWriter mets_output = new StringWriter(mets_builder); METS_File_ReaderWriter metsWriter = new METS_File_ReaderWriter(); string errorMessage; metsWriter.Write_Metadata(mets_output, currentItem, null, out errorMessage); string mets_string = mets_builder.ToString(); string header = mets_string.Substring(0, mets_string.IndexOf("<METS:mets")); string remainder = mets_string.Substring(header.Length); Output.WriteLine(header.Replace("<?", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<?").Replace("?>", "?>&AAA;/span&ZZZ;").Replace("<!--", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<!--&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Gray;&QQQ;&ZZZ;").Replace("-->", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;-->&AAA;/span&ZZZ;").Replace("\r", "<br />").Replace("&AAA;", "<").Replace("&ZZZ;", ">").Replace("&QQQ;", "\"")); Output.WriteLine(remainder.Replace("<?", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<?").Replace("?>", "?>&AAA;/span&ZZZ;").Replace("<!--", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<!--&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Gray;&QQQ;&ZZZ;").Replace("-->", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;-->&AAA;/span&ZZZ;").Replace("</", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;</&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Maroon;&QQQ;&ZZZ;").Replace("<", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Maroon;&QQQ;&ZZZ;").Replace("=\"", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;="&AAA;/span&ZZZ;").Replace("\">", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;">&AAA;/span&ZZZ;").Replace("\"", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;"&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Maroon;&QQQ;&ZZZ;").Replace("/>", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;/>&AAA;/span&ZZZ;").Replace(">", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;>&AAA;/span&ZZZ;").Replace("\r", "<br />").Replace("&AAA;", "<").Replace("&ZZZ;", ">").Replace("&QQQ;", "\"")); // Output.WriteLine("</td></tr></table>"); break; default: Output.WriteLine("<div class=\"sbkEimv_Citation\">"); //Citation_ItemViewer citationViewer = new Citation_ItemViewer(UI_ApplicationCache_Gateway.Translation, UI_ApplicationCache_Gateway.Aggregations, false) // {CurrentItem = currentItem, CurrentMode = RequestSpecificValues.Current_Mode}; //Output.WriteLine(citationViewer.Standard_Citation_String(false, Tracer)); break; } Output.WriteLine("</div><br />"); }
private void show_preview(TextWriter Output, string Preview_Mode, Custom_Tracer Tracer) { Tracer.Add_Trace("Edit_Item_Metadata_MySobekViewer.show_preview", String.Empty); Output.WriteLine("<script language=\"JavaScript\">"); // Get the URL to use for forwarding string current_submode = currentMode.My_Sobek_SubMode; currentMode.My_Sobek_SubMode = "ZZZZZ"; string redirect_url = currentMode.Redirect_URL(); currentMode.My_Sobek_SubMode = current_submode; Output.WriteLine(" function preview1() {if (document.itemNavForm.pickme) location='" + redirect_url.Replace("ZZZZZ", "preview") + "#template'}"); Output.WriteLine(" function preview2() {if (document.itemNavForm.pickme) location='" + redirect_url.Replace("ZZZZZ", "marc") + "#template'}"); Output.WriteLine(" function preview3() {if (document.itemNavForm.pickme) location='" + redirect_url.Replace("ZZZZZ", "mets") + "#template'}"); Output.WriteLine("</script>"); Output.WriteLine("<center>"); Output.WriteLine(Preview_Mode == "preview" ? "<input TYPE=\"radio\" NAME=\"pickme\" onclick=\"preview1()\" checked=\"checked\" />Standard View " : "<input TYPE=\"radio\" NAME=\"pickme\" onclick=\"preview1()\" />Standard View "); Output.WriteLine(Preview_Mode == "marc" ? "<input TYPE=\"radio\" NAME=\"pickme\" onclick=\"preview2()\" checked=\"checked\" />MARC View " : "<input TYPE=\"radio\" NAME=\"pickme\" onclick=\"preview2()\" />MARC View "); Output.WriteLine(Preview_Mode == "mets" ? "<input TYPE=\"radio\" NAME=\"pickme\" onclick=\"preview3()\" checked=\"checked\" />METS View" : "<input TYPE=\"radio\" NAME=\"pickme\" onclick=\"preview3()\" />METS View"); Output.WriteLine("</center>"); Output.WriteLine("<br />"); switch (Preview_Mode) { case "marc": Output.WriteLine("<div class=\"SobekCitation\">"); Citation_ItemViewer marcViewer = new Citation_ItemViewer(Translator, codeManager, false) { CurrentItem = item, CurrentMode = currentMode }; Output.WriteLine(marcViewer.MARC_String("735px", Tracer)); break; case "mets": Output.WriteLine("<div class=\"SobekCitation_METS\" width=\"950px\" >"); Output.WriteLine("<table width=\"950px\"><tr><td width=\"950px\">"); StringBuilder mets_builder = new StringBuilder(2000); StringWriter mets_output = new StringWriter(mets_builder); SobekCM_Item testItem = Test_Bib_Package.Create(String.Empty); METS_File_ReaderWriter metsWriter = new METS_File_ReaderWriter(); string Error_Message; metsWriter.Write_Metadata(mets_output, testItem, null, out Error_Message); string mets_string = mets_builder.ToString(); string header = mets_string.Substring(0, mets_string.IndexOf("<METS:mets")); string remainder = mets_string.Substring(header.Length); Output.WriteLine(header.Replace("<?", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<?").Replace("?>", "?>&AAA;/span&ZZZ;").Replace("<!--", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<!--&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Gray;&QQQ;&ZZZ;").Replace("-->", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;-->&AAA;/span&ZZZ;").Replace("\r", "<br />").Replace("&AAA;", "<").Replace("&ZZZ;", ">").Replace("&QQQ;", "\"")); Output.WriteLine(remainder.Replace("<?", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<?").Replace("?>", "?>&AAA;/span&ZZZ;").Replace("<!--", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<!--&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Gray;&QQQ;&ZZZ;").Replace("-->", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;-->&AAA;/span&ZZZ;").Replace("</", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;</&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Maroon;&QQQ;&ZZZ;").Replace("<", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;<&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Maroon;&QQQ;&ZZZ;").Replace("=\"", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;="&AAA;/span&ZZZ;").Replace("\">", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;">&AAA;/span&ZZZ;").Replace("\"", "&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;"&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Maroon;&QQQ;&ZZZ;").Replace("/>", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;/>&AAA;/span&ZZZ;").Replace(">", "&AAA;/span&ZZZ;&AAA;span style=&QQQ;color:Blue;&QQQ;&ZZZ;>&AAA;/span&ZZZ;").Replace("\r", "<br />").Replace("&AAA;", "<").Replace("&ZZZ;", ">").Replace("&QQQ;", "\"")); Output.WriteLine("</td></tr></table>"); break; default: Output.WriteLine("<div class=\"SobekCitation\">"); Citation_ItemViewer citationViewer = new Citation_ItemViewer(Translator, codeManager, false) { CurrentItem = item, CurrentMode = currentMode }; Output.WriteLine(citationViewer.Standard_Citation_String(false, Tracer)); break; } Output.WriteLine("</div><br />"); }
/// <summary> Perform the requested work </summary> public void Do_Work() { // Get the current user name string username = WindowsIdentity.GetCurrent().Name; int recordsProcessed = 0; // Look for a mappings file for this repository Dictionary <string, string> oai_objectid_mapping = new Dictionary <string, string>(); string mappings_file = mapping_directory + "\\" + repository.Repository_Identifier + ".xml"; try { if (String.IsNullOrEmpty(repository.Repository_Identifier)) { mappings_file = mapping_directory + "\\" + repository.Name + ".xml"; } if ((mapping_directory.Length > 0) && (Directory.Exists(mapping_directory)) && (File.Exists(mappings_file))) { DataSet mappingSet = new DataSet(); mappingSet.ReadXml(mappings_file); foreach (DataRow thisRow in mappingSet.Tables[0].Rows) { oai_objectid_mapping[thisRow[0].ToString()] = thisRow[1].ToString(); } } } catch (Exception ee) { Debug.WriteLine(ee.Message); OnComplete(0, OAI_PMH_Importer_Error_Enum.Unable_to_read_existing_mappings_file); } // Get the first set of records OAI_Repository_Records_List records = OAI_Repository_Stream_Reader.List_Records(repository.Harvested_URL, set_to_import, "oai_dc"); if ((records == null) || (records.Count == 0)) { OnComplete(0, OAI_PMH_Importer_Error_Enum.Unable_to_pull_feed_data); return; } // Flag used to keep the user request if a previous mapping is found that matches a record Nullable <bool> use_previous_mappings = null; try { // Continue through each pull using the resumption token while ((records != null) && (records.Count > 0)) { // Step through these records int total_count = records.Count; for (int i = 0; i < total_count; i++) { // Get this record out OAI_Repository_DublinCore_Record record = records[i]; // Create the bib package SobekCM_Item bibPackage = new SobekCM_Item(record); // Add some more information about the repository here bibPackage.Bib_Info.Add_Identifier(record.OAI_Identifier, "oai"); bibPackage.Bib_Info.Record.Main_Record_Identifier.Type = "oai"; bibPackage.Bib_Info.Record.Main_Record_Identifier.Identifier = record.OAI_Identifier; bibPackage.Bib_Info.Location.Other_URL_Note = repository.Name; bibPackage.Bib_Info.Location.Other_URL_Display_Label = "External Link"; bibPackage.Bib_Info.Source.Statement = repository.Name; // Add constant data from each mapped column into the bib package constantCollection.Add_To_Package(bibPackage); // Make sure there is a title if (bibPackage.Bib_Info.Main_Title.ToString().Trim().Length == 0) { bibPackage.Bib_Info.Main_Title.Title = "Missing Title"; } // Set some defaults bibPackage.Source_Directory = destination_folder; if (MetaTemplate_UserSettings.Individual_Creator.Length > 0) { bibPackage.METS_Header.Creator_Individual = MetaTemplate_UserSettings.Individual_Creator; } else { bibPackage.METS_Header.Creator_Individual = username; } bibPackage.METS_Header.Add_Creator_Individual_Notes("Imported via OAI from " + repository.Name); bibPackage.VID = "00001"; bibPackage.METS_Header.Creator_Software = "SobekCM METS Editor"; // See if this already exists in the mapping if ((!use_previous_mappings.HasValue) && (oai_objectid_mapping.ContainsKey(record.OAI_Identifier))) { DialogResult result = MessageBox.Show("Record from OAI set appears in previous mapping file. \n\nShould the previous mappings be used? \n\nIf you select 'YES' the ObjectID will be the same as the previous harvest.\n\nIf you select 'NO' a new ObjectID will be assigned from your range. ", "Previous Mapping Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { use_previous_mappings = true; } if (result == DialogResult.No) { use_previous_mappings = false; } } // Assign a BibId if ((use_previous_mappings.HasValue) && (use_previous_mappings.Value) && (oai_objectid_mapping.ContainsKey(record.OAI_Identifier))) { // Use the existing BibId from the previous mapping bibPackage.BibID = oai_objectid_mapping[record.OAI_Identifier]; } else { // Determine the next BibID to be assigned string next_bibid = next_bibid_counter.ToString(); next_bibid_counter++; bibPackage.BibID = (bibid_start + next_bibid.PadLeft(10 - bibid_start.Length, '0')).ToUpper(); // Save this mapping to the dictionary oai_objectid_mapping[record.OAI_Identifier] = bibPackage.BibID; } // Set some values bibPackage.METS_Header.Creator_Organization = bibPackage.Bib_Info.Source.Code + "," + bibPackage.Bib_Info.Source.Statement; if (MetaTemplate_UserSettings.AddOns_Enabled.Contains("FCLA")) { PALMM_Info palmmInfo = bibPackage.Get_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY) as PALMM_Info; if (palmmInfo == null) { palmmInfo = new PALMM_Info(); bibPackage.Add_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY, palmmInfo); } if ((palmmInfo.toPALMM) && (palmmInfo.PALMM_Project.Length > 0)) { string creator_org_to_remove = String.Empty; foreach (string thisString in bibPackage.METS_Header.Creator_Org_Notes) { if (thisString.IndexOf("projects=") >= 0) { creator_org_to_remove = thisString; break; } } if (creator_org_to_remove.Length > 0) { bibPackage.METS_Header.Replace_Creator_Org_Notes(creator_org_to_remove, "projects=" + palmmInfo.PALMM_Project); } else { bibPackage.METS_Header.Add_Creator_Org_Notes("projects=" + palmmInfo.PALMM_Project); } } } // Determine the filename string mets_file = destination_folder + "\\" + bibPackage.BibID + "_" + bibPackage.VID + MetaTemplate_UserSettings.METS_File_Extension; // Save the actual file METS_File_ReaderWriter metsWriter = new METS_File_ReaderWriter(); string writing_error = String.Empty; metsWriter.Write_Metadata(mets_file, bibPackage, null, out writing_error); // Increment progress recordsProcessed++; OnNewProgress(recordsProcessed, total_count); } // If there was a resumption token, pull the next set of records from the repository if (String.IsNullOrEmpty(records.Resumption_Token)) { records = null; } else { records = OAI_Repository_Stream_Reader.List_Records(repository.Harvested_URL, records.Resumption_Token); } } } catch (Exception ee) { Debug.WriteLine(ee.Message); OnComplete(recordsProcessed, OAI_PMH_Importer_Error_Enum.Unknown_error_while_processing_feed); } // Now, save this mapping if (mapping_directory.Length > 0) { try { // Ensure the directory exists if (!Directory.Exists(mapping_directory)) { Directory.CreateDirectory(mapping_directory); } // Create the dataset/table with the new mappings (includes old if one was found) DataSet mappingSet2 = new DataSet("SobekCM_METS_Editor_OAI_Mapping"); DataTable mappingTable = new DataTable("OAI_ObjectID_Map"); mappingSet2.Tables.Add(mappingTable); mappingTable.Columns.Add("OAI_Identifier"); mappingTable.Columns.Add("SobekCM_ObjectID"); // Copy over the data into the new datatable foreach (string thisKey in oai_objectid_mapping.Keys) { DataRow newRow = mappingTable.NewRow(); newRow[0] = thisKey; newRow[1] = oai_objectid_mapping[thisKey]; mappingTable.Rows.Add(newRow); } // Write the mappings as the dataset in XML format mappingSet2.WriteXml(mappings_file, XmlWriteMode.WriteSchema); } catch (Exception ee) { Debug.WriteLine(ee.Message); OnComplete(recordsProcessed, OAI_PMH_Importer_Error_Enum.Unable_to_save_mappings_file); } } // Process complete! OnComplete(recordsProcessed, OAI_PMH_Importer_Error_Enum.NO_ERROR); }
public void Do_Work() { string username = WindowsIdentity.GetCurrent().Name; List <string> directories_to_process = new List <string>(); try { recurse_through_directories(directory, directories_to_process); } catch { } // Now, iterate through all the directories int current_directory = 1; int errors_encountered = 0; foreach (string thisDirectory in directories_to_process) { try { DirectoryInfo thisDirectoryInfo = new DirectoryInfo(thisDirectory); string folder_name_for_progress = thisDirectoryInfo.Name; if (folder_name_for_progress.Length <= 5) { folder_name_for_progress = (thisDirectoryInfo.Parent.Name) + "\\" + folder_name_for_progress; } OnNewFolder(folder_name_for_progress + " ( " + current_directory + " of " + directories_to_process.Count + " )"); // Get the metadata file string[] metadata = Directory.GetFiles(thisDirectory, filter); if (metadata.Length > 0) { SobekCM_Item newItem = null; if (metadata_type.IndexOf("METS") >= 0) { newItem = SobekCM_Item.Read_METS(metadata[0]); } else { newItem = new SobekCM_Item(); newItem.Source_Directory = thisDirectory; newItem = new SobekCM_Item(); List <string> addOns = MetaTemplate_UserSettings.AddOns_Enabled; // Set the initial agents if (MetaTemplate_UserSettings.Individual_Creator.Length > 0) { newItem.METS_Header.Creator_Individual = MetaTemplate_UserSettings.Individual_Creator; } else { newItem.METS_Header.Creator_Individual = username; } newItem.METS_Header.Creator_Software = "SobekCM METS Editor"; // Add FCLA add-on defaults if (addOns.Contains("FCLA")) { PALMM_Info palmmInfo = newItem.Get_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY) as PALMM_Info; if (palmmInfo == null) { palmmInfo = new PALMM_Info(); newItem.Add_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY, palmmInfo); } palmmInfo.PALMM_Project = MetaTemplate_UserSettings.PALMM_Code; palmmInfo.toPALMM = MetaTemplate_UserSettings.FCLA_Flag_PALMM; DAITSS_Info daitssInfo = newItem.Get_Metadata_Module(GlobalVar.DAITSS_METADATA_MODULE_KEY) as DAITSS_Info; if (daitssInfo == null) { daitssInfo = new DAITSS_Info(); newItem.Add_Metadata_Module(GlobalVar.DAITSS_METADATA_MODULE_KEY, daitssInfo); } daitssInfo.toArchive = MetaTemplate_UserSettings.FCLA_Flag_FDA; daitssInfo.Account = MetaTemplate_UserSettings.FDA_Account; daitssInfo.SubAccount = MetaTemplate_UserSettings.FDA_SubAccount; daitssInfo.Project = MetaTemplate_UserSettings.FDA_Project; } // Add SobekCM add-on defaults if (addOns.Contains("SOBEKCM")) { // Add any wordmarks List <string> wordmarks = MetaTemplate_UserSettings.SobekCM_Wordmarks; foreach (string thisWordmark in wordmarks) { newItem.Behaviors.Add_Wordmark(thisWordmark); } // Add any aggregations List <string> aggregations = MetaTemplate_UserSettings.SobekCM_Aggregations; foreach (string thisAggregation in aggregations) { newItem.Behaviors.Add_Aggregation(thisAggregation); } // Add any web skins List <string> webskins = MetaTemplate_UserSettings.SobekCM_Web_Skins; foreach (string thisWebSkin in webskins) { newItem.Behaviors.Add_Web_Skin(thisWebSkin); } // Add any viewers List <string> viewers = MetaTemplate_UserSettings.SobekCM_Viewers; foreach (string thisViewer in viewers) { if (String.Compare(thisViewer, "Page Image (JPEG)") == 0) { newItem.Behaviors.Add_View(View_Enum.JPEG); } if (String.Compare(thisViewer, "Zoomable (JPEG2000)") == 0) { newItem.Behaviors.Add_View(View_Enum.JPEG2000); } if (String.Compare(thisViewer, "Page Turner") == 0) { newItem.Behaviors.Add_View(View_Enum.PAGE_TURNER); } if (String.Compare(thisViewer, "Text") == 0) { newItem.Behaviors.Add_View(View_Enum.TEXT); } if (String.Compare(thisViewer, "Thumbnails") == 0) { newItem.Behaviors.Add_View(View_Enum.RELATED_IMAGES); } } } // Add all other defaults newItem.Bib_Info.Source.Code = MetaTemplate_UserSettings.Default_Source_Code; newItem.Bib_Info.Source.Statement = MetaTemplate_UserSettings.Default_Source_Statement; if (MetaTemplate_UserSettings.Default_Funding_Note.Length > 0) { newItem.Bib_Info.Add_Note(MetaTemplate_UserSettings.Default_Funding_Note, Note_Type_Enum.funding); } if (MetaTemplate_UserSettings.Default_Rights_Statement.Length > 0) { newItem.Bib_Info.Access_Condition.Text = MetaTemplate_UserSettings.Default_Rights_Statement; } // Set some final values newItem.Bib_Info.Type.MODS_Type = TypeOfResource_MODS_Enum.Text; // Assign an ObjectID switch (next_bibid_counter) { case -1: newItem.METS_Header.ObjectID = thisDirectoryInfo.Name; if ((newItem.METS_Header.ObjectID.Length == 16) && (newItem.METS_Header.ObjectID[10] == '_')) { newItem.VID = newItem.BibID.Substring(11); newItem.BibID = newItem.BibID.Substring(0, 10).ToUpper(); } break; case -2: newItem.METS_Header.ObjectID = (new FileInfo(metadata[0])).Name; if ((newItem.METS_Header.ObjectID.Length == 16) && (newItem.METS_Header.ObjectID[10] == '_')) { newItem.VID = newItem.BibID.Substring(11); newItem.BibID = newItem.BibID.Substring(0, 10).ToUpper(); } break; default: string next_bibid = next_bibid_counter.ToString(); next_bibid_counter++; newItem.BibID = (bibid_start + next_bibid.PadLeft(10 - bibid_start.Length, '0')).ToUpper(); newItem.VID = "00001"; break; } string errors = String.Empty; if (metadata_type.IndexOf("DUBLIN CORE") >= 0) { // Open a stream to read the indicated import file Stream reader = new FileStream(metadata[0], FileMode.Open, FileAccess.Read); DC_File_ReaderWriter dcreader = new DC_File_ReaderWriter(); dcreader.Read_Metadata(reader, newItem, null, out errors); } if (metadata_type.IndexOf("MODS") >= 0) { // Open a stream to read the indicated import file Stream reader = new FileStream(metadata[0], FileMode.Open, FileAccess.Read); MODS_File_ReaderWriter dcreader = new MODS_File_ReaderWriter(); dcreader.Read_Metadata(reader, newItem, null, out errors); } if (metadata_type.IndexOf("MARCXML") >= 0) { // Open a stream to read the indicated import file Stream reader = new FileStream(metadata[0], FileMode.Open, FileAccess.Read); MarcXML_File_ReaderWriter dcreader = new MarcXML_File_ReaderWriter(); dcreader.Read_Metadata(reader, newItem, null, out errors); } } // Make sure there is a title if (newItem.Bib_Info.Main_Title.ToString().Trim().Length == 0) { newItem.Bib_Info.Main_Title.Title = "Missing Title"; } // We now have a good METS file, so let's look for files to add string[] existing_files = Directory.GetFiles(thisDirectory); bool image_files_found = false; List <string> otherFiles = new List <string>(); foreach (string thisFile in existing_files) { string upper_case = new FileInfo(thisFile).Name.ToUpper(); if ((upper_case.IndexOf(".TIF") > 0) || (upper_case.IndexOf(".JPG") > 0) || (upper_case.IndexOf(".JP2") > 0)) { image_files_found = true; } else if ((upper_case.IndexOf(".METS") < 0) && (upper_case.IndexOf(".TXT") < 0) && (upper_case.IndexOf(".PRO") < 0) && (upper_case.IndexOf(".XML") < 0) && (upper_case.IndexOf(".MODS") < 0) && (upper_case.IndexOf(".DC") < 0)) { otherFiles.Add((new FileInfo(thisFile)).Name); } } // Add the image files first newItem.Source_Directory = thisDirectory; Bib_Package_Builder.Add_All_Files(newItem, "*.tif|*.jpg|*.jp2|*.txt|*.pro|*.gif", MetaTemplate_UserSettings.Always_Recurse_Through_Subfolders_On_New, MetaTemplate_UserSettings.Page_Images_In_Seperate_Folders_Can_Be_Same_Page); // Add any downloads next foreach (string thisFile in otherFiles) { newItem.Divisions.Download_Tree.Add_File(thisFile); } // Now, save this METS file // Prepare to save the enw METS // Determine the filename string mets_file = thisDirectory + "\\" + newItem.METS_Header.ObjectID + MetaTemplate_UserSettings.METS_File_Extension; // Save the actual file newItem.Divisions.Suppress_Checksum = !MetaTemplate_UserSettings.Include_Checksums; // Save the actual file METS_File_ReaderWriter metsWriter = new METS_File_ReaderWriter(); string writing_error = String.Empty; metsWriter.Write_Metadata(mets_file, newItem, null, out writing_error); } } catch (Exception ee) { errors_encountered++; } OnNewProgress(current_directory, directories_to_process.Count); current_directory++; } OnComplete(current_directory, errors_encountered); }