Esempio n. 1
0
        /// <summary> Constructor for a new instance of the Web_Content_HtmlSubwriter class </summary>
        /// <param name="Hierarchy_Object"> Current item aggregation object to display </param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
        /// <param name="Static_Web_Content"> Object contains all the basic information about this info display </param>
        /// <param name="Site_Map"> Optional site map object used to render a navigational tree-view on left side of page</param>
        public Web_Content_HtmlSubwriter(Item_Aggregation Hierarchy_Object,
                                         SobekCM_Navigation_Object Current_Mode, SobekCM_Skin_Object HTML_Skin, HTML_Based_Content Static_Web_Content,
                                         SobekCM_SiteMap Site_Map)
        {
            base.Hierarchy_Object = Hierarchy_Object;
            currentMode           = Current_Mode;
            Skin = HTML_Skin;

            thisStaticBrowseObject = Static_Web_Content;
            siteMap = Site_Map;

            // If there is a sitemap, check if this is a robot request and then if the URL
            // for the sitemap pages is URL restricted
            if ((siteMap != null) && (siteMap.Is_URL_Restricted_For_Robots) && (currentMode.Is_Robot))
            {
                if (currentMode.Base_URL != siteMap.Restricted_Robot_URL)
                {
                    currentMode.Base_URL = siteMap.Restricted_Robot_URL;
                    string redirect_url = currentMode.Redirect_URL();

                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Status = "301 Moved Permanently";
                    HttpContext.Current.Response.AddHeader("Location", redirect_url);
                    HttpContext.Current.Response.End();
                }
            }
        }
        /// <summary> Reads an existing site map file and returns the fully built <see cref="SobekCM_SiteMap" /> object </summary>
        /// <param name="SiteMap_File"> Sitemap file to read </param>
        /// <returns> Fully built sitemap object </returns>
        public static SobekCM_SiteMap Read_SiteMap_File(string SiteMap_File)
        {
            Stream          reader     = null;
            XmlTextReader   nodeReader = null;
            SobekCM_SiteMap siteMap    = null;
            int             nodeValue  = 1;

            Stack <SobekCM_SiteMap_Node> nodesStack = new Stack <SobekCM_SiteMap_Node>();

            try
            {
                // Create and open the readonly file stream
                reader = new FileStream(SiteMap_File, FileMode.Open, FileAccess.Read);

                // create the XML node reader
                nodeReader = new XmlTextReader(reader);

                // Read through the XML document
                while (nodeReader.Read())
                {
                    if (nodeReader.NodeType == XmlNodeType.Element)
                    {
                        // Handle the main sitemap tag
                        if (nodeReader.Name == "siteMap")
                        {
                            // This is the first node read, so it may have additional information
                            siteMap = new SobekCM_SiteMap();

                            // Look for the optional default breadcrumbs attribute
                            if (nodeReader.MoveToAttribute("default_breadcrumb"))
                            {
                                siteMap.Default_Breadcrumb = nodeReader.Value;
                            }

                            // Look for the optional width attribute
                            if (nodeReader.MoveToAttribute("width"))
                            {
                                short width;
                                Int16.TryParse(nodeReader.Value, out width);
                                siteMap.Width = width;
                            }

                            // Look for the optional url restriction attribute
                            if (nodeReader.MoveToAttribute("restrictedRobotUrl"))
                            {
                                siteMap.Restricted_Robot_URL = nodeReader.Value;
                            }
                        }

                        // Handle a new siteMapNode
                        if (nodeReader.Name == "siteMapNode")
                        {
                            string url         = String.Empty;
                            string title       = String.Empty;
                            string description = String.Empty;
                            bool   empty       = false;

                            // Before moving to any attributes, check to see if this is empty
                            if (nodeReader.IsEmptyElement)
                            {
                                empty = true;
                            }

                            // Step through the attributes
                            while (nodeReader.MoveToNextAttribute())
                            {
                                switch (nodeReader.Name)
                                {
                                case "url":
                                    url = nodeReader.Value;
                                    break;

                                case "title":
                                    title = nodeReader.Value;
                                    break;

                                case "description":
                                    description = nodeReader.Value;
                                    break;
                                }
                            }

                            // Create the new node
                            SobekCM_SiteMap_Node newNode = new SobekCM_SiteMap_Node(url, title, description, nodeValue++);

                            // Add to the parent
                            if (nodesStack.Count == 0)
                            {
                                // This is the first node read so it should be the root node
                                if (siteMap != null)
                                {
                                    siteMap.RootNodes.Add(newNode);
                                }
                            }
                            else
                            {
                                nodesStack.Peek().Add_Child_Node(newNode);
                            }

                            // Add this to the stack, at least until the end of this node is found
                            // if this is not an empty element
                            if (!empty)
                            {
                                nodesStack.Push(newNode);
                            }
                        }
                    }
                    else if ((nodeReader.NodeType == XmlNodeType.EndElement) && (nodeReader.Name == "siteMapNode"))
                    {
                        nodesStack.Pop();
                    }
                }
            }
            finally
            {
                if (nodeReader != null)
                {
                    nodeReader.Close();
                }
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(siteMap);
        }