/// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the publisher, and place of publications
            if (Original.Bib_Info.Publishers_Count > 0)
            {
                // Keep track of place of publications alreadyadded
                Dictionary<string, string> pub_places = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

                // Step through each publisher
                foreach (Publisher_Info thisPublisher in Original.Bib_Info.Publishers)
                {
                    // Add the name
                    New.Add_Description("Publisher", thisPublisher.Name);

                    // Add the places of publication
                    foreach (Origin_Info_Place thisPubPlace in thisPublisher.Places)
                    {
                        if (!pub_places.ContainsKey(thisPubPlace.Place_Text))
                        {
                            New.Add_Description("Place of Publication", thisPubPlace.Place_Text);
                            pub_places.Add(thisPubPlace.Place_Text, thisPubPlace.Place_Text);
                        }
                    }
                }
            }

            return true;
        }
        /// <summary> Gets the list of all the files associated with this digital resource </summary>
        /// <param name="DigitalResource"> The digital resource object  </param>
        /// <returns> List of the file information for this digital resource, or NULL if this does not exist somehow </returns>
        public List<SobekFileSystem_FileInfo> GetFiles(BriefItemInfo DigitalResource)
        {
            string directory = Resource_Network_Uri(DigitalResource);

            try
            {

                if (Directory.Exists(directory))
                {
                    FileInfo[] files = (new DirectoryInfo(directory)).GetFiles();
                    List<SobekFileSystem_FileInfo> returnValue = new List<SobekFileSystem_FileInfo>();
                    foreach (FileInfo thisFile in files)
                    {
                        SobekFileSystem_FileInfo returnFile = new SobekFileSystem_FileInfo
                        {
                            Name = thisFile.Name,
                            LastWriteTime = thisFile.LastWriteTime,
                            Extension = thisFile.Extension,
                            Length = thisFile.Length
                        };

                        returnValue.Add(returnFile);
                    }

                    return returnValue;
                }
            }
            catch (Exception ee)
            {
                return null;
            }

            return null;
        }
        /// <summary> Constructor for a new instance of the Text_Search_ItemViewer class, which allows the full text of an 
        /// individual resource to be searched and individual matching pages are displayed with page thumbnails </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Text_Search_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer )
        {
            Tracer.Add_Trace("Text_Search_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            if (!String.IsNullOrWhiteSpace(CurrentRequest.Text_Search))
            {
                List<string> terms = new List<string>();
                List<string> web_fields = new List<string>();

                // Split the terms correctly
                SobekCM_Assistant.Split_Clean_Search_Terms_Fields(CurrentRequest.Text_Search, "ZZ", Search_Type_Enum.Basic, terms, web_fields, null, Search_Precision_Type_Enum.Contains, '|');

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Performing Solr/Lucene search");

                int page = CurrentRequest.SubPage.HasValue ? Math.Max(CurrentRequest.SubPage.Value, ((ushort)1)) : 1;
                results = Solr_Page_Results.Search(BriefItem.BibID, BriefItem.VID, terms, 20, page, false);

                Tracer.Add_Trace("Text_Search_ItemViewer.Constructor", "Completed Solr/Lucene search in " + results.QueryTime + "ms");
            }
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // If the original item was DARK, don't add any file information
            if (Original.Behaviors.Dark_Flag) return true;

            // Step through each of the nodes within the images first
            List<BriefItem_FileGrouping> images = new List<BriefItem_FileGrouping>();
            List<BriefItem_FileGrouping> downloads = new List<BriefItem_FileGrouping>();
            List<BriefItem_TocElement> images_toc = new List<BriefItem_TocElement>();
            List<BriefItem_TocElement> downloads_toc = new List<BriefItem_TocElement>();

            // Do the images (i.e., physical tree) first
            collect_nodes(Original.Divisions.Physical_Tree, images, images_toc);

            // If there were groupings and TOCs assigned, add them
            if (images.Count > 0)
                New.Images = images;
            if (images_toc.Count > 0)
                New.Images_TOC = images_toc;

            // Collect the downloads next
            collect_nodes(Original.Divisions.Download_Tree, downloads, downloads_toc);

            // If there were groupings and TOCs assigned, add them
            if (downloads.Count > 0)
                New.Downloads = downloads;
            if (downloads_toc.Count > 0)
                New.Downloads_TOC = downloads_toc;

            // No exception
            return true;
        }
        /// <summary> Constructor for a new instance of the TEI_ItemViewer class, used to display a
        /// TEI file for a given digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public TEI_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Get the TEI files to use
            tei_file = BriefItem.Behaviors.Get_Setting("TEI.Source_File");
            xslt_file = BriefItem.Behaviors.Get_Setting("TEI.XSLT");
            css_file = BriefItem.Behaviors.Get_Setting("TEI.CSS");

            // Ensure the XSLT file really exists
            if (!File.Exists(xslt_file))
            {
                // This may just not have the path on it
                if ((xslt_file.IndexOf("/") < 0) && (xslt_file.IndexOf("\\") < 0))
                {
                    xslt_file = Path.Combine(UI_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network, "plugins\\tei\\xslt", xslt_file);
                }
            }

            string tei_file_network = SobekFileSystem.Resource_Network_Uri(BriefItem, tei_file);

            XSLT_Transformer_ReturnArgs returnArgs = XSLT_Transformer.Transform(tei_file_network, xslt_file);
            tei_string_to_display = String.Empty;
            if (returnArgs.Successful)
            {
                tei_string_to_display = returnArgs.TransformedString;

                // FInd the head information
                int head_start = tei_string_to_display.IndexOf("<head", StringComparison.OrdinalIgnoreCase);
                int head_end = tei_string_to_display.IndexOf("</head>", StringComparison.OrdinalIgnoreCase);
                if ((head_start > 0) && (head_end > 0))
                {
                    head_info = tei_string_to_display.Substring(head_start, head_end - head_start);
                    int end_bracket = head_info.IndexOf(">");
                    head_info = head_info.Substring(end_bracket + 1);
                }

                // Trim down to the body
                int body_start = tei_string_to_display.IndexOf("<body", StringComparison.OrdinalIgnoreCase);
                int body_end = tei_string_to_display.IndexOf("</body>", StringComparison.OrdinalIgnoreCase);

                if ((body_start > 0) && (body_end > 0))
                {
                    tei_string_to_display = tei_string_to_display.Substring(body_start, body_end - body_start);
                    int end_bracket = tei_string_to_display.IndexOf(">");
                    tei_string_to_display = tei_string_to_display.Substring(end_bracket + 1);
                }

            }
            else
            {
                tei_string_to_display = "Error during XSLT transform of TEI<br /><br />" + returnArgs.ErrorMessage;
            }
        }
        /// <summary> Create the BriefItemInfo from a full METS-based SobekCM_Item object,
        /// using the default mapping set </summary>
        /// <param name="Original"> Original METS-based object to use </param>
        /// <param name="MappingSetId"> Name of the mapping set to use (if there are more than one)</param>
        /// <param name="Tracer"> Custom tracer to record general process flow </param>
        /// <returns> Completely built BriefItemInfo object from the METS-based SobekCM_Item object </returns>
        public static BriefItemInfo Create(SobekCM_Item Original, string MappingSetId, Custom_Tracer Tracer )
        {
            // Try to get the brief mapping set
            List<IBriefItemMapper> mappingSet = get_mapping_set(MappingSetId);

            // Create the mostly empty new brief item
            Tracer.Add_Trace("BriefItem_Factory.Create", "Create the mostly empty new brief item");
            BriefItemInfo newItem = new BriefItemInfo
            {
                BibID = Original.BibID,
                VID = Original.VID,
                Title = Original.Bib_Info.Main_Title.Title
            };

            // Build the new item using the selected mapping set
            Tracer.Add_Trace("BriefItem_Factory.Create", "Use the set of mappers to map data to the brief item");
            foreach (IBriefItemMapper thisMapper in mappingSet)
            {
                Tracer.Add_Trace("BriefItem_Factory.Create", "...." + thisMapper.GetType().ToString().Replace("SobekCM.Engine_Library.Items.BriefItems.Mappers.",""));
                thisMapper.MapToBriefItem(Original, newItem);
            }
            Tracer.Add_Trace("BriefItem_Factory.Create", "Finished using all instatiated and configued mappers");

            return newItem;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the IDENTIFIERS
            if (Original.Bib_Info.Identifiers_Count > 0)
            {
                foreach (Identifier_Info thisIdentifier in Original.Bib_Info.Identifiers)
                {
                    // Add this identifier
                    if (!String.IsNullOrWhiteSpace(thisIdentifier.Type))
                    {
                        New.Add_Description("Resource Identifier", thisIdentifier.Identifier).Authority = thisIdentifier.Type;

                        // Special code for accession number
                        if (thisIdentifier.Type.IndexOf("ACCESSION", StringComparison.OrdinalIgnoreCase) >= 0)
                            New.Add_Description("Accession Number", thisIdentifier.Identifier).Authority = thisIdentifier.Type;
                    }
                    else
                    {
                        New.Add_Description("Resource Identifier", thisIdentifier.Identifier);
                    }
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the aggregations
            if ((Original.Behaviors.Aggregation_Count > 0) && (Engine_ApplicationCache_Gateway.Codes != null))
            {
                foreach (Aggregation_Info thisAggr in Original.Behaviors.Aggregations)
                {
                    // Look for the aggregation in the current aggregation codes
                    Item_Aggregation_Related_Aggregations aggrObj = Engine_ApplicationCache_Gateway.Codes[thisAggr.Code];

                    // If the aggregation is NULL, as it may have been deleted, skip it
                    if (aggrObj == null) continue;

                    // If active, add with the URL, otherwise just add the short name
                    if (aggrObj.Active)
                    {
                        New.Add_Description("Aggregations", aggrObj.ShortName).Add_URI("[%BASEURL%]" + aggrObj.Code + "[%URLOPTS%]");
                    }
                    else
                    {
                        New.Add_Description("Aggregations", aggrObj.ShortName);
                    }
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the SOURCE INSTITUTION information
            if (!String.IsNullOrWhiteSpace(Original.Bib_Info.Source.Statement))
            {
                // Add the source institution
                BriefItem_DescTermValue sourceValue = New.Add_Description("Source Institution", Original.Bib_Info.Source.Statement);

                // Was the code present, and active?
                if (!String.IsNullOrWhiteSpace(Original.Bib_Info.Source.Code))
                {
                    if ((Engine_ApplicationCache_Gateway.Codes != null) && (Engine_ApplicationCache_Gateway.Codes.isValidCode("i" + Original.Bib_Info.Source.Code)))
                    {
                        Item_Aggregation_Related_Aggregations sourceAggr = Engine_ApplicationCache_Gateway.Codes["i" + Original.Bib_Info.Source.Code];
                        if (sourceAggr.Active)
                        {
                            sourceValue.Add_URI("[%BASEURL%]" + "i" + Original.Bib_Info.Source.Code + "[%URLOPTS%]");
                        }

                        // Was there an external link on this agggreation?
                        if (!String.IsNullOrWhiteSpace(sourceAggr.External_Link))
                        {
                            sourceValue.Add_URI(sourceAggr.External_Link);
                        }
                    }
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add all the origination information, primarily dates )
            if (Original.Bib_Info.Origin_Info != null)
            {
                // Add the creation date
                if ((!String.IsNullOrWhiteSpace(Original.Bib_Info.Origin_Info.Date_Created)) && (Original.Bib_Info.Origin_Info.Date_Created.Trim() != "-1"))
                {
                    New.Add_Description("Creation Date", Original.Bib_Info.Origin_Info.Date_Created);
                }

                // Add the publication date, looking under DATE ISSUED, or under MARC DATE ISSUED
                if (!String.IsNullOrWhiteSpace(Original.Bib_Info.Origin_Info.Date_Issued))
                {
                    if (Original.Bib_Info.Origin_Info.Date_Issued.Trim() != "-1")
                    {
                        New.Add_Description("Publication Date", Original.Bib_Info.Origin_Info.Date_Issued);
                    }
                }
                else if (!String.IsNullOrWhiteSpace(Original.Bib_Info.Origin_Info.MARC_DateIssued))
                {
                    New.Add_Description("Publication Date", Original.Bib_Info.Origin_Info.MARC_DateIssued);
                }

                // Add the copyright date
                if ((!String.IsNullOrWhiteSpace(Original.Bib_Info.Origin_Info.Date_Copyrighted)) && (Original.Bib_Info.Origin_Info.Date_Copyrighted.Trim() != "-1"))
                {
                    New.Add_Description("Copyright Date", Original.Bib_Info.Origin_Info.Date_Copyrighted);
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add each language
            if (Original.Bib_Info.Languages_Count > 0)
            {
                foreach (Language_Info thisLanguage in Original.Bib_Info.Languages)
                {
                    if (!String.IsNullOrWhiteSpace(thisLanguage.Language_Text))
                    {
                        string language_text = thisLanguage.Language_Text;
                        string from_possible_code = thisLanguage.Get_Language_By_Code(language_text);
                        if (from_possible_code.Length > 0)
                            language_text = from_possible_code;
                        New.Add_Description("Language", language_text);
                    }
                    else
                    {
                        if (!String.IsNullOrWhiteSpace(thisLanguage.Language_ISO_Code))
                        {
                            string language_text = thisLanguage.Get_Language_By_Code(thisLanguage.Language_ISO_Code);
                            if (language_text.Length > 0)
                            {
                                New.Add_Description("Language", language_text);
                            }
                        }
                    }
                }
            }

            return true;
        }
        /// <summary> Constructor for a new instance of the JPEG_ItemViewer class, used to display JPEGs linked to
        /// pages in a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <param name="JPEG_ViewerCode"> JPEG viewer code, as determined by configuration files </param>
        /// <param name="FileExtensions"> File extensions that this viewer allows, as determined by configuration files </param>
        public JPEG_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer, string JPEG_ViewerCode, string[] FileExtensions)
        {
            // Add the trace
            if ( Tracer != null )
                Tracer.Add_Trace("JPEG_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties
            Behaviors = EmptyBehaviors;

            // Is the JPEG2000 viewer included in this item?
            bool zoomableViewerIncluded = BriefItem.UI.Includes_Viewer_Type("JPEG2000");
            string[] jpeg2000_extensions = null;
            if (zoomableViewerIncluded)
            {
                iItemViewerPrototyper jp2Prototyper = ItemViewer_Factory.Get_Viewer_By_ViewType("JPEG2000");
                if (jp2Prototyper == null)
                    zoomableViewerIncluded = false;
                else
                {
                    zoomableViewerCode = jp2Prototyper.ViewerCode;
                    jpeg2000_extensions = jp2Prototyper.FileExtensions;
                }
            }

            // Set some default values
            width = 500;
            height = -1;
            includeLinkToZoomable = false;

            // Determine the page
            page = 1;
            if (!String.IsNullOrEmpty(CurrentRequest.ViewerCode))
            {
                int tempPageParse;
                if (Int32.TryParse(CurrentRequest.ViewerCode.Replace(JPEG_ViewerCode.Replace("#",""), ""), out tempPageParse))
                    page = tempPageParse;
            }

            // Just a quick range check
            if (page > BriefItem.Images.Count)
                page = 1;

            // Try to set the file information here
            if ((!set_file_information(FileExtensions, zoomableViewerIncluded, jpeg2000_extensions)) && (page != 1))
            {
                // If there was an error, just set to the first page
                page = 1;
                set_file_information(FileExtensions, zoomableViewerIncluded, jpeg2000_extensions);
            }

            // Since this is a paging viewer, set the viewer code
            if (String.IsNullOrEmpty(CurrentRequest.ViewerCode))
                CurrentRequest.ViewerCode = JPEG_ViewerCode.Replace("#", page.ToString());
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Try to get the VRA Core metadata
            VRACore_Info vraInfo = Original.Get_Metadata_Module(GlobalVar.VRACORE_METADATA_MODULE_KEY) as VRACore_Info;

            // Add the learning object metadata if it exists
            if ((vraInfo != null) && (vraInfo.hasData))
            {
                // Collect the state/edition information
                if (vraInfo.State_Edition_Count > 0)
                {
                    New.Add_Description("State / Edition", vraInfo.State_Editions);
                }

                // Collect and display all the material information
                if (vraInfo.Material_Count > 0)
                {
                    foreach (VRACore_Materials_Info materials in vraInfo.Materials)
                    {
                        New.Add_Description("Materials", materials.Materials);
                    }
                }

                // Collect and display all the measurements information
                if (vraInfo.Measurement_Count > 0)
                {
                    foreach (VRACore_Measurement_Info measurement in vraInfo.Measurements)
                    {
                        New.Add_Description("Measurements", measurement.Measurements);
                    }
                }

                // Display all cultural context information
                if (vraInfo.Cultural_Context_Count > 0)
                {
                    New.Add_Description("Cultural Context", vraInfo.Cultural_Contexts );
                }

                // Display all style/period information
                if (vraInfo.Style_Period_Count > 0)
                {
                    New.Add_Description("Style/Period", vraInfo.Style_Periods);
                }

                // Display all technique information
                if (vraInfo.Technique_Count > 0)
                {
                    New.Add_Description("Technique", vraInfo.Techniques);
                }

                // Add the inscriptions
                if (vraInfo.Inscription_Count > 0)
                {
                    New.Add_Description("Inscription", vraInfo.Inscriptions);
                }
            }

            return true;
        }
        /// <summary> Constructor for a new instance of the Google_Coordinate_Entry_ItemViewer class, used to edit the 
        /// coordinate information associated with this digital resource within an online google maps interface </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Google_Coordinate_Entry_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer )
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            try
            {

                // Get the full SobekCM item
                Tracer.Add_Trace("Google_Coordinate_Entry_ItemViewer.Constructor", "Try to pull this sobek complete item");
                currentItem = SobekEngineClient.Items.Get_Sobek_Item(CurrentRequest.BibID, CurrentRequest.VID, Tracer);
                if (currentItem == null)
                {
                    Tracer.Add_Trace("Google_Coordinate_Entry_ItemViewer.Constructor", "Unable to build complete item");
                    CurrentRequest.Mode = Display_Mode_Enum.Error;
                    CurrentRequest.Error_Message = "Invalid Request : Unable to build complete item";
                    return;
                }

                //string resource_directory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + CurrentItem.Web.AssocFilePath;
                //string current_mets = resource_directory + CurrentItem.METS_Header.ObjectID + ".mets.xml";

                // If there is no user, send to the login
                if (CurrentUser == null)
                {
                    CurrentRequest.Mode = Display_Mode_Enum.My_Sobek;
                    CurrentRequest.My_Sobek_Type = My_Sobek_Type_Enum.Logon;
                    CurrentRequest.Return_URL = BriefItem.BibID + "/" + BriefItem.VID + "/mapedit";
                    UrlWriterHelper.Redirect(CurrentRequest);
                    return;
                }

                //holds actions from page
                string action = HttpContext.Current.Request.Form["action"] ?? String.Empty;
                string payload = HttpContext.Current.Request.Form["payload"] ?? String.Empty;

                // See if there were hidden requests
                if (!String.IsNullOrEmpty(action))
                {
                    if (action == "save")
                        SaveContent(payload);
                }

                ////create a backup of the mets
                //string backup_directory = UI_ApplicationCache_Gateway.Settings.Servers.Image_Server_Network + Current_Item.Web.AssocFilePath + UI_ApplicationCache_Gateway.Settings.Resources.Backup_Files_Folder_Name;
                //string backup_mets_name = backup_directory + "\\" + CurrentItem.METS_Header.ObjectID + "_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".mets.bak";
                //File.Copy(current_mets, backup_mets_name);

            }
            catch (Exception ee)
            {
                //Custom_Tracer.Add_Trace("MapEdit Start Failure");
                throw new ApplicationException("MapEdit Start Failure\r\n" + ee.Message);
            }
        }
        /// <summary> Creates and sends the email when a user 'shares' a single digital resource </summary>
        /// <param name="Recepient_List"> Recepient list for this email </param>
        /// <param name="CcList"> CC list for this email </param>
        /// <param name="Comments"> Sender's comments to be included in the email </param>
        /// <param name="User_Name"> Name of the user that sent this email </param>
        /// <param name="SobekCM_Instance_Name"> Name of the current SobekCM instance (i.e., UDC, dLOC, etc..)</param>
        /// <param name="Item"> Digital resource to email </param>
        /// <param name="HTML_Format"> Tells if this should be sent as HMTL, otherwise it will be plain text </param>
        /// <param name="URL"> Direct URL for this item </param>
        /// <param name="UserID"> Primary key for the user that is sendig the email </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool Send_Email( string Recepient_List, string CcList, string Comments, string User_Name, string SobekCM_Instance_Name, BriefItemInfo Item, bool HTML_Format, string URL, int UserID )
        {
            if (HTML_Format)
            {
                return HTML_Send_Email(Recepient_List, CcList, Comments, User_Name, SobekCM_Instance_Name, Item, URL, UserID) || Text_Send_Email(Recepient_List, CcList, Comments, User_Name, SobekCM_Instance_Name, Item, URL, UserID);
            }

            return Text_Send_Email(Recepient_List, CcList, Comments, User_Name, SobekCM_Instance_Name, Item, URL, UserID);
        }
        /// <summary> Constructor for a new instance of the Flash_ItemViewer class, used to display a
        /// flash file, or flash video, for a given digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public Flash_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Find the appropriate flash files and label
            flash_file = String.Empty;
            flash_label = String.Empty;
            string first_label = String.Empty;
            string first_file = String.Empty;

            int current_flash_index = 0;
            const int FLASH_INDEX = 0;
            foreach (BriefItem_FileGrouping thisPage in BriefItem.Downloads)
            {
                // Look for a flash file on each page
                foreach (BriefItem_File thisFile in thisPage.Files)
                {
                    if (String.Compare(thisFile.File_Extension, ".SWF", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // If this is the first one, assign it
                        if (String.IsNullOrEmpty(first_file))
                        {
                            first_file = thisFile.Name;
                            first_label = thisPage.Label;
                        }

                        if (current_flash_index == FLASH_INDEX)
                        {
                            flash_file = thisFile.Name;
                            flash_label = thisPage.Label;
                            break;
                        }
                        current_flash_index++;
                    }
                }
            }

            // If none found, but a first was found, use that
            if ((String.IsNullOrEmpty(flash_file)) && (!String.IsNullOrEmpty(first_file)))
            {
                flash_file = first_file;
                flash_label = first_label;
            }

            // If this is not already a link format, make it one
            if (( !String.IsNullOrEmpty(flash_file)) && ( flash_file.IndexOf("http:") < 0))
            {
                flash_file = BriefItem.Web.Source_URL + "/" + flash_file;
            }
        }
        /// <summary> Constructor for a new instance of the Restricted_ItemViewer class, used display
        ///  the applicable restricted message for a digital resource which is currently restricted due to IP restrictions </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public Restricted_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the donor
            if ((Original.Bib_Info.hasDonor) && (!String.IsNullOrWhiteSpace(Original.Bib_Info.Donor.Full_Name)))
            {
                New.Add_Description("Donor", Original.Bib_Info.Donor.ToString());
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the physical description
            if ((Original.Bib_Info.Original_Description != null) && (!String.IsNullOrWhiteSpace(Original.Bib_Info.Original_Description.Extent)))
            {
                New.Add_Description("Physical Description", Original.Bib_Info.Original_Description.Extent);
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Attempt to pull the top-level geo-spatial data from the source object
            GeoSpatial_Information geoInfo = Original.Get_Metadata_Module(GlobalVar.GEOSPATIAL_METADATA_MODULE_KEY) as GeoSpatial_Information;

            // If there was geo-spatial data here, add it to the new item
            if ((geoInfo != null) && (geoInfo.hasData) && ((geoInfo.Point_Count > 0) || (geoInfo.Polygon_Count > 0)))
            {
                // Add each point first
                for (int i = 0; i < geoInfo.Point_Count; i++)
                {
                    if ( !String.IsNullOrEmpty(geoInfo.Points[i].Label))
                    {
                        New.Add_Description("Coordinates", geoInfo.Points[i].Latitude + " x " + geoInfo.Points[i].Longitude + " ( " + geoInfo.Points[i].Label + " )");
                    }
                    else
                    {
                        New.Add_Description("Coordinates", geoInfo.Points[i].Latitude + " x " + geoInfo.Points[i].Longitude );
                    }
                }

                // Add the polygons
                if (geoInfo.Polygon_Count == 1)
                {
                    for (int i = 0; i < geoInfo.Polygon_Count; i++)
                    {
                        Coordinate_Polygon polygon = geoInfo.Get_Polygon(i);
                        StringBuilder polygonBuilder = new StringBuilder();
                        foreach (Coordinate_Point thisPoint in polygon.Edge_Points)
                        {
                            if (polygonBuilder.Length > 0)
                            {
                                polygonBuilder.Append(", " + thisPoint.Latitude + " x " + thisPoint.Longitude);
                            }
                            else
                            {
                                polygonBuilder.Append(thisPoint.Latitude + " x " + thisPoint.Longitude);
                            }
                        }

                        if (polygon.Label.Length > 0)
                        {
                            polygonBuilder.Append(" ( " + polygon.Label + " )");
                        }
                        if (polygonBuilder.ToString().Trim().Length > 0)
                        {
                            New.Add_Description("Polygon", polygonBuilder.ToString());
                        }
                    }
                }
            }

            return true;
        }
        /// <summary> Constructor for a new instance of the Directory_ItemViewer class, used display
        /// the tracking milestones information for a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public Directory_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Directory_ItemViewer.Constructor");

            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            if (!String.IsNullOrEmpty(Original.Tracking.Internal_Comments))
            {
                if (New.Web == null)
                    New.Web = new BriefItem_Web();

                New.Web.Internal_Comments = Original.Tracking.Internal_Comments;
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the desciption user tags
            if (Original.Behaviors.User_Tags_Count > 0)
            {
                foreach (Descriptive_Tag tag in Original.Behaviors.User_Tags)
                {
                    New.Add_Description("User Description", tag.Description_Tag).Authority = tag.UserName + "|" + tag.Date_Added.ToShortDateString();
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the containers
            if (Original.Bib_Info.Containers_Count > 0)
            {
                foreach (Finding_Guide_Container thisContainer in Original.Bib_Info.Containers)
                {
                    New.Add_Description("Physical Location", thisContainer.Name).SubTerm = thisContainer.Type;
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add all the (author) affiliations
            if (Original.Bib_Info.Affiliations_Count > 0)
            {
                foreach (Affiliation_Info thisAffiliation in Original.Bib_Info.Affiliations)
                {
                    New.Add_Description("Affiliation", thisAffiliation.ToString());
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the desciption user tag objects
            if (Original.Behaviors.User_Tags_Count > 0)
            {
                foreach (Descriptive_Tag tag in Original.Behaviors.User_Tags)
                {
                    New.Web.Add_User_Tag(tag.UserID, tag.UserName, tag.Description_Tag, tag.Date_Added, tag.TagID);
                }
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the RIGHTS STATEMENT
            if (!String.IsNullOrWhiteSpace(Original.Bib_Info.Access_Condition.Text))
            {
                string value = Original.Bib_Info.Access_Condition.Text;
                string uri = String.Empty;

                if (value.IndexOf("[cc by-nc-nd]") >= 0)
                {
                    value = value.Replace("[cc by-nc-nd]", String.Empty);
                    uri = "http://creativecommons.org/licenses/by-nc-nd/3.0/";
                }
                if (value.IndexOf("[cc by-nc-sa]") >= 0)
                {
                    value = value.Replace("[cc by-nc-sa]", String.Empty);
                    uri = "http://creativecommons.org/licenses/by-nc-sa/3.0/";
                }
                if (value.IndexOf("[cc by-nc]") >= 0)
                {
                    value = value.Replace("[cc by-nc]", String.Empty);
                    uri = "http://creativecommons.org/licenses/by-nc/3.0/";
                }
                if (value.IndexOf("[cc by-nd]") >= 0)
                {
                    value = value.Replace("[cc by-nd]", String.Empty);
                    uri = "http://creativecommons.org/licenses/by-nd/3.0/";
                }
                if (value.IndexOf("[cc by-sa]") >= 0)
                {
                    value = value.Replace("[cc by-sa]", String.Empty);
                    uri = "http://creativecommons.org/licenses/by-sa/3.0/";
                }
                if (value.IndexOf("[cc by]") >= 0)
                {
                    value = value.Replace("[cc by]", String.Empty);
                    uri = "http://creativecommons.org/licenses/by/3.0/";
                }
                if (value.IndexOf("[cc0]") >= 0)
                {
                    value = value.Replace("[cc0]", String.Empty);
                    uri = "http://creativecommons.org/publicdomain/zero/1.0/";
                }

                BriefItem_DescTermValue rightsVal = New.Add_Description("Rights Management", value);
                if (uri.Length > 0)
                    rightsVal.Add_URI(uri);
            }

            return true;
        }
        /// <summary> Map one or more data elements from the original METS-based object to the
        /// BriefItem object </summary>
        /// <param name="Original"> Original METS-based object </param>
        /// <param name="New"> New object to populate some data from the original </param>
        /// <returns> TRUE if successful, FALSE if an exception is encountered </returns>
        public bool MapToBriefItem(SobekCM_Item Original, BriefItemInfo New)
        {
            // Add the manufacturers
            if (Original.Bib_Info.Manufacturers_Count > 0)
            {
                foreach (Publisher_Info thisPublisher in Original.Bib_Info.Manufacturers)
                {
                    // Add the name
                    New.Add_Description("Manufacturer", thisPublisher.Name);
                }
            }

            return true;
        }
        /// <summary> Constructor for a new instance of the PDF_ItemViewer class, used to display a PDF file from a digital resource </summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <param name="FileExtensions"> List of file extensions this video viewer should show </param>
        public PDF_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest, Custom_Tracer Tracer, string[] FileExtensions)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Determine if this should be written as an iFrame
            writeAsIframe = ((!String.IsNullOrEmpty(CurrentRequest.Browser_Type)) && (CurrentRequest.Browser_Type.IndexOf("CHROME") == 0));

            // Set the behavior properties
            Behaviors = new List<HtmlSubwriter_Behaviors_Enum> {HtmlSubwriter_Behaviors_Enum.Suppress_Footer};

            // Determine if a particular video was selected
            pdf = 1;
            if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["pdf"]))
            {
                int tryPdf;
                if (Int32.TryParse(HttpContext.Current.Request.QueryString["pdf"], out tryPdf))
                {
                    if (tryPdf < 1)
                        tryPdf = 1;
                    pdf = tryPdf;
                }
            }

            // Collect the list of pdf by stepping through each download page
            pdfFileNames = new List<string>();
            pdfLabels = new List<string>();
            foreach (BriefItem_FileGrouping downloadPage in BriefItem.Downloads)
            {
                foreach (BriefItem_File thisFileInfo in downloadPage.Files)
                {
                    string extension = thisFileInfo.File_Extension.Replace(".", "");
                    foreach (string thisPossibleFileExtension in FileExtensions)
                    {
                        if (String.Compare(extension, thisPossibleFileExtension, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            pdfFileNames.Add(thisFileInfo.Name);
                            pdfLabels.Add(downloadPage.Label);
                        }
                    }
                }
            }

            // Ensure the pdf count wasn't too large
            if (pdf > pdfFileNames.Count)
                pdf = 1;
        }
        /// <summary> Constructor for a new instance of the Citation_MARC_ItemViewer class, used to display the 
        /// descriptive citation in MARC21 format</summary>
        /// <param name="BriefItem"> Digital resource object </param>
        /// <param name="CurrentUser"> Current user, who may or may not be logged on </param>
        /// <param name="CurrentRequest"> Information about the current request </param>
        public Citation_MARC_ItemViewer(BriefItemInfo BriefItem, User_Object CurrentUser, Navigation_Object CurrentRequest)
        {
            // Save the arguments for use later
            this.BriefItem = BriefItem;
            this.CurrentUser = CurrentUser;
            this.CurrentRequest = CurrentRequest;

            // Set the behavior properties to the empy behaviors ( in the base class )
            Behaviors = EmptyBehaviors;

            // Check to see if the user can edit this
            userCanEdit = false;
            if ( CurrentUser != null )
                userCanEdit = CurrentUser.Can_Edit_This_Item(BriefItem.BibID, BriefItem.Type, BriefItem.Behaviors.Source_Institution_Aggregation, BriefItem.Behaviors.Holding_Location_Aggregation, BriefItem.Behaviors.Aggregation_Code_List);
        }
 /// <summary> Constructor for a new instance of the BriefItem_CitationXmlResponse class </summary>
 public BriefItem_CitationResponse()
 {
     briefItem = new BriefItemInfo();
 }
 /// <summary> Constructor for a new instance of the BriefItem_CitationXmlResponse class </summary>
 /// <param name="fullItemInfo"> Full information object to be wrapped by this class </param>
 public BriefItem_CitationResponse(BriefItemInfo fullItemInfo)
 {
     briefItem = fullItemInfo;
 }