private void read_behavior_sec(XmlReader R, SobekCM_Item Package)
{
// Create the flags
bool views_flag = false;
bool interfaces_flag = false;
// Loop through reading each XML node
do
{
// If this is the end of this section, return
if ((R.NodeType == XmlNodeType.EndElement) && (R.Name == "METS:behaviorSec"))
return;
// Make sure this is the behaviorSec node and it has attributes?
if ((R.Name == "METS:behaviorSec") && (R.HasAttributes))
{
// Move to the ID node, if it exists.
if (R.MoveToAttribute("ID"))
{
// Is this the VIEWS behavior sec?
if (R.Value == "VIEWS")
{
views_flag = true;
interfaces_flag = false;
}
// Is this the INTERFACES behavior sec?
if (R.Value == "INTERFACES")
{
interfaces_flag = true;
views_flag = false;
}
}
}
// Process the views
if (views_flag)
{
// Create the sorted list
SortedList views_sorted = new SortedList();
string view_id = String.Empty;
string view_procedure = String.Empty;
string view_procedure_upper = String.Empty;
string view_label = String.Empty;
string view_attributes = String.Empty;
// begin to loop through the XML DOM tree
while (R.Read())
{
// Is this the end of this behavior sec?
if ((R.NodeType == XmlNodeType.EndElement) && (R.Name == "METS:behaviorSec"))
{
views_flag = false;
break;
}
// Is this an element node? If so collect either the behavior id or the title
if (R.NodeType == XmlNodeType.Element)
{
// Is this a new behavior?
if ((R.Name == "METS:behavior") && (R.HasAttributes) && (R.MoveToAttribute("ID")))
{
// Get the view id
view_id = R.Value.ToUpper();
}
// Is this the new mechanism?
if ((R.Name == "METS:mechanism") && (R.HasAttributes))
{
if (R.MoveToAttribute("xlink:title"))
{
// Get the title of this behavior mechanism?
view_procedure = R.Value;
view_procedure_upper = view_procedure.ToUpper();
}
if (R.MoveToAttribute("LABEL"))
{
view_label = R.Value;
}
}
}
// If we have both an id and title, then add this view
if ((view_id.Length > 0) && (view_procedure.Length > 0))
{
// Get any attribute
int first_parenthesis = view_procedure.IndexOf("(");
int second_parenthesis = view_procedure.IndexOf(")");
if ((first_parenthesis > 0) && (second_parenthesis > (first_parenthesis + 1)))
{
view_attributes = view_procedure.Substring(first_parenthesis + 1, second_parenthesis - first_parenthesis - 1);
view_attributes = view_attributes.Replace("\"", " ").Replace("'", " ").Trim();
}
// Add this to the sorted list
views_sorted.Add(view_id, new View_Object(view_procedure_upper, view_label, view_attributes));
// Clear this data
view_id = String.Empty;
view_procedure = String.Empty;
view_procedure_upper = String.Empty;
view_label = String.Empty;
view_attributes = String.Empty;
}
} // end while
// Add these views to the bib object
Package.Behaviors.Clear_Views();
for (int i = 0; i < views_sorted.Count; i++)
{
View_Object tempViewObject = (View_Object) views_sorted.GetByIndex(i);
Package.Behaviors.Add_View(tempViewObject);
}
}
// Process the interfaces
if (interfaces_flag)
{
// Create the sorted list
SortedList interfaces_sorted = new SortedList();
string interface_id = String.Empty;
string interface_title = String.Empty;
// begin to loop through the XML DOM tree
while (R.Read())
{
// Is this the end of this behavior sec?
if ((R.NodeType == XmlNodeType.EndElement) && (R.Name == "METS:behaviorSec"))
{
interfaces_flag = false;
break;
}
// Is this an element node? If so collect either the behavior id or the title
if (R.NodeType == XmlNodeType.Element)
{
// Is this a new behavior?
if ((R.Name.Trim() == "METS:behavior") && (R.HasAttributes) && (R.MoveToAttribute("ID")))
{
// Get the view id
interface_id = R.Value.ToUpper();
}
// Is this the new mechanism?
if ((R.Name.Trim() == "METS:mechanism") && (R.HasAttributes) && (R.MoveToAttribute("xlink:title")))
{
// Get the title of this behavior mechanism?
interface_title = R.Value.ToUpper();
interface_title = interface_title.Replace("_INTERFACE_LOADER", "");
}
}
// If we have both an id and title, then add this view
if ((interface_id.Length > 0) && (interface_title.Length > 0))
{
// Add this to the sorted list
interfaces_sorted.Add(interface_id, interface_title);
// Clear this data
interface_id = String.Empty;
interface_title = String.Empty;
}
} // end while
// Add these web skin to the bib object
Package.Behaviors.Clear_Web_Skins();
for (int i = 0; i < interfaces_sorted.Count; i++)
{
Package.Behaviors.Add_Web_Skin(interfaces_sorted.GetByIndex(i).ToString());
}
}
} while (R.Read());
}