Exemple #1
0
        private SobekCM_SiteMap_Node find_node_by_value(SobekCM_SiteMap_Node Node, int NodeValue)
        {
            // If this is the matching node, return it
            if (Node.NodeValue == NodeValue)
            {
                return(Node);
            }

            // If no children or first child is already invalid, return NULL
            if ((Node.Child_Nodes_Count == 0) || (Node.Child_Nodes[0].NodeValue > NodeValue))
            {
                return(null);
            }

            // Look through the children nodes
            int nodeNumber = 0;
            ReadOnlyCollection <SobekCM_SiteMap_Node> childNodes = Node.Child_Nodes;

            while (nodeNumber < (Node.Child_Nodes_Count - 1))
            {
                // Is the NEXT child node value too great, then it would be in THIS node's child tree
                if (childNodes[nodeNumber + 1].NodeValue > NodeValue)
                {
                    return(find_node_by_value(childNodes[nodeNumber], NodeValue));
                }
                nodeNumber++;
            }

            // Must still be in the last child node tree, the VERY LAST node
            return(find_node_by_value(childNodes[childNodes.Count - 1], NodeValue));
        }
        /// <summary> Add a child node to this node </summary>
        /// <param name="Child_URL">Relative URL for the child node within a hierarchical site map</param>
        /// <param name="Child_Title">Title for the child node within a hierarchical site map, displayed in the
        /// navigation tree </param>
        /// <param name="Child_Description">Description for the child node within a hierarchical site map, used for
        /// a tooltip when hovering over this node in the navigation tree</param>
        /// <param name="Child_NodeValue"> Unique node value used to select this node from the site map during callbacks due to using the left navigational tree structure </param>
        /// <returns> Fully built SobekCM_SiteMap_Node child object </returns>
        public SobekCM_SiteMap_Node Add_Child_Node(string Child_URL, string Child_Title, string Child_Description, int Child_NodeValue)
        {
            SobekCM_SiteMap_Node newNode = new SobekCM_SiteMap_Node(Child_URL, Child_Title, Child_Description, Child_NodeValue);

            Add_Child_Node(newNode);
            newNode.Parent_Node = this;
            return(newNode);
        }
        /// <summary> Add a child node to this node </summary>
        /// <param name="Child_Node"> Child node to add </param>
        public void Add_Child_Node(SobekCM_SiteMap_Node Child_Node)
        {
            if (childNodes == null)
            {
                childNodes = new List <SobekCM_SiteMap_Node>();
            }

            childNodes.Add(Child_Node);
            Child_Node.Parent_Node = this;
        }
Exemple #4
0
        private int recurse_selected_nodevalue_find(SobekCM_SiteMap_Node Node, string Current_URL)
        {
            if (Node.URL == Current_URL)
            {
                return(Node.NodeValue);
            }

            if (Node.Child_Nodes_Count > 0)
            {
                foreach (int returnValue in Node.Child_Nodes.Select(childNode => recurse_selected_nodevalue_find(childNode, Current_URL)).Where(returnValue => returnValue > 0))
                {
                    return(returnValue);
                }
            }

            return(-1);
        }
 /// <summary> Add a child node to this node </summary>
 /// <param name="Child_URL">Relative URL for the child node within a hierarchical site map</param>
 /// <param name="Child_Title">Title for the child node within a hierarchical site map, displayed in the
 /// navigation tree </param>
 /// <param name="Child_Description">Description for the child node within a hierarchical site map, used for 
 /// a tooltip when hovering over this node in the navigation tree</param>
 /// <param name="Child_NodeValue"> Unique node value used to select this node from the site map during callbacks due to using the left navigational tree structure </param>
 /// <returns> Fully built SobekCM_SiteMap_Node child object </returns>
 public SobekCM_SiteMap_Node Add_Child_Node(string Child_URL, string Child_Title, string Child_Description, int Child_NodeValue )
 {
     SobekCM_SiteMap_Node newNode = new SobekCM_SiteMap_Node(Child_URL, Child_Title, Child_Description, Child_NodeValue);
     Add_Child_Node(newNode);
     newNode.Parent_Node = this;
     return newNode;
 }
        /// <summary> Add a child node to this node </summary>
        /// <param name="Child_Node"> Child node to add </param>
        public void Add_Child_Node(SobekCM_SiteMap_Node Child_Node)
        {
            if (childNodes == null)
                childNodes = new List<SobekCM_SiteMap_Node>();

            childNodes.Add(Child_Node);
            Child_Node.Parent_Node = this;
        }
        private void recursively_draw_sitemap_for_robots(TextWriter Output, SobekCM_SiteMap_Node Node, string Indent)
        {
            // Add this text
            if ((Node.URL.Length > 0) && (Node.URL != RequestSpecificValues.Current_Mode.Info_Browse_Mode))
            {
                Output.WriteLine(Indent + "<a href='" + RequestSpecificValues.Current_Mode.Base_URL + Node.URL + "' title='" + Node.Description + "'>" + Node.Title + "</a><br />");
            }
            else
            {
                Output.WriteLine(Indent + "<span Title='" + Node.Description + "' class='sbkWchs_SiteMapNoLink' >" + Node.Title + "</span><br />");
            }

            // Add all the children
            if (Node.Child_Nodes_Count > 0)
            {
                foreach (SobekCM_SiteMap_Node childNode in Node.Child_Nodes)
                {
                    recursively_draw_sitemap_for_robots(Output, childNode, Indent + " &nbsp; &nbsp; &nbsp; ");
                }
            }
        }
        private void add_child_nodes(TreeNode treeNode, SobekCM_SiteMap_Node siteNode, string base_url, int selected_node )
        {
            // Only do anything if there are child nodes defined
            if (siteNode.Child_Nodes_Count > 0)
            {
                // Step through each child node
                ReadOnlyCollection<SobekCM_SiteMap_Node> childNodes = siteNode.Child_Nodes;
                int child_node_counter = 0;
                while ( child_node_counter < childNodes.Count )
                {
                    // Get this child node
                    SobekCM_SiteMap_Node childNode = childNodes[child_node_counter];

                    // Add this child node to the tree view
                    TreeNode childTreeNode = new TreeNode
                                                 {
                                                     SelectAction = TreeNodeSelectAction.None,
                                                     Value = childNode.NodeValue.ToString()
                                                 };

                    if (childNode.URL.Length > 0)
                    {
                        childTreeNode.Text = string.Format("<a href='{0}' title='{1}'>{2}</a>", base_url + childNode.URL, childNode.Description, childNode.Title);
                    }
                    else
                    {
                        childTreeNode.Text = string.Format("<span Title='{0}' class='SobekSiteMapNoLink' >{1}</span>", childNode.Description, childNode.Title);
                        childTreeNode.SelectAction = TreeNodeSelectAction.Expand;
                    }
                    treeNode.ChildNodes.Add(childTreeNode);

                    if (childNode.Child_Nodes_Count > 0)
                    {
                        // Determine if the selected node is in the child nodes...
                        if ((childNode.NodeValue < selected_node) && ((child_node_counter + 1 == childNodes.Count) || (childNodes[child_node_counter + 1].NodeValue > selected_node)))
                        {
                            // Recurse through any children
                            add_child_nodes(childTreeNode, childNode, base_url, selected_node);
                        }
                        else
                        {
                            childTreeNode.PopulateOnDemand = true;
                        }
                    }

                    // Was this node currently selected?
                    if (childNode.NodeValue == selected_node )
                    {
                        childTreeNode.Text = string.Format("<span Title='{0}'>{1}</span>", childNode.Description, childNode.Title);
                        childTreeNode.Expand();

                        // Create the breadcrumbs now
                        StringBuilder breadcrumbBuilder = new StringBuilder();
                        breadcrumbBuilder.Append(childTreeNode.Text);

                        // Add each parent next, if they have a URL and also expand each parent
                        TreeNode selectedNodeExpander = childTreeNode;
                        while (selectedNodeExpander.Parent != null)
                        {
                            // expand this node
                            (selectedNodeExpander.Parent).Expand();

                            // add to breadcrumb, if a link
                            if (selectedNodeExpander.Parent.SelectAction == TreeNodeSelectAction.None)
                            {
                                string text = selectedNodeExpander.Parent.Text.Replace(" Namespace</a>","</a>").Replace(" Sub-Namespace</a>","</a>");

                                breadcrumbBuilder.Insert(0, text + " <img src=\"" + RequestSpecificValues.Current_Mode.Base_URL + "design/skins/" + RequestSpecificValues.Current_Mode.Base_Skin_Or_Skin + "/breadcrumbimg.gif\" alt=\">\" /><img src=\"" + RequestSpecificValues.Current_Mode.Base_URL + "design/skins/" + RequestSpecificValues.Current_Mode.Base_Skin_Or_Skin + "/breadcrumbimg.gif\" alt=\">\" /> ");
                            }

                            // step up another level
                            selectedNodeExpander = selectedNodeExpander.Parent;
                        }
                        breadcrumbs = breadcrumbBuilder.ToString();
                    }

                    child_node_counter++;
                }
            }
        }
        private int recurse_selected_nodevalue_find(SobekCM_SiteMap_Node Node, string Current_URL)
        {
            if (Node.URL == Current_URL)
                return Node.NodeValue;

            if (Node.Child_Nodes_Count > 0)
            {
                foreach (int returnValue in Node.Child_Nodes.Select(childNode => recurse_selected_nodevalue_find(childNode, Current_URL)).Where(returnValue => returnValue > 0))
                {
                    return returnValue;
                }
            }

            return -1;
        }
        private SobekCM_SiteMap_Node find_node_by_value(SobekCM_SiteMap_Node Node, int NodeValue)
        {
            // If this is the matching node, return it
            if (Node.NodeValue == NodeValue)
                return Node;

            // If no children or first child is already invalid, return NULL
            if ((Node.Child_Nodes_Count == 0) || ( Node.Child_Nodes[0].NodeValue > NodeValue ))
                return null;

            // Look through the children nodes
            int nodeNumber = 0;
            ReadOnlyCollection<SobekCM_SiteMap_Node> childNodes = Node.Child_Nodes;
            while (nodeNumber < ( Node.Child_Nodes_Count - 1 ))
            {
                // Is the NEXT child node value too great, then it would be in THIS node's child tree
                if (childNodes[nodeNumber + 1].NodeValue > NodeValue)
                {
                    return find_node_by_value(childNodes[nodeNumber], NodeValue);
                }
                nodeNumber++;
            }

            // Must still be in the last child node tree, the VERY LAST node
            return find_node_by_value(childNodes[childNodes.Count - 1], NodeValue);
        }
        /// <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;
        }