Example #1
0
        private void preorder_build(List <abstract_TreeNode> collection, abstract_TreeNode thisNode, bool only_add_pages)
        {
            // Since this is pre-order, first 'visit' this
            if (!only_add_pages)
            {
                collection.Add(thisNode);
            }
            else
            {
                // If we are just getting pages, only add if it is not already added
                if ((thisNode.Page) && (!collection.Contains(thisNode)))
                {
                    collection.Add(thisNode);
                }
            }

            // is this a division node? .. which can have children ..
            if (!thisNode.Page)
            {
                Division_TreeNode thisDivNode = (Division_TreeNode)thisNode;

                // Do the same for all the children
                foreach (abstract_TreeNode childNode in thisDivNode.Nodes)
                {
                    preorder_build(collection, childNode, only_add_pages);
                }
            }
        }
 /// <summary> Flag indicates if this active reader/writer will write a dmdSec for this node </summary>
 /// <param name="MetsDivision"> Division to check if a dmdSec will be written </param>
 /// <param name="Options"> Dictionary of any options which this METS section writer may utilize</param>
 /// <returns> TRUE if the package has data to be written, otherwise fALSE </returns>
 public bool Include_dmdSec(abstract_TreeNode MetsDivision, Dictionary<string, object> Options)
 {
     // GEt the geo-spatial information if it exists
     GeoSpatial_Information geoInfo = MetsDivision.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
     if ((geoInfo == null) || (!geoInfo.hasData))
         return false;
     return true;
 }
        /// <summary> Reads the dmdSec at the current position in the XmlTextReader and associates it with 
        /// one subsection/division from the METS structure map </summary>
        /// <param name="Input_XmlReader"> Open XmlReader from which to read the metadata </param>
        /// <param name="MetsDivision"> Division from the overall package into which to read the metadata</param>
        /// <param name="Options"> Dictionary of any options which this METS section writer may utilize</param>
        /// <returns> TRUE if successful, otherwise FALSE</returns>
        public bool Read_dmdSec(XmlReader Input_XmlReader, abstract_TreeNode MetsDivision, Dictionary<string, object> Options)
        {
            // Get the geo-spatial information if it exists or create a new one
            GeoSpatial_Information geoInfo = MetsDivision.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
            if (geoInfo == null)
            {
                geoInfo = new GeoSpatial_Information();
                MetsDivision.Add_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY, geoInfo);
            }

            return Read_Metadata_Section(Input_XmlReader, geoInfo, Options);
        }
Example #4
0
        private void preorder_build(List <abstract_TreeNode> Collection, abstract_TreeNode ThisNode, bool OnlyAddPages, bool PagesMustHaveFiles)
        {
            // Since this is pre-order, first 'visit' this
            if (!OnlyAddPages)
            {
                Collection.Add(ThisNode);
            }
            else
            {
                // If we are just getting pages, only add if it is not already added
                if ((ThisNode.Page) && (!Collection.Contains(ThisNode)))
                {
                    // If you just add all files, just add it here
                    if (!PagesMustHaveFiles)
                    {
                        Collection.Add(ThisNode);
                    }
                    else
                    {
                        // Must ensure this page has files to add it
                        Page_TreeNode asPage = ThisNode as Page_TreeNode;
                        if (asPage != null)
                        {
                            if ((asPage.Files != null) && (asPage.Files.Count > 0))
                            {
                                Collection.Add(asPage);
                            }
                        }
                    }
                }
            }

            // is this a division node? .. which can have children ..
            if (!ThisNode.Page)
            {
                Division_TreeNode thisDivNode = (Division_TreeNode)ThisNode;

                // Do the same for all the children
                foreach (abstract_TreeNode childNode in thisDivNode.Nodes)
                {
                    preorder_build(Collection, childNode, OnlyAddPages, PagesMustHaveFiles);
                }
            }
        }
Example #5
0
        private bool recursively_add_file(abstract_TreeNode Node, SobekCM_File_Info New_File, string SystemName_Upper)
        {
            // If this is a page, check for a match first
            if (Node.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode)Node;
                if (pageNode.Files.Count >= 1)
                {
                    if (pageNode.Files[0].File_Name_Sans_Extension == SystemName_Upper)
                    {
                        // Belongs to this page.  Now, just make sure it doesn't already exist
                        foreach (SobekCM_File_Info thisFile in pageNode.Files)
                        {
                            if (thisFile.System_Name.ToUpper() == New_File.System_Name.ToUpper())
                            {
                                return(true);
                            }
                        }

                        // Not found, so add it to this page
                        pageNode.Files.Add(New_File);
                        return(true);
                    }
                }
            }

            // If this was a division, check all pages
            if (!Node.Page)
            {
                Division_TreeNode divNode = (Division_TreeNode)Node;
                foreach (abstract_TreeNode childNodes in divNode.Nodes)
                {
                    if (recursively_add_file(childNodes, New_File, SystemName_Upper))
                    {
                        return(true);
                    }
                }
            }

            // If nothing found that matches under this node, return false
            return(false);
        }
Example #6
0
        private bool recursively_check_for_any_files(abstract_TreeNode Node)
        {
            if (Node.Page)
            {
                if (((Page_TreeNode)Node).Files.Count > 0)
                {
                    return(true);
                }
            }

            if (!Node.Page)
            {
                Division_TreeNode divNode = (Division_TreeNode)Node;
                foreach (abstract_TreeNode TreeNode in divNode.Nodes)
                {
                    if (recursively_check_for_any_files(TreeNode))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 private void recurse_through_nodes(abstract_TreeNode Node, List<Page_TreeNode> PagesEncountered)
 {
     if (Node.Page)
     {
         Page_TreeNode pageNode = (Page_TreeNode)Node;
         if (!PagesEncountered.Contains(pageNode))
         {
             pageseq++;
         }
     }
     else
     {
         Division_TreeNode divNode = (Division_TreeNode)Node;
         foreach (abstract_TreeNode childNode in divNode.Nodes)
         {
             recurse_through_nodes(childNode, PagesEncountered);
         }
     }
 }
        private static bool recursively_remove_empty_divisions(abstract_TreeNode ChildNode)
        {
            // This steps through all the children nodes and checks for emptiness
            // If the node is empty and should be removed by the parent, TRUE is returned,
            // otherwise FALSE is returned, in which case the node has some children and
            // should not be removed
            if (!ChildNode.Page)
            {
                Division_TreeNode divNode = (Division_TreeNode) ChildNode;
                if (divNode.Nodes.Count > 0)
                {
                    int nodeCounter = 0;
                    while (nodeCounter < divNode.Nodes.Count)
                    {
                        abstract_TreeNode thisNode = divNode.Nodes[nodeCounter];
                        if (recursively_remove_empty_divisions(thisNode))
                        {
                            divNode.Nodes.Remove(thisNode);
                        }
                        else
                        {
                            nodeCounter++;
                        }
                    }
                    return divNode.Nodes.Count <= 0;
                }

                return true;
            }

            Page_TreeNode pageNode = (Page_TreeNode) ChildNode;
            return pageNode.Files.Count == 0;
        }
        private static void recursively_add_all_METS_files(abstract_TreeNode RootNode,
                                                           List<SobekCM_File_Info> METSFiles, Builder_Page_File_Collection METSFileCollection,
                                                           Dictionary<SobekCM_File_Info, Page_TreeNode> FileToPage, Dictionary<Page_TreeNode, Division_TreeNode> PageToDiv,
                                                           List<string> FileFilters)
        {
            if (RootNode.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode) RootNode;
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    bool add_file = false;
                    if (FileFilters.Count == 0)
                    {
                        add_file = true;
                    }
                    else
                    {
                        foreach (string file_filter in FileFilters)
                        {
                            if (thisFile.System_Name.ToUpper().IndexOf(file_filter) > 0)
                            {
                                add_file = true;
                                break;
                            }
                        }
                    }

                    if (add_file)
                    {
                        METSFiles.Add(thisFile);
                        Builder_Page_File newPageFile = new Builder_Page_File(thisFile.System_Name, true);
                        newPageFile.METS_Page = pageNode;
                        newPageFile.METS_Division = PageToDiv[pageNode];
                        METSFileCollection.Insert(newPageFile);
                        FileToPage.Add(thisFile, pageNode);
                    }
                }
            }
            else
            {
                Division_TreeNode divNode = (Division_TreeNode) RootNode;
                foreach (abstract_TreeNode thisNode in divNode.Nodes)
                {
                    if (thisNode.Page)
                    {
                        try
                        {
                            if (!PageToDiv.ContainsKey((Page_TreeNode) thisNode))
                            {
                                PageToDiv.Add((Page_TreeNode) thisNode, divNode);
                            }
                        }
                        catch
                        {
                        }
                    }

                    recursively_add_all_METS_files(thisNode, METSFiles, METSFileCollection, FileToPage, PageToDiv, FileFilters);
                }
            }
        }
Example #10
0
        private void recursively_build_all_files_list(List <SobekCM_File_Info> returnValue, List <Page_TreeNode> handledPages, abstract_TreeNode thisNode)
        {
            // Since this is pre-order, first 'visit' this
            if (thisNode.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode)thisNode;
                if (!handledPages.Contains(pageNode))
                {
                    foreach (SobekCM_File_Info file in pageNode.Files)
                    {
                        returnValue.Add(file);
                    }
                    handledPages.Add(pageNode);
                }
            }

            // is this a division node? .. which can have children ..
            if (!thisNode.Page)
            {
                Division_TreeNode thisDivNode = (Division_TreeNode)thisNode;

                // Do the same for all the children
                foreach (abstract_TreeNode childNode in thisDivNode.Nodes)
                {
                    recursively_build_all_files_list(returnValue, handledPages, childNode);
                }
            }
        }
        private void recurse_through_nodes( SobekCM_Item ThisPackage, abstract_TreeNode Node, List<Page_TreeNode> PagesEncountered )
        {
            if (Node.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode)Node;
                if ( !PagesEncountered.Contains( pageNode ))
                {
                    pageseq++;

                    // Add each of the files view codes to the list
                    bool page_added = false;
                    foreach (SobekCM_File_Info thisFile in pageNode.Files)
                    {
                        string upper_name = thisFile.System_Name.ToUpper();
                        if ((upper_name.IndexOf("SOUNDFILESONLY") < 0) && ( upper_name.IndexOf("FILMONLY") < 0 ) && ( upper_name.IndexOf("MULTIMEDIA") < 0 ) && ( upper_name.IndexOf("THM.JPG") < 0 ))
                        {
                            if (!page_added)
                            {
                                // Add this to the simple page collection
                                ThisPackage.Web.Add_Pages_By_Sequence(pageNode);
                                PagesEncountered.Add(pageNode);
                                page_added = true;
                            }
                            View_Object thisViewer = thisFile.Get_Viewer();
                            if (thisViewer != null)
                            {
                                string[] codes = thisViewer.Viewer_Codes;
                                if ((codes.Length > 0) && (codes[0].Length > 0))
                                {
                                    ThisPackage.Web.Viewer_To_File[pageseq.ToString() + codes[0]] = thisFile;
                                }
                            }
                        }

                        // TEST: Special case for text
                        if ((ThisPackage.BibID == "UF00001672") || ( ThisPackage.BibID == "TEST000003"))
                        {
                            if (thisFile.File_Extension.ToLower().IndexOf("jpg") >= 0)
                            {
                                string filename = thisFile.File_Name_Sans_Extension + ".txt";
                                SobekCM_File_Info thisFileInfo = new SobekCM_File_Info(filename);
                                ThisPackage.Web.Viewer_To_File[pageseq.ToString() + "t"] = thisFileInfo;
                            }
                        }
                    }
                }
            }
            else
            {
                divseq++;
                Division_TreeNode divNode = (Division_TreeNode)Node;
                foreach (abstract_TreeNode childNode in divNode.Nodes)
                {
                    recurse_through_nodes(ThisPackage, childNode, PagesEncountered);
                }
            }
        }
        private void recursively_add_div_info(abstract_TreeNode ThisNode, TextWriter Results, Dictionary<abstract_TreeNode, int> PagesToAppearances, int Order)
        {
            // Add the div information for this node first
            if (ThisNode.Page)
            {
                // If the ID of this page is SKIP, then just return and do nothing here
                if (ThisNode.ID == "SKIP")
                    return;

                if (PagesToAppearances.ContainsKey(ThisNode))
                {
                    PagesToAppearances[ThisNode] = PagesToAppearances[ThisNode] + 1;
                    Results.Write("<METS:div ID=\"" + ThisNode.ID + "_repeat" + PagesToAppearances[ThisNode] + "\"");
                }
                else
                {
                    PagesToAppearances[ThisNode] = 1;
                    Results.Write("<METS:div ID=\"" + ThisNode.ID + "\"");
                }
            }
            else
            {
                Results.Write("<METS:div ID=\"" + ThisNode.ID + "\"");
            }

            // Add links to dmd secs and amd secs
            if ( !String.IsNullOrEmpty(ThisNode.DMDID))
            {
                Results.Write(" DMDID=\"" + ThisNode.DMDID + "\"");
            }
            if (!String.IsNullOrEmpty(ThisNode.ADMID))
            {
                Results.Write(" ADMID=\"" + ThisNode.ADMID + "\"");
            }

            // Add the label, if there is one
            if ((ThisNode.Label.Length > 0) && (ThisNode.Label != ThisNode.Type))
                Results.Write(" LABEL=\"" + Convert_String_To_XML_Safe(ThisNode.Label) + "\"");

            // Finish the start div label for this division
            Results.WriteLine(" ORDER=\"" + Order + "\" TYPE=\"" + ThisNode.Type + "\">");

            // If this is a page, add all the files, otherwise call this method recursively
            if (ThisNode.Page)
            {
                // Add each file
                Page_TreeNode thisPage = (Page_TreeNode)ThisNode;
                foreach (SobekCM_File_Info thisFile in thisPage.Files)
                {
                    // Add the file pointer informatino
                    if ( thisFile.ID.Length > 0 )
                        Results.WriteLine("<METS:fptr FILEID=\"" + thisFile.ID + "\" />");
                }
            }
            else
            {
                // Call this method for each subdivision
                int inner_order = 1;
                Division_TreeNode thisDivision = (Division_TreeNode)ThisNode;
                foreach (abstract_TreeNode thisSubDivision in thisDivision.Nodes)
                {
                    recursively_add_div_info(thisSubDivision, Results, PagesToAppearances, inner_order++ );
                }
            }

            // Close out this division
            Results.WriteLine("</METS:div>");
        }
        private void recursively_build_all_files_list(List<SobekCM_File_Info> returnValue, List<Page_TreeNode> handledPages, abstract_TreeNode thisNode)
        {
            // Since this is pre-order, first 'visit' this
            if (thisNode.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode) thisNode;
                if (!handledPages.Contains(pageNode))
                {
                    foreach (SobekCM_File_Info file in pageNode.Files)
                    {
                        returnValue.Add(file);
                    }
                    handledPages.Add(pageNode);
                }
            }

            // is this a division node? .. which can have children ..
            if (!thisNode.Page)
            {
                Division_TreeNode thisDivNode = (Division_TreeNode) thisNode;

                // Do the same for all the children
                foreach (abstract_TreeNode childNode in thisDivNode.Nodes)
                {
                    recursively_build_all_files_list(returnValue, handledPages, childNode);
                }
            }
        }
 /// <summary> Flag indicates if this active reader/writer needs to append schema reference information
 /// to the METS XML header by analyzing the contents of the division </summary>
 /// <param name="MetsDivision"> Division from the overall package into which to read the metadata</param>
 /// <returns> TRUE if the schema should be attached, otherwise fALSE </returns>
 public bool Schema_Reference_Required_Division(abstract_TreeNode MetsDivision)
 {
     // GEt the geo-spatial information if it exists
     GeoSpatial_Information geoInfo = MetsDivision.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
     if ((geoInfo == null) || (!geoInfo.hasData))
         return false;
     return true;
 }
        private void recursively_add_div_page_text( string source_directory, abstract_TreeNode thisNode, TextWriter Output_Stream, ref int page_count )
        {
            if (thisNode.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode) thisNode;

                if (pageNode.Files.Count > 0)
                {
                    string pageimage = String.Empty;
                    string textfilename = pageNode.Files[0].File_Name_Sans_Extension + ".txt";
                    foreach (SobekCM_File_Info thisFile in pageNode.Files)
                    {
                        if (thisFile.File_Extension.ToLower() == "txt")
                            textfilename = thisFile.System_Name;
                        if ((thisFile.File_Extension.ToLower() == "jpg") && (thisFile.System_Name.ToLower().IndexOf("thm.jpg") < 0))
                            pageimage = thisFile.System_Name;
                    }

                    // Add the page break first
                    Output_Stream.Write("<pb n=\"" + page_count + "\"");
                    if ( pageimage.Length > 0 )
                        Output_Stream.Write(" facs=\"" + Convert_String_To_XML_Safe(pageimage) + "\"");
                    Output_Stream.WriteLine(" />");

                    // Does the text file exist?
                    string text_file = source_directory + "\\" + textfilename;
                    try
                    {
                        if (System.IO.File.Exists(text_file))
                        {
                            Output_Stream.WriteLine(Convert_String_To_XML_Safe(System.IO.File.ReadAllText(text_file)));
                        }
                    }
                    catch { }

                }
                page_count++;
            }
            else
            {
                Division_TreeNode divNode = (Division_TreeNode) thisNode;
                if (thisNode.Type != "main")
                {
                    Output_Stream.WriteLine("<div type=\"" + thisNode.Type + "\">");
                    if ((thisNode.Label.Length > 0) && (thisNode.Label != thisNode.Type))
                    {
                        Output_Stream.WriteLine("<head>" + Convert_String_To_XML_Safe(thisNode.Label) + "</head>");
                    }
                }

                // Now, step through child nodes
                foreach (abstract_TreeNode childNode in divNode.Nodes)
                {
                    recursively_add_div_page_text(source_directory, childNode, Output_Stream, ref page_count);
                }

                if (thisNode.Type != "main")
                {
                    Output_Stream.WriteLine("</div>");

                }
            }
        }
        private void recurse_through_nodes(abstract_TreeNode Node, List<string> Extensions)
        {
            // Was this node a page?
            if (Node.Page)
            {
                // Cast back to the PAGE node
                Page_TreeNode pageNode = (Page_TreeNode)Node;

                // If no files, do not add this back
                if (pageNode.Files.Count == 0)
                    return;

                // Add a filenode for each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    string extension = thisFile.File_Extension.ToLower();
                    if (!Extensions.Contains(extension))
                        Extensions.Add(extension);
                }
            }
            else
            {
                // This was a division node
                Division_TreeNode divNode = (Division_TreeNode)Node;

                // Look for children nodes
                foreach (abstract_TreeNode childNode in divNode.Nodes)
                {
                    // Visit each child node
                    recurse_through_nodes(childNode, Extensions);
                }
            }
        }
        private void recurse_through_nodes( SobekCM_Item thisPackage, abstract_TreeNode node, List<Page_TreeNode> pages_encountered )
        {
            if (node.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode)node;
                if ( !pages_encountered.Contains( pageNode ))
                {
                    pageseq++;

                    // Add each of the files view codes to the list
                    bool page_added = false;
                    foreach (SobekCM_File_Info thisFile in pageNode.Files)
                    {
                        string upper_name = thisFile.System_Name.ToUpper();
                        if ((upper_name.IndexOf("SOUNDFILESONLY") < 0) && ( upper_name.IndexOf("FILMONLY") < 0 ) && ( upper_name.IndexOf("MULTIMEDIA") < 0 ) && ( upper_name.IndexOf("THM.JPG") < 0 ))
                        {
                            if (!page_added)
                            {
                                // Add this to the simple page collection
                                thisPackage.Web.Add_Pages_By_Sequence(pageNode);
                                pages_encountered.Add(pageNode);
                                page_added = true;
                            }
                            View_Object thisViewer = thisFile.Get_Viewer();
                            if (thisViewer != null)
                            {
                                string[] codes = thisViewer.Viewer_Codes;
                                if ((codes.Length > 0) && (codes[0].Length > 0))
                                {
                                    thisPackage.Web.Viewer_To_File[pageseq.ToString() + codes[0]] = thisFile;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                divseq++;
                Division_TreeNode divNode = (Division_TreeNode)node;
                foreach (abstract_TreeNode childNode in divNode.Nodes)
                {
                    recurse_through_nodes(thisPackage, childNode, pages_encountered);
                }
            }
        }
        private void preorder_build(List<abstract_TreeNode> Collection, abstract_TreeNode ThisNode, bool OnlyAddPages, bool PagesMustHaveFiles)
        {
            // Since this is pre-order, first 'visit' this
            if (!OnlyAddPages)
            {
                Collection.Add(ThisNode);
            }
            else
            {
                // If we are just getting pages, only add if it is not already added
                if ((ThisNode.Page) && (!Collection.Contains(ThisNode)))
                {
                    // If you just add all files, just add it here
                    if ( !PagesMustHaveFiles )
                        Collection.Add(ThisNode);
                    else
                    {
                        // Must ensure this page has files to add it
                        Page_TreeNode asPage = ThisNode as Page_TreeNode;
                        if (asPage != null)
                        {
                            if (( asPage.Files != null ) && ( asPage.Files.Count > 0 ))
                                Collection.Add(asPage);
                        }
                    }

                }
            }

            // is this a division node? .. which can have children ..
            if (!ThisNode.Page)
            {
                Division_TreeNode thisDivNode = (Division_TreeNode) ThisNode;

                // Do the same for all the children
                foreach (abstract_TreeNode childNode in thisDivNode.Nodes)
                {
                    preorder_build(Collection, childNode, OnlyAddPages, PagesMustHaveFiles);
                }
            }
        }
        private void preorder_build(List<abstract_TreeNode> collection, abstract_TreeNode thisNode, bool only_add_pages)
        {
            // Since this is pre-order, first 'visit' this
            if (!only_add_pages)
            {
                collection.Add(thisNode);
            }
            else
            {
                // If we are just getting pages, only add if it is not already added
                if ((thisNode.Page) && (!collection.Contains(thisNode)))
                    collection.Add(thisNode);
            }

            // is this a division node? .. which can have children ..
            if (!thisNode.Page)
            {
                Division_TreeNode thisDivNode = (Division_TreeNode) thisNode;

                // Do the same for all the children
                foreach (abstract_TreeNode childNode in thisDivNode.Nodes)
                {
                    preorder_build(collection, childNode, only_add_pages);
                }
            }
        }
        private bool recursively_add_file(abstract_TreeNode Node, SobekCM_File_Info New_File, string SystemName_Upper)
        {
            // If this is a page, check for a match first
            if (Node.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode) Node;
                if (pageNode.Files.Count >= 1)
                {
                    if (pageNode.Files[0].File_Name_Sans_Extension == SystemName_Upper)
                    {
                        // Belongs to this page.  Now, just make sure it doesn't already exist
                        foreach (SobekCM_File_Info thisFile in pageNode.Files)
                        {
                            if (thisFile.System_Name.ToUpper() == New_File.System_Name.ToUpper())
                                return true;
                        }

                        // Not found, so add it to this page
                        pageNode.Files.Add(New_File);
                        return true;
                    }
                }
            }

            // If this was a division, check all pages
            if (!Node.Page)
            {
                Division_TreeNode divNode = (Division_TreeNode) Node;
                foreach (abstract_TreeNode childNodes in divNode.Nodes)
                {
                    if (recursively_add_file(childNodes, New_File, SystemName_Upper))
                    {
                        return true;
                    }
                }
            }

            // If nothing found that matches under this node, return false
            return false;
        }
        /// <summary> Writes the dmdSec for one subsection/division of the METS structure map </summary>
        /// <param name="Output_Stream">Stream to which the formatted text is written </param>
        /// <param name="MetsDivision">Division from the overall package with all the metadata to save</param>
        /// <param name="Options"> Dictionary of any options which this METS section writer may utilize</param>
        /// <returns>TRUE if successful, otherwise FALSE </returns>
        public bool Write_dmdSec(TextWriter Output_Stream, abstract_TreeNode MetsDivision, Dictionary<string, object> Options)
        {
            // GEt the geo-spatial information if it exists
            GeoSpatial_Information geoInfo = MetsDivision.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;
            if ((geoInfo == null) || (!geoInfo.hasData))
                return true;

            return Write_Metadata_Section(Output_Stream, geoInfo, Options);
        }
        private bool recursively_check_for_any_files(abstract_TreeNode Node)
        {
            if (Node.Page)
            {
                if (((Page_TreeNode) Node).Files.Count > 0)
                    return true;
            }

            if (!Node.Page)
            {
                Division_TreeNode divNode = (Division_TreeNode) Node;
                foreach (abstract_TreeNode TreeNode in divNode.Nodes)
                {
                    if (recursively_check_for_any_files(TreeNode))
                        return true;
                }
            }

            return false;
        }
        private bool recurse_through_nodes(abstract_TreeNode Node, List<BriefItem_FileGrouping> Groupings, List<BriefItem_TocElement> Toc, Stack<BriefItem_TocElement> CurrDivStack, int Level)
        {
            // Was this node a page?
            if (Node.Page)
            {
                // Cast back to the PAGE node
                Page_TreeNode pageNode = (Page_TreeNode) Node;

                // If no files, do not add this back
                if (pageNode.Files.Count == 0)
                    return false;

                // Create the file grouping object for this
                BriefItem_FileGrouping newNode = new BriefItem_FileGrouping(pageNode.Label);

                // Add a filenode for each file
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    BriefItem_File newFile = new BriefItem_File(thisFile.System_Name);
                    if (thisFile.Width > 0)
                        newFile.Width = thisFile.Width;
                    if (thisFile.Height > 0)
                        newFile.Height = thisFile.Height;
                    newNode.Files.Add(newFile);
                }

                // Add this to the list of images
                Groupings.Add(newNode);

                // Since this was a page with files, return TRUE
                return true;
            }
            else
            {
                // Get what will be the sequence (if it turned out to have pages under it)
                int sequence = Groupings.Count + 1;

                // This was a division node
                Division_TreeNode divNode = (Division_TreeNode) Node;

                // Create the brief item TOC element
                BriefItem_TocElement divToc = new BriefItem_TocElement
                {
                    Level = Level,
                    Name = divNode.Label
                };
                if (string.IsNullOrEmpty(divToc.Name))
                    divToc.Name = divNode.Type;

                // Add to the stack
                CurrDivStack.Push(divToc);

                // Look for children nodes
                bool some_files_under = false;
                foreach (abstract_TreeNode childNode in divNode.Nodes)
                {
                    // Visit each child node
                    if (recurse_through_nodes(childNode, Groupings, Toc, CurrDivStack, Level + 1))
                        some_files_under = true;
                }

                // Were there some files under here?
                if (some_files_under)
                {
                    // Now, pop-up all the nodes in the queue and add them
                    if (CurrDivStack.Count > 0)
                    {
                        IEnumerable<BriefItem_TocElement> reversed = CurrDivStack.Reverse();
                        foreach (BriefItem_TocElement revDiv in reversed)
                        {
                            revDiv.Sequence = sequence;
                            Toc.Add(revDiv);
                        }
                        CurrDivStack.Clear();
                    }
                }
                else
                {
                    // If this division (with NO pages under it apparently) is on the stack,
                    // just pop it off
                    if (( CurrDivStack.Count > 0 ) && (CurrDivStack.Peek() == divToc))
                    {
                        CurrDivStack.Pop();
                    }
                }

                // Return whether there were any files under this
                return some_files_under;
            }
        }
 /// <summary> Add a new child node under this tree node </summary>
 /// <param name="childNode"> New node to add </param>
 public void Add_Child(abstract_TreeNode childNode)
 {
     children.Add(childNode);
 }
Example #25
0
 /// <summary> Add a new child node under this tree node </summary>
 /// <param name="childNode"> New node to add </param>
 public void Add_Child(abstract_TreeNode childNode)
 {
     children.Add(childNode);
 }
        private void recursively_add_page_names(abstract_TreeNode thisNode, string parentType, int Order, int Sibling_Count, List<abstract_TreeNode> visitedNodes)
        {
            if (thisNode.Page)
            {
                if (thisNode.Label.Length == 0)
                {
                    if ((parentType.ToUpper().IndexOf("CHAPTER") < 0) && (parentType.ToUpper().IndexOf("SUB") != 0))
                    {
                        if (Sibling_Count != 1)
                        {
                            thisNode.Label = parentType + " " + Order;
                        }
                        else
                        {
                            thisNode.Label = parentType;
                        }
                    }
                    else
                    {
                        thisNode.Label = "Unnumbered ( " + total_order + " )";
                    }
                }

                // Move along the total order counter
                if (!visitedNodes.Contains(thisNode))
                {
                    total_order++;
                    visitedNodes.Add(thisNode);
                }
            }
            else
            {
                Division_TreeNode divNode = (Division_TreeNode) thisNode;
                int new_order = 1;
                foreach (abstract_TreeNode subNode in divNode.Nodes)
                {
                    recursively_add_page_names(subNode, divNode.Type, new_order++, divNode.Nodes.Count, visitedNodes);
                }
            }
        }
        private void recursively_write_toc(StreamWriter Writer, abstract_TreeNode TreeNode, string Indent)
        {
            // Write this label, regardless of whether it is a page or a division (some page names have useful info)
            if ( TreeNode.Label.Length > 0 )
                Writer.WriteLine(Indent + TreeNode.Label + "<br />");
            else
                Writer.WriteLine(Indent + TreeNode.Type + "<br />");

            // If not a page, recurse more
            if (!TreeNode.Page)
            {
                Division_TreeNode divNode = (Division_TreeNode)TreeNode;
                foreach (abstract_TreeNode childNode in divNode.Nodes)
                {
                    recursively_write_toc(Writer, childNode, Indent + "&nbsp; &nbsp; ");
                }
            }
        }