Ejemplo n.º 1
0
        /// <summary>
        /// Render out the bullet list (ul , li)
        /// </summary>
        /// <param name="writer">Html Text Writer</param>
        /// <param name="nodes">SiteMapNodeCollection to traverse</param>
        /// <param name="depthTravelled">How far down the nodes to go</param>
        private void RenderSiteMapLevelAsBulletedList(HtmlTextWriter writer, SiteMapNodeCollection nodes, int depthTravelled)
        {
            depthTravelled++;

            foreach (SiteMapNode node in nodes)
            {
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["skipBlog"], CultureInfo.CurrentCulture) && node.Title == ConfigurationManager.AppSettings["blogNodeTitle"].ToString())
                {
                    continue;
                }

                if (node == this.DataSource.Provider.CurrentNode)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "currentNode");
                }

                writer.RenderBeginTag(HtmlTextWriterTag.Li);

                if (node.Url != null && node.Url.Length > 0)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, CrossReferencesControl.StripCrossRefMarkerOff(node.Url));
                    writer.AddAttribute(HtmlTextWriterAttribute.Title, string.Format(CultureInfo.CurrentCulture, SiteMapListControl.SiteMapAnchorTitlePrefix, node.Description));
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.WriteEncodedText(node.Title);
                    writer.RenderEndTag(); // close anchor
                }
                else
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);
                    writer.WriteEncodedText(node.Title);
                    writer.RenderEndTag(); // close span
                }

                // Add any children levels, if needed (recursively)
                if (node.HasChildNodes && (this.Depth == 0 || this.Depth > depthTravelled))
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Ul);

                    this.RenderSiteMapLevelAsBulletedList(writer, node.ChildNodes, depthTravelled);

                    writer.RenderEndTag();
                }

                writer.RenderEndTag();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Init time processing
        /// </summary>
        /// <param name="e">Event Argument.</param>
        protected override void OnInit(EventArgs e)
        {
            this.CrossReferencesTable.SiteMapNodes = CrossReferencesControl.GetSiteMapNodesForCrossReferences(this.SiteMapDS);

            base.OnInit(e);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Render out the cross referneces table
        /// </summary>
        /// <param name="writer">Html Text Writer</param>
        private void RenderTable(HtmlTextWriter writer)
        {
            List <SiteMapNode> crossReferenceCategories = new List <SiteMapNode>();
            List <SiteMapNode> crossReferences          = new List <SiteMapNode>();

            writer.AddAttribute("summary", string.Format(CultureInfo.CurrentCulture, CrossReferenceTableSummary, this.BuildCategoryText()));
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            writer.AddAttribute(HtmlTextWriterAttribute.Width, "50%");
            writer.RenderBeginTag(HtmlTextWriterTag.Col);
            writer.RenderEndTag();
            writer.AddAttribute(HtmlTextWriterAttribute.Width, "50%");
            writer.RenderBeginTag(HtmlTextWriterTag.Col);
            writer.RenderEndTag();

            // Write out the Cross References table header
            writer.RenderBeginTag(HtmlTextWriterTag.Thead);

            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

            foreach (SiteMapNode crossReferenceCategory in this.SiteMapNodes)
            {
                crossReferenceCategories.Add(crossReferenceCategory);

                writer.RenderBeginTag(HtmlTextWriterTag.Th);

                writer.WriteEncodedText(crossReferenceCategory.Title);

                writer.RenderEndTag();

                // Whilst iterating get all cross reference nodes into a single array
                foreach (SiteMapNode node in crossReferenceCategory.ChildNodes)
                {
                    crossReferences.Add(node);
                }
            }

            writer.RenderEndTag();

            writer.RenderEndTag();

            // THEAD rendered open a TBODY
            writer.RenderBeginTag(HtmlTextWriterTag.Tbody);

            ArrayList written        = new ArrayList(crossReferences.Count);
            bool      moreRowsNeeded = true;

            do
            {
                bool               moveToNextRow = false;
                bool[]             crossRefWrittenForCategory = new bool[crossReferenceCategories.Count];
                List <SiteMapNode> siteMapNodesForRow         = new List <SiteMapNode>();
                int crossReferenceIndex = 0;

                while (moveToNextRow == false && crossReferenceIndex < crossReferences.Count)
                {
                    // If the cross reference has not been written...
                    if (written.Contains(crossReferences[crossReferenceIndex].Title) == false)
                    {
                        // ... check that we have not already written one for that Category
                        // and if not write it out
                        SiteMapNode crossReference = crossReferences[crossReferenceIndex];

                        if (crossRefWrittenForCategory[crossReferenceCategories.IndexOf(crossReference.ParentNode)] == false)
                        {
                            siteMapNodesForRow.Add(crossReference);
                        }
                        else if (crossRefWrittenForCategory.Length == crossReferenceCategories.Count)
                        {
                            // We have written ONE entry for each of the categories.
                            // We only write a SINGLE entryu per row per category so time to move to next Row
                            moveToNextRow = true;
                        }

                        if (written.Count + siteMapNodesForRow.Count == crossReferences.Count)
                        {
                            moveToNextRow = true;
                        }
                    }

                    crossReferenceIndex++;
                }

                // If we have some SiteMapNodes for the row so render them
                if (siteMapNodesForRow.Count > 0)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                    // Write out all cross references for row
                    for (int cellIndex = 0; cellIndex < crossReferenceCategories.Count; cellIndex++)
                    {
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);

                        foreach (SiteMapNode node in siteMapNodesForRow)
                        {
                            if (node.ParentNode == crossReferenceCategories[cellIndex])
                            {
                                // Render out the title and description for the Cross Reference link. Rather than use whatever text
                                // is set in the Cross Reference SiteMapNode, always use that from the SiteMapNode
                                // that is being cross referenced i.e. the destination of the cross reference

                                // Get the destination node by looking up the cross reference's url minus its CrossRef marker
                                SiteMapNode crossReferenceDestinationNode = node.Provider.FindSiteMapNode(CrossReferencesControl.StripCrossRefMarkerOff(node.Url));

                                if (crossReferenceDestinationNode == null)
                                {
                                    throw new ApplicationException("Unable to find a cross-referenced item in the sitemap '" + node.Url + "'");
                                }

                                writer.AddAttribute(HtmlTextWriterAttribute.Href, CrossReferencesControl.StripCrossRefMarkerOff(node.Url));
                                writer.AddAttribute(HtmlTextWriterAttribute.Title, string.Format(CultureInfo.CurrentCulture, CrossReferencesControl.CrossReferenceAnchorTitlePrefix, crossReferenceDestinationNode.Description));
                                writer.RenderBeginTag(HtmlTextWriterTag.A);

                                writer.WriteEncodedText(crossReferenceDestinationNode.Title);

                                writer.RenderEndTag(); // close anchor

                                // Add the title of the node to the list of written nodes
                                written.Add(node.Title);

                                break;
                            }
                        }

                        writer.RenderEndTag(); // Close TD
                    }

                    writer.RenderEndTag(); // Close TR
                }

                // If we have written all the cross references no moreRowsNeeded
                if (written.Count == crossReferences.Count)
                {
                    moreRowsNeeded = false;
                }
            }while (moreRowsNeeded == true);

            writer.RenderEndTag(); // Closes TBODY

            writer.RenderEndTag(); // Close TABLE
        }