private void read_mets_header(XmlReader R, SobekCM_Item Package)
{
// Since we are now using child trees, read here to get to the first (top-level) element
R.Read();
// Is this an empty element?
bool isEmptyMetsHeader = R.IsEmptyElement;
// Read the attributes on the METS header first
if (R.MoveToAttribute("CREATEDATE"))
{
DateTime outDate1;
if (DateTime.TryParse(R.Value.Replace("T", " ").Replace("Z", ""), out outDate1))
Package.METS_Header.Create_Date = outDate1;
}
if (R.MoveToAttribute("LASTMODDATE"))
{
DateTime outDate2;
if (DateTime.TryParse(R.Value.Replace("T", " ").Replace("Z", ""), out outDate2))
Package.METS_Header.Modify_Date = outDate2;
}
if (R.MoveToAttribute("RECORDSTATUS"))
Package.METS_Header.RecordStatus = R.Value;
if (R.MoveToAttribute("ID"))
Package.METS_Header.ObjectID = R.Value;
// If this appears to be BibID_VID format, then assign those as well
Package.BibID = Package.METS_Header.ObjectID;
if ((Package.METS_Header.ObjectID.Length == 16) && (Package.METS_Header.ObjectID[10] == '_'))
{
bool char_found = false;
foreach (char thisChar in Package.METS_Header.ObjectID.Substring(11))
{
if (!char.IsNumber(thisChar))
{
char_found = true;
}
}
if (!char_found)
{
string objectid = Package.METS_Header.ObjectID;
Package.BibID = objectid.Substring(0, 10);
Package.VID = objectid.Substring(11);
}
}
// If this is an empty METS header, skip the rest
if (isEmptyMetsHeader)
return;
// Loop through reading each XML node
int agent_type = -1;
while (R.Read())
{
// If this is the end of this section, return
if (R.NodeType == XmlNodeType.EndElement)
{
if ((R.Name == "METS:metsHdr") || (R.Name == "metsHdr"))
return;
if ((R.Name == "METS:agent") || (R.Name == "agent"))
agent_type = -1;
}
// Essentially a small enumeration here
const int UNKNOWN_TYPE = -1;
const int ORGANIZATION = 1;
const int OTHER = 2;
const int INDIVIDUAL = 3;
if (R.NodeType == XmlNodeType.Element)
{
switch (R.Name.Replace("METS:", ""))
{
case "agent":
if ((R.MoveToAttribute("ROLE")) && (R.GetAttribute("ROLE") == "CREATOR") && (R.MoveToAttribute("TYPE")))
{
switch (R.Value)
{
case "ORGANIZATION":
agent_type = ORGANIZATION;
break;
case "OTHER":
agent_type = OTHER;
break;
case "INDIVIDUAL":
agent_type = INDIVIDUAL;
break;
default:
agent_type = UNKNOWN_TYPE;
break;
}
}
break;
case "name":
switch (agent_type)
{
case ORGANIZATION:
R.Read();
Package.METS_Header.Creator_Organization = R.Value;
Package.Bib_Info.Source.Code = R.Value;
Package.Bib_Info.Source.Statement = R.Value;
if (R.Value.IndexOf(",") < 0)
{
// Some presets for source codes in Florida
switch (R.Value.ToUpper())
{
case "UF":
Package.Bib_Info.Source.Statement = "University of Florida";
break;
case "FS":
case "FSU":
Package.Bib_Info.Source.Statement = "Florida State University";
break;
case "UCF":
case "CF":
Package.Bib_Info.Source.Statement = "University of Central Florida";
break;
case "USF":
case "SF":
Package.Bib_Info.Source.Statement = "University of South Florida";
break;
case "UNF":
case "NF":
Package.Bib_Info.Source.Statement = "University of North Florida";
break;
case "UWF":
case "WF":
Package.Bib_Info.Source.Statement = "University of West Florida";
break;
case "FIU":
case "FI":
Package.Bib_Info.Source.Statement = "Florida International University";
break;
case "FGCU":
case "FG":
case "GC":
Package.Bib_Info.Source.Statement = "Florida Gulf Coast University";
break;
case "FAMU":
case "AM":
Package.Bib_Info.Source.Statement = "Florida Agricultural and Mechanical University";
break;
case "FAU":
Package.Bib_Info.Source.Statement = "Florida Atlantic University";
break;
case "FCLA":
Package.Bib_Info.Source.Statement = "Florida Center for Library Automation";
break;
}
}
else
{
string code = R.Value.Substring(0, R.Value.IndexOf(","));
string name = R.Value.Substring(R.Value.IndexOf(",") + 1);
Package.Bib_Info.Source.Statement = name;
Package.Bib_Info.Source.Code = code;
}
break;
case OTHER:
R.Read();
Package.METS_Header.Creator_Software = R.Value;
break;
case INDIVIDUAL:
R.Read();
Package.METS_Header.Creator_Individual = R.Value;
break;
}
break;
case "note":
switch (agent_type)
{
case ORGANIZATION:
R.Read();
Package.METS_Header.Add_Creator_Org_Notes(R.Value);
break;
case INDIVIDUAL:
R.Read();
Package.METS_Header.Add_Creator_Individual_Notes(R.Value);
break;
}
break;
}
}
}
}