/// <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();
        }
Beispiel #2
0
        protected override void Render(HtmlTextWriter writer)
        {
            //base.Render(writer);

            if (this.Page == null)
            {
                return;
            }

            if (!(this.Page is BasePage))
            {
                return;
            }

            BasePage bpage = this.Page as BasePage;

            if (bpage.IsGuideOn)
            {
                int __currentStep = bpage.GuideCurrentStep;
                if (__currentStep < 1)
                {
                    return;
                }

                //{0} ��ǰ������(1-5)
                //{1} ��ǰ��������
                //{2} ��ǰ��������
                //{3} ǰһ��class
                //{4} ��һ��class
                string temp = SupplierCenterTemplates.GetTemplate("BBT_GUIDE");

                string content=String.Format(temp,
                    __currentStep.ToString(),
                    GetCurrentStepName(__currentStep),
                    GetCurrentStepDesc(__currentStep),
                    GetPreBtnClass(__currentStep),
                    GetNextBtnClass(__currentStep)
                );
                using (XhtmlTextWriter xWrite = new XhtmlTextWriter(writer))
                {
                    xWrite.Write(content);
                }
            }
        }
        public bool Render(object o, string description, int depth, XhtmlTextWriter writer)
        {
            //there are two principal ways of rendering an object,
            // if it's an enumerable we render each object as a row in a table
            // if it's jut an object we render each property of the object as a row in a table

            if(!String.IsNullOrWhiteSpace(description))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.H3);
                writer.Write(description);
                writer.RenderEndTag();
                writer.WriteLine();
            }

            if (depth <= 0)
                return true;

            if (o is IEnumerable && !(o is String))
                return RenderEnumerable((IEnumerable)o, depth, writer);
            else
                return RenderObject(o, depth, writer);
        }
        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;

            }
        }
        private void LoopItems(DictionaryItem item, XhtmlTextWriter writer)
        {
            switch (htmlTagName.ToLower().Trim())
            {
                case "select":
                    writer.WriteBeginTag("option");
                    writer.WriteAttribute("value", item.Key);
                    if (IsSelected(item.Key))
                    {
                        writer.WriteAttribute("selected", "selected");
                    }
                    writer.Write(HtmlTextWriter.TagRightChar);
                    int d = item.Depth;
                    if (!String.IsNullOrEmpty(parentId))
                    {
                        d -= parentId.Length / (provider == "category" ? Categories.Category.CATEGORY_LEVEL_LENGTH : DictionaryItem.KEY_LEVEL_LENGTH);
                    }
                    string text = BrandQQ.LeadLib.Utils.Util.RepeatString(identChar, (ushort)d);
                    if (d > 0)
                    {
                        text += prefixChar;
                    }

                    writer.Write(text + item.Value);
                    writer.WriteEndTag("option");
                    break;

                case "ul":
                    writer.WriteBeginTag("li");
                    writer.WriteAttribute("id", "LI_" + this.ClientID + "_" + item.Key);
                    writer.Write(HtmlTextWriter.TagRightChar);

                    if (!String.IsNullOrEmpty(checkBoxOrRadio))//����ѡ��
                    {
                        writer.WriteBeginTag("input");
                        writer.WriteAttribute("type", checkBoxOrRadio);
                        writer.WriteAttribute("id", this.ClientID + "_" + item.Key);
                        if (String.IsNullOrEmpty(htmlControlName))
                        {
                            writer.WriteAttribute("name", this.ClientID);
                        }
                        else
                        {
                            writer.WriteAttribute("name", htmlControlName);
                        }
                        writer.WriteAttribute("value", item.Key);
                        if (IsSelected(item.Key))
                        {
                            writer.WriteAttribute("checked", "checked");
                        }
                        writer.Write(HtmlTextWriter.SelfClosingTagEnd);
                        writer.WriteBeginTag("label");
                        writer.WriteAttribute("for", this.ClientID + "_" + item.Key);
                        writer.Write(HtmlTextWriter.TagRightChar);
                        writer.Write(item.Value);
                        writer.WriteEndTag("label");
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(linkFormat))
                        {
                            writer.Write(String.Format(linkFormat, item.Key, item.Value));
                        }
                        else
                        {
                            writer.Write(item.Value);
                        }
                    }

                    writer.WriteEndTag("li");
                    break;
            }

            if (item.Children.Count > 0 && htmlTagName.ToLower().Trim() == "ul")
            {
                writer.WriteFullBeginTag("ul");
            }

            foreach (DictionaryItem subItem in item.Children)
            {
                LoopItems(subItem, writer);
            }

            if (item.Children.Count > 0 && htmlTagName.ToLower().Trim() == "ul")
            {
                writer.WriteEndTag("ul");
            }
        }
        protected override void Render(HtmlTextWriter writer)
        {
            ArrayList list=null;
            switch (provider.ToLower())
            {
                case "industry":
                    list = Dictionary.Industries;
                    break;
                case "category":
                    list = Dictionary.Categories;
                    break;
                case "area":
                    list = Dictionary.Areas;
                    break;
                case "libclass":
                    list = Dictionary.LibClasses;
                    break;
                case "companynature":
                    list = Dictionary.CompanyNatures;
                    break;
                case "tags":
                    foreach (string tag in Tag.GetTags())
                    {
                        writer.WriteFullBeginTag("span");
                        writer.Write(tag);
                        writer.WriteEndTag("span");
                    }
                    return;
            }

            if (list == null)
            {
                return;
            }

            XhtmlTextWriter xWrite = new XhtmlTextWriter(writer);
            switch (htmlTagName.ToLower().Trim())
            {
                case "select":
                    xWrite.WriteBeginTag("select");
                    xWrite.WriteAttribute("id", this.ClientID);
                    if (String.IsNullOrEmpty(htmlControlName))
                    {
                        xWrite.WriteAttribute("name", this.ClientID);
                    }
                    else
                    {
                        xWrite.WriteAttribute("name", htmlControlName);
                    }
                    if (!String.IsNullOrEmpty(this.CssClass))
                    {
                        xWrite.WriteAttribute("class", this.CssClass);
                    }
                    xWrite.Write(HtmlTextWriter.TagRightChar);

                    if (!String.IsNullOrEmpty(defaultOptText))
                    {
                        writer.WriteBeginTag("option");
                        writer.WriteAttribute("value", defaultOptValue);
                        writer.Write(HtmlTextWriter.TagRightChar);
                        writer.Write(defaultOptText);
                        writer.WriteEndTag("option");
                    }

                    foreach (DictionaryItem item in list)
                    {
                        LoopItems(item, xWrite);
                    }
                    xWrite.WriteEndTag("select");
                    break;

                case "ul":
                    xWrite.WriteBeginTag("ul");
                    writer.WriteAttribute("id", "UL_" + this.ClientID);
                    if (!String.IsNullOrEmpty(this.CssClass))
                    {
                        xWrite.WriteAttribute("class", this.CssClass);
                    }
                    xWrite.Write(HtmlTextWriter.TagRightChar);
                    foreach (DictionaryItem item in list)
                    {
                        LoopItems(item, xWrite);
                    }
                    xWrite.WriteEndTag("ul");
                    break;
            }
        }
        public bool RenderEnumerable(IEnumerable enumerable, int depth, XhtmlTextWriter writer)
        {
            var elementType = GetElementTypeOfEnumerable(enumerable);
            if (elementType == null)
                return false;

            //get the members (fields and properties)
            var members = GetMembers(elementType);

            //write the headers and start the table
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            //if the element type is an element that needs to be rendered atomically we use a different method
            if(IsSimpleType(elementType))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Th);
                writer.Write(elementType.Name);
                writer.RenderEndTag();
                writer.RenderEndTag();

                foreach (var element in enumerable)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write(element.ToString());
                    writer.RenderEndTag();
                    writer.RenderEndTag();
                }
            }
            else
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                foreach (var member in members)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Th);
                    writer.Write(member.Name);
                    writer.RenderEndTag();
                }
                writer.RenderEndTag(); //tr
                writer.WriteLine();

                //write all the members
                foreach (var element in enumerable)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    foreach (var member in members)
                    {
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);
                        RenderMember(member, element, depth, writer);
                        writer.RenderEndTag(); //td
                    }
                    writer.RenderEndTag(); //tr
                    writer.WriteLine();
                }
            }

            //end the table
            writer.RenderEndTag();

            writer.WriteLine();
            return true;
        }
        private void RenderMember(MemberInfo memberInfo, object o, int depth, XhtmlTextWriter writer)
        {
            //try to get the value
            object value = null;
            try
            {
                value = GetValue(memberInfo, o);
            }
            catch (Exception ex)
            {
                value = "Error getting member value: " + ex.Message;
            }

            if(value == null)
            {
                writer.Write("null");
                return;
            }

            var valueType = GetValueType(memberInfo);
            if (valueType == null)
            {
                writer.Write("Error getting member type.");
            }
            else if (valueType == typeof(double) ||
                valueType == typeof(decimal) ||
                valueType == typeof(float))
            {
                //if the property seems to contain percent data we format it appropriately
                if (memberInfo.Name.ToLower().Contains("percent") || memberInfo.Name.ToLower().Contains("prc"))
                    writer.Write("{0:0.00%}", value);
                else
                    writer.Write("{0:0.00}", value);
            }
            else if (valueType == typeof(DateTime) ||
                valueType == typeof(DateTimeOffset))
            {
                //todo: optional date time formatting
                writer.Write(value);
            }
            else if (IsSimpleType(valueType))
            {
                writer.Write(value);
            }
            else
            {
                //recurively call the render method to descend one level in the object tree
                Render(value, null, depth - 1, writer);
            }
        }
        public bool RenderObject(object o, int depth, XhtmlTextWriter writer)
        {
            var objectType = o.GetType();

            if(IsSimpleType(objectType))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.Write(o.ToString());
                writer.RenderEndTag();

                writer.WriteLine();
                return true;
            }

            //get the members (fields and properties)
            var members = GetMembers(objectType);

            //create a two column table containing member and then value
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            //write a header containing the class name
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
            writer.RenderBeginTag(HtmlTextWriterTag.Th);
            writer.Write(objectType.Name);
            writer.RenderEndTag(); //th
            writer.RenderEndTag(); //tr

            foreach (var member in members)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "left");
                writer.RenderBeginTag(HtmlTextWriterTag.Th);
                writer.Write(member.Name);
                writer.RenderEndTag(); //th

                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                RenderMember(member, o, depth, writer);
                writer.RenderEndTag(); //td
                writer.RenderEndTag(); //tr
            }

            writer.RenderEndTag(); //table

            writer.WriteLine();
            return true;
        }
Beispiel #10
0
        private void Reformat()
        {
            //
            // Write out the HTML document lead.
            //

            StringWriter sw = new StringWriter();
            XhtmlTextWriter htmlWriter = new XhtmlTextWriter(sw, "  ");
            htmlWriter.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
            htmlWriter.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml");
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Html);
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Head);
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Title);
            htmlWriter.WriteEncodedText(Path.GetFileNameWithoutExtension(Mask.EmptyString(DocumentPath, _defaultFileName)));
            htmlWriter.RenderEndTag();
            htmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Style);
            htmlWriter.Write(@"a:link{ color:#00c}
              body{ background:#fff;  font-size:83%;  font-family:arial,sans-serif}
              td, th{ font-size:100%}
              td{ border:solid 1px #aaa;  padding:5px}
              table{ border-collapse:separate}
              h1{ font-size:x-large;  margin-top:0px}
              h2{ font-size:large}
              h3{ font-size:medium}
              h4{ font-size:small}
              img{ border:0}
              pre{ margin-left:2em;  padding:0.5em;  border-left:3px solid #ccc}");
            htmlWriter.RenderEndTag(/* style */);
            htmlWriter.RenderEndTag(/* head */);
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Body);

            //
            // Format the wiki into the HTML body.
            //

            new HtmlFormatter().Format(new WikiParser().Parse(new StringReader(_wikiBox.Text)), htmlWriter);

            //
            // Conclude the HTML document.
            //

            htmlWriter.RenderEndTag(/* body */);
            htmlWriter.RenderEndTag(/* html */);

            string html = sw.GetStringBuilder().ToString().Replace("\r", string.Empty);

            //
            // Update the WebBrowser with the HTML preview.
            //

            _webBrowser.AllowNavigation = true;
            _webBrowser.DocumentText = html;

            //
            // Update the RichTextBox with the HTML source and highlight
            // the markup.
            //

            _htmlBox.Clear();
            _htmlBox.Text = html;
            HighlightMarkup(_htmlBox);

            //
            // The preview is now up to date with the wiki changes.
            //

            _wikiChanged = false;
        }