/// <summary> Read the metadata file and enrich the existing bibliographic package </summary> /// <param name="Data_File">Generic (unspecified) metadata file</param> /// <param name="thisPackage">Bibliographic package to enrich</param> public void Read(string Data_File, SobekCM_Item thisPackage) { // Many readers output an error message string errorMessage; // Does this filename have '.info.xml' in it? if (Data_File.ToUpper().IndexOf(".INFO.XML") > 0) { INFO_File_ReaderWriter readInfo = new INFO_File_ReaderWriter(); readInfo.Read_Metadata(Data_File, thisPackage, null, out errorMessage); return; } // Does this file have '.mets' in it? if ((Data_File.ToUpper().IndexOf(".METS") > 0) || (Data_File.ToUpper().IndexOf(".PMETS") > 0)) { METS_File_ReaderWriter readInfo = new METS_File_ReaderWriter(); readInfo.Read_Metadata(Data_File, thisPackage, null, out errorMessage); return; } // If it made it here, it may be METS or MXF if (Data_File.ToUpper().IndexOf(".XML") > 0) { // Read first couple lines StreamReader reader = new StreamReader(Data_File); string thisLine = reader.ReadLine(); while (thisLine != null) { // Is this MXF? if (thisLine.ToUpper().Trim() == "<MXF>") { // Close the current connection reader.Close(); // Read in the MXF file MXF_File_ReaderWriter readInfo = new MXF_File_ReaderWriter(); readInfo.Read_Metadata(Data_File, thisPackage, null, out errorMessage); return; } // Is this a METS declaration? if (thisLine.ToUpper().IndexOf("<METS:") > 0) { // Close the current connection reader.Close(); // Read in the METS file METS_File_ReaderWriter readInfo = new METS_File_ReaderWriter(); readInfo.Read_Metadata(Data_File, thisPackage, null, out errorMessage); return; } // Read the next line thisLine = reader.ReadLine(); } } }
private SobekCM_Item Build_Item_From_METS(string METS_URL, string METS_Name, Custom_Tracer Tracer) { try { if (Tracer != null) { Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Build_Item_From_METS", "Open http web request stream to METS file ( <a href=\"" + METS_URL + "\">" + METS_Name + "</a> )"); } SobekCM_Item thisPackage = new SobekCM_Item(); if (METS_URL.IndexOf("http:") >= 0) { WebRequest objRequest = WebRequest.Create(METS_URL); objRequest.Timeout = 5000; WebResponse objResponse = objRequest.GetResponse(); if (Tracer != null) { Tracer.Add_Trace("SobekCM_METS_Based_ItemBuilder.Build_Item_From_METS", "Read the METS file from the stream"); } // Read the METS file and create the package METS_File_ReaderWriter reader = new METS_File_ReaderWriter(); string errorMessage; reader.Read_Metadata(objResponse.GetResponseStream(), thisPackage, null, out errorMessage); objResponse.Close(); } else { if (File.Exists(METS_URL.Replace("/", "\\"))) { // Read the METS file and create the package METS_File_ReaderWriter reader = new METS_File_ReaderWriter(); string errorMessage; reader.Read_Metadata(METS_URL.Replace("/", "\\"), thisPackage, null, out errorMessage); } else { return(null); } } return(thisPackage); } catch (Exception ee) { if (ee.Message.Length > 0) { return(new SobekCM_Item()); } return(null); } }