/// <summary>
        /// Converts a UfDataNode structure into a very basic form HTML.
        /// </summary>
        /// <param name="node">Node</param>
        /// <param name="formatDescriber">Microformat format describer object</param>
        /// <returns>HTML string</returns>
        public string Convert(UfDataNode node, UfFormatDescriber formatDescriber)
        {
            string output = string.Empty;

            StringWriter       stringWriter     = new StringWriter();
            UfElementDescriber elementDescriber = formatDescriber.BaseElement;

            using (XhtmlTextWriter writer = new XhtmlTextWriter(stringWriter))
            {
                writer.WriteBeginTag("div");
                writer.WriteAttribute("class", "microformats");
                writer.Write(HtmlTextWriter.TagRightChar);

                foreach (UfDataNode child in node.Nodes)
                {
                    writer.WriteLine();
                    AddNode(child, elementDescriber, writer);
                }

                writer.WriteEndTag("div");
                writer.WriteLine();
            }

            return(stringWriter.ToString());
        }
Пример #2
0
        public Stream RenderPageEnd()
        {
            XhtmlTextWriter xhtmlWriter = new XhtmlTextWriter(Writer);

            xhtmlWriter.Indent = 3;

            // Flush writer contents to output.
            xhtmlWriter.Flush();

            if (ReportFooter != null && ReportFooter.Length > 0)
            {
                xhtmlWriter.RenderBeginTag("hr");
                xhtmlWriter.WriteEndTag("hr");

                //
                xhtmlWriter.AddAttribute("class", "footer");
                xhtmlWriter.RenderBeginTag("div");

                xhtmlWriter.Write(ReportFooter);
                xhtmlWriter.WriteEndTag("div");

                xhtmlWriter.RenderBeginTag("hr");
                xhtmlWriter.WriteEndTag("hr");

                xhtmlWriter.WriteLine(Writer.NewLine);
                // </h2>
            }
            //--------------------------------------------------------
            // No matter what state the Renderer left us in, close
            // off the <body> and <html> elements.
            //--------------------------------------------------------

            // </body>
            xhtmlWriter.WriteEndTag("body");

            // </html>
            xhtmlWriter.WriteEndTag("html");

            // Flush writer contents to output.
            xhtmlWriter.Flush();

            return(Writer.BaseStream);
        }
Пример #3
0
        public virtual Stream Render(IDataSource dataSource)
        {
            XhtmlTextWriter xhtmlWriter = new XhtmlTextWriter(_writer);

            // <div class='core'>
            xhtmlWriter.AddAttribute("class", "core");
            xhtmlWriter.RenderBeginTag("div");
            xhtmlWriter.WriteLine(Writer.NewLine);


            //-----------------------------------------------------------------
            // If the 'Renderer' supports the ITextControl interface, we will
            // defer rendering of the 'Text' block to it. The assignment needs
            // to take place before 'DataBind' so the 'Renderer' can act
            // on the Text. (Maybe a token substitution will happen, perhaps!)
            //-----------------------------------------------------------------
            ITextControl _textControl = Renderer as ITextControl;

            if (_textControl != null)
            {
                _textControl.Text = Text;
            }

            // Bind the Data to the Renderer
            if (dataSource != null)
            {
                Renderer.DataSource = dataSource;
                Renderer.DataBind();
            }

            xhtmlWriter.Flush();

            // Render unto the Stream that which belongs to the Stream...
            Renderer.ID = ID;
            Renderer.RenderControl(xhtmlWriter);

            // </div>
            xhtmlWriter.WriteEndTag("div");

            xhtmlWriter.Flush();

            return(_writer.BaseStream);
        }
        private void AddNode(UfDataNode node, UfElementDescriber elementDescriber, XhtmlTextWriter writer)
        {
            if (node.Name != string.Empty)
            {
                indentNum++;
                writer.Indent = indentNum;

                UfElementDescriber currentDescriber = elementDescriber;
                foreach (UfElementDescriber childElementDescriber in elementDescriber.Elements)
                {
                    if (node.Name == childElementDescriber.Name || node.Name == childElementDescriber.CompoundName)
                    {
                        currentDescriber = childElementDescriber;
                    }
                }

                if (currentDescriber.Attribute == "class")
                {
                    writer.WriteBeginTag("div");
                    if (currentDescriber.CompoundName == "")
                    {
                        writer.WriteAttribute("class", node.Name);
                    }
                    else
                    {
                        writer.WriteAttribute("class", node.Name + " " + currentDescriber.Name);
                    }

                    if (!string.IsNullOrEmpty(node.ElementId))
                    {
                        writer.WriteAttribute("id", node.ElementId);
                    }

                    writer.Write(HtmlTextWriter.TagRightChar);
                    writer.WriteEncodedText(node.Value);


                    foreach (UfDataNode child in node.Nodes)
                    {
                        writer.WriteLine();
                        AddNode(child, currentDescriber, writer);
                    }


                    if (node.Name != string.Empty)
                    {
                        writer.WriteEndTag("div");
                        writer.WriteLine();
                    }
                }

                if (currentDescriber.Attribute == "rel")
                {
                    writer.WriteBeginTag("a");
                    writer.WriteAttribute("href", node.DescendantValue("link"));
                    writer.WriteAttribute("rel", node.Name);
                    writer.Write(HtmlTextWriter.TagRightChar);

                    writer.WriteEncodedText(node.DescendantValue("text"));
                    writer.WriteEndTag("a");
                    writer.WriteLine();
                }

                indentNum--;
                writer.Indent = indentNum;
            }
        }
Пример #5
0
        /// <summary>
        /// Visit XHTMLElement and write it to stream
        /// </summary>
        /// <param name="element">Element to visit</param>
        public void Visit(XHTMLElement element)
        {
            if (element.GetTag() == "cdata")
            {   //CData need different handling
                WriteCData(element);
            }
            else if (element.GetTag() == "comment")
            {   //Write comment
                WriteComment(element);
            }
            else
            {   //Normal XHTML tag handling
                XhtmlWriter.BeginRender();

                //Check if element is tag, if not write tag, otherwise handle as XHTML tag
                if (!element.GetTagState())
                {
                    XhtmlWriter.BeginRender();

                    //Get escape chars out of this tag
                    CharIterator charIterator = new CharIterator();
                    String       tag          = charIterator.ParseText(element.GetTag());
                    XhtmlWriter.Write(tag);
                    XhtmlWriter.EndRender();
                    XhtmlWriter.Flush();
                    return;
                }

                XhtmlWriter.WriteBeginTag(element.GetTag());
                foreach (KeyValuePair <String, String> pair in element.GetAttributes())
                {
                    XhtmlWriter.WriteAttribute(pair.Key, pair.Value, false);
                }

                if (IsEmptyElement(element))
                {   //Nothing inside element, so write tag end
                    XhtmlWriter.Write(XhtmlTextWriter.SelfClosingTagEnd);
                }
                else if (IsXHTMLTag(element.GetTag()))
                {
                    //Write tag opening closing
                    XhtmlWriter.Write(XhtmlTextWriter.TagRightChar);

                    //Write content
                    XhtmlWriter.Write(element.GetContent());

                    //Visit children
                    foreach (XHTMLElement child in element.GetChildren())
                    {
                        Visit(child);
                    }

                    //Write closing tag
                    XhtmlWriter.WriteEndTag(element.GetTag());
                    XhtmlWriter.Flush();
                }
                else
                {
                    //Just write it
                    XhtmlWriter.Write(element.GetTag());
                    XhtmlWriter.EndRender();
                    XhtmlWriter.Flush();
                }
            }
        }
Пример #6
0
        public Stream RenderPageBegin()
        {
            XhtmlTextWriter xhtmlWriter = new XhtmlTextWriter(Writer);

            xhtmlWriter.Indent = 3;

            xhtmlWriter.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml");
            xhtmlWriter.RenderBeginTag("html");

            xhtmlWriter.RenderBeginTag("head");
            if (ReportHeading != null && ReportHeading.Length > 0)
            {
                xhtmlWriter.RenderBeginTag("title");
                xhtmlWriter.Write(ReportHeading);
                xhtmlWriter.WriteEndTag("title");
            }

            // <style type='text/css'>
            xhtmlWriter.WriteLine(Writer.NewLine);
            xhtmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
            xhtmlWriter.RenderBeginTag("style");
            foreach (var style in _styles)
            {
                xhtmlWriter.WriteLine(style.Key);
                xhtmlWriter.WriteLine("{");
                xhtmlWriter.WriteLine(style.Value);
                xhtmlWriter.WriteLine("}");
            }
            xhtmlWriter.WriteEndTag("style");
            xhtmlWriter.WriteLine(Writer.NewLine);
            // </style>

            xhtmlWriter.WriteEndTag("head");

            // <body>
            xhtmlWriter.RenderBeginTag("body");

            if (ReportHeading != null && ReportHeading.Length > 0)
            {
                // <h2 class='heading'>
                xhtmlWriter.AddAttribute("class", "heading");
                xhtmlWriter.RenderBeginTag("h2");
                xhtmlWriter.Write(ReportHeading);
                xhtmlWriter.WriteEndTag("h2");
                xhtmlWriter.WriteLine(Writer.NewLine);
                // </h2>
            }

            if (!(Renderer is ITextControl) && Text != null && Text.Length > 0)
            {
                // <p class='text'>
                xhtmlWriter.AddAttribute("class", "caption");
                xhtmlWriter.RenderBeginTag("p");
                xhtmlWriter.Write(Text);
                xhtmlWriter.WriteEndTag("p");
                xhtmlWriter.WriteLine(Writer.NewLine);
                // </p>
            }

            // Flush writer contents to output.
            xhtmlWriter.Flush();

            return(Writer.BaseStream);
        }