2006-02-12 Cesar Lopez Nataren <cnataren@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI / HtmlTextWriter.cs
index 6bf3c75cae003179594dfb1ce645315f6c0658fc..925d94316272c7803ff67a582489dcd67734cb72 100644 (file)
-/*     System.Web.UI\r
-*      Authors\r
-*              Leen Toelen (toelen@hotmail.com)\r
-*/\r
-\r
-using System;\r
-using System.IO;\r
-using System.Collections;\r
-using System.Web;\r
-using System.Web.UI;\r
-\r
-namespace System.Web.UI{\r
-\r
-public class HtmlTextWriter : System.IO.TextWriter {\r
-\r
-static HtmlTextWriter(){\r
-       HtmlTextWriter._tagKeyLookupTable = new Hashtable(97);\r
-       HtmlTextWriter._tagNameLookupArray = new TagInformation[97];\r
-       HtmlTextWriter.RegisterTag("", HtmlTextWriterTag.Unknown, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("a", HtmlTextWriterTag.A, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("acronym", HtmlTextWriterTag.Acronym, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("address", HtmlTextWriterTag.Address, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("area", HtmlTextWriterTag.Area, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("b", HtmlTextWriterTag.B, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("base", HtmlTextWriterTag.Base, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("basefont", HtmlTextWriterTag.Basefont, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("bdo", HtmlTextWriterTag.Bdo, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("bgsound", HtmlTextWriterTag.Bgsound, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("big", HtmlTextWriterTag.Big, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("blockquote", HtmlTextWriterTag.Blockquote, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("body", HtmlTextWriterTag.Body, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("br", HtmlTextWriterTag.Br, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("button", HtmlTextWriterTag.Button, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("caption", HtmlTextWriterTag.Caption, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("center", HtmlTextWriterTag.Center, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("cite", HtmlTextWriterTag.Cite, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("code", HtmlTextWriterTag.Code, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("col", HtmlTextWriterTag.Col, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("colgroup", HtmlTextWriterTag.Colgroup, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("del", HtmlTextWriterTag.Del, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("dd", HtmlTextWriterTag.Dd, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("dfn", HtmlTextWriterTag.Dfn, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("dir", HtmlTextWriterTag.Dir, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("div", HtmlTextWriterTag.Div, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("dl", HtmlTextWriterTag.Dl, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("dt", HtmlTextWriterTag.Dt, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("em", HtmlTextWriterTag.Em, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("embed", HtmlTextWriterTag.Embed, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("fieldset", HtmlTextWriterTag.Fieldset, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("font", HtmlTextWriterTag.Font, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("form", HtmlTextWriterTag.Form, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("frame", HtmlTextWriterTag.Frame, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("frameset", HtmlTextWriterTag.Frameset, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("h1", HtmlTextWriterTag.H1, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("h2", HtmlTextWriterTag.H2, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("h3", HtmlTextWriterTag.H3, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("h4", HtmlTextWriterTag.H4, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("h5", HtmlTextWriterTag.H5, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("h6", HtmlTextWriterTag.H6, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("head", HtmlTextWriterTag.Head, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("hr", HtmlTextWriterTag.Hr, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("html", HtmlTextWriterTag.Html, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("i", HtmlTextWriterTag.I, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("iframe", HtmlTextWriterTag.Iframe, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("img", HtmlTextWriterTag.Img, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("input", HtmlTextWriterTag.Input, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("ins", HtmlTextWriterTag.Ins, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("isindex", HtmlTextWriterTag.Isindex, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("kbd", HtmlTextWriterTag.Kbd, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("label", HtmlTextWriterTag.Label, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("legend", HtmlTextWriterTag.Legend, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("li", HtmlTextWriterTag.Li, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("link", HtmlTextWriterTag.Link, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("map", HtmlTextWriterTag.Map, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("marquee", HtmlTextWriterTag.Marquee, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("menu", HtmlTextWriterTag.Menu, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("meta", HtmlTextWriterTag.Meta, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("nobr", HtmlTextWriterTag.Nobr, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("noframes", HtmlTextWriterTag.Noframes, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("noscript", HtmlTextWriterTag.Noscript, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("object", HtmlTextWriterTag.Object, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("ol", HtmlTextWriterTag.Ol, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("option", HtmlTextWriterTag.Option, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("p", HtmlTextWriterTag.P, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("param", HtmlTextWriterTag.Param, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("pre", HtmlTextWriterTag.Pre, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("q", HtmlTextWriterTag.Q, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("rt", HtmlTextWriterTag.Rt, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("ruby", HtmlTextWriterTag.Ruby, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("s", HtmlTextWriterTag.S, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("samp", HtmlTextWriterTag.Samp, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("script", HtmlTextWriterTag.Script, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("select", HtmlTextWriterTag.Select, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("small", HtmlTextWriterTag.Small, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("span", HtmlTextWriterTag.Span, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("strike", HtmlTextWriterTag.Strike, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("strong", HtmlTextWriterTag.Strong, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("style", HtmlTextWriterTag.Style, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("sub", HtmlTextWriterTag.Sub, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("sup", HtmlTextWriterTag.Sup, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("table", HtmlTextWriterTag.Table, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("tbody", HtmlTextWriterTag.Tbody, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("td", HtmlTextWriterTag.Td, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("textarea", HtmlTextWriterTag.Textarea, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("tfoot", HtmlTextWriterTag.Tfoot, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("th", HtmlTextWriterTag.Th, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("thead", HtmlTextWriterTag.Thead, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("title", HtmlTextWriterTag.Title, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("tr", HtmlTextWriterTag.Tr, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("tt", HtmlTextWriterTag.Tt, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("u", HtmlTextWriterTag.U, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("ul", HtmlTextWriterTag.Ul, TagType.Other);\r
-       HtmlTextWriter.RegisterTag("var", HtmlTextWriterTag.Var, TagType.Inline);\r
-       HtmlTextWriter.RegisterTag("wbr", HtmlTextWriterTag.Wbr, TagType.NonClosing);\r
-       HtmlTextWriter.RegisterTag("xml", HtmlTextWriterTag.Xml, TagType.Other);\r
-\r
-       HtmlTextWriter._attrKeyLookupTable = new Hashtable(40);\r
-       HtmlTextWriter._attrNameLookupArray = new AttributeInformation[40];\r
-       HtmlTextWriter.RegisterAttribute("accesskey", HtmlTextWriterAttribute.Accesskey, true);\r
-       HtmlTextWriter.RegisterAttribute("align", HtmlTextWriterAttribute.Align, false);\r
-       HtmlTextWriter.RegisterAttribute("alt", HtmlTextWriterAttribute.Alt, true);\r
-       HtmlTextWriter.RegisterAttribute("background", HtmlTextWriterAttribute.Background, true);\r
-       HtmlTextWriter.RegisterAttribute("bgcolor", HtmlTextWriterAttribute.Bgcolor, false);\r
-       HtmlTextWriter.RegisterAttribute("border", HtmlTextWriterAttribute.Border, false);\r
-       HtmlTextWriter.RegisterAttribute("bordercolor", HtmlTextWriterAttribute.Bordercolor, false);\r
-       HtmlTextWriter.RegisterAttribute("cellpadding", HtmlTextWriterAttribute.Cellpadding, false);\r
-       HtmlTextWriter.RegisterAttribute("cellspacing", HtmlTextWriterAttribute.Cellspacing, false);\r
-       HtmlTextWriter.RegisterAttribute("checked", HtmlTextWriterAttribute.Checked, false);\r
-       HtmlTextWriter.RegisterAttribute("class", HtmlTextWriterAttribute.Class, true);\r
-       HtmlTextWriter.RegisterAttribute("cols", HtmlTextWriterAttribute.Cols, false);\r
-       HtmlTextWriter.RegisterAttribute("colspan", HtmlTextWriterAttribute.Colspan, false);\r
-       HtmlTextWriter.RegisterAttribute("disabled", HtmlTextWriterAttribute.Disabled, false);\r
-       HtmlTextWriter.RegisterAttribute("for", HtmlTextWriterAttribute.For, false);\r
-       HtmlTextWriter.RegisterAttribute("height", HtmlTextWriterAttribute.Height, false);\r
-       HtmlTextWriter.RegisterAttribute("href", HtmlTextWriterAttribute.Href, true);\r
-       HtmlTextWriter.RegisterAttribute("id", HtmlTextWriterAttribute.Id, false);\r
-       HtmlTextWriter.RegisterAttribute("maxlength", HtmlTextWriterAttribute.Maxlength, false);\r
-       HtmlTextWriter.RegisterAttribute("multiple", HtmlTextWriterAttribute.Multiple, false);\r
-       HtmlTextWriter.RegisterAttribute("name", HtmlTextWriterAttribute.Name, false);\r
-       HtmlTextWriter.RegisterAttribute("nowrap", HtmlTextWriterAttribute.Nowrap, false);\r
-       HtmlTextWriter.RegisterAttribute("onchange", HtmlTextWriterAttribute.Onchange, true);\r
-       HtmlTextWriter.RegisterAttribute("onclick", HtmlTextWriterAttribute.Onclick, true);\r
-       HtmlTextWriter.RegisterAttribute("readonly", HtmlTextWriterAttribute.ReadOnly, false);\r
-       HtmlTextWriter.RegisterAttribute("rows", HtmlTextWriterAttribute.Rows, false);\r
-       HtmlTextWriter.RegisterAttribute("rowspan", HtmlTextWriterAttribute.Rowspan, false);\r
-       HtmlTextWriter.RegisterAttribute("rules", HtmlTextWriterAttribute.Rules, false);\r
-       HtmlTextWriter.RegisterAttribute("selected", HtmlTextWriterAttribute.Selected, false);\r
-       HtmlTextWriter.RegisterAttribute("size", HtmlTextWriterAttribute.Size, false);\r
-       HtmlTextWriter.RegisterAttribute("src", HtmlTextWriterAttribute.Src, true);\r
-       HtmlTextWriter.RegisterAttribute("style", HtmlTextWriterAttribute.Style, false);\r
-       HtmlTextWriter.RegisterAttribute("tabindex", HtmlTextWriterAttribute.Tabindex, false);\r
-       HtmlTextWriter.RegisterAttribute("target", HtmlTextWriterAttribute.Target, false);\r
-       HtmlTextWriter.RegisterAttribute("title", HtmlTextWriterAttribute.Title, true);\r
-       HtmlTextWriter.RegisterAttribute("type", HtmlTextWriterAttribute.Type, false);\r
-       HtmlTextWriter.RegisterAttribute("valign", HtmlTextWriterAttribute.Valign, false);\r
-       HtmlTextWriter.RegisterAttribute("value", HtmlTextWriterAttribute.Value, true);\r
-       HtmlTextWriter.RegisterAttribute("width", HtmlTextWriterAttribute.Width, false);\r
-       HtmlTextWriter.RegisterAttribute("wrap", HtmlTextWriterAttribute.Wrap, false);\r
-\r
-       HtmlTextWriter._styleKeyLookupTable = new Hashtable(14);\r
-       HtmlTextWriter._styleNameLookupArray = new String[14];\r
-       HtmlTextWriter.RegisterStyle("background-color", HtmlTextWriterStyle.BackgroundColor);\r
-       HtmlTextWriter.RegisterStyle("background-image", HtmlTextWriterStyle.BackgroundImage);\r
-       HtmlTextWriter.RegisterStyle("border-collapse", HtmlTextWriterStyle.BorderCollapse);\r
-       HtmlTextWriter.RegisterStyle("border-color", HtmlTextWriterStyle.BorderColor);\r
-       HtmlTextWriter.RegisterStyle("border-style", HtmlTextWriterStyle.BorderStyle);\r
-       HtmlTextWriter.RegisterStyle("border-width", HtmlTextWriterStyle.BorderWidth);\r
-       HtmlTextWriter.RegisterStyle("color", HtmlTextWriterStyle.Color);\r
-       HtmlTextWriter.RegisterStyle("font-family", HtmlTextWriterStyle.FontFamily);\r
-       HtmlTextWriter.RegisterStyle("font-size", HtmlTextWriterStyle.FontSize);\r
-       HtmlTextWriter.RegisterStyle("font-style", HtmlTextWriterStyle.FontStyle);\r
-       HtmlTextWriter.RegisterStyle("font-weight", HtmlTextWriterStyle.FontWeight);\r
-       HtmlTextWriter.RegisterStyle("height", HtmlTextWriterStyle.Height);\r
-       HtmlTextWriter.RegisterStyle("text-decoration", HtmlTextWriterStyle.TextDecoration);\r
-       HtmlTextWriter.RegisterStyle("width", HtmlTextWriterStyle.Width);\r
-}\r
-\r
-public HtmlTextWriter(TextWriter writer):this(writer, "        "){}\r
-\r
-public HtmlTextWriter(TextWriter writer, string tabString) : base() {\r
-       this.writer = writer;\r
-       this.tabString = tabString;\r
-       indentLevel = 0;\r
-       tabsPending = false;\r
-       _httpWriter = writer as HttpWriter;\r
-       _isDescendant = GetType() == typeof(HtmlTextWriter) == false;\r
-       _attrList = new RenderAttribute[20];\r
-       _attrCount = 0;\r
-       _styleList = new RenderStyle[20];\r
-       _styleCount = 0;\r
-       _endTags = new TagStackEntry[16];\r
-       _endTagCount = 0;\r
-       _inlineCount = 0;\r
-}\r
-\r
-public virtual void AddAttribute(HtmlTextWriterAttribute key, string value){\r
-       if ((int) key >= 0 && (int) key < HtmlTextWriter._attrNameLookupArray.Length) {\r
-               AttributeInformation attrInfo = HtmlTextWriter._attrNameLookupArray[(int) key];\r
-               AddAttribute(attrInfo.name, value, key, attrInfo.encode);\r
-       }\r
-}\r
-\r
-public virtual void AddAttribute(HtmlTextWriterAttribute key, string value, bool fEncode){\r
-       if ((int) key >= 0 && (int) key < HtmlTextWriter._attrNameLookupArray.Length) {\r
-               AddAttribute(HtmlTextWriter._attrNameLookupArray[(int) key].name, value, key, fEncode);\r
-       }\r
-}\r
-\r
-public virtual void AddAttribute(string name, string value){\r
-       HtmlTextWriterAttribute attr = GetAttributeKey(name);\r
-       value = EncodeAttributeValue(GetAttributeKey(name), value);\r
-       AddAttribute(name, value, attr);\r
-}\r
-\r
-public virtual void AddAttribute(string name, string value, bool fEndode){\r
-       value = EncodeAttributeValue(value, fEndode);\r
-       AddAttribute(name, value, GetAttributeKey(name));\r
-}\r
-\r
-protected virtual void AddAttribute(string name, string value, HtmlTextWriterAttribute key){\r
-       AddAttribute(name, value, key, false);\r
-}\r
-\r
-private void AddAttribute(string name, string value, HtmlTextWriterAttribute key, bool encode){\r
-       if (_attrCount >= (int) _attrList.Length) {\r
-               RenderAttribute[] rAttrArr = new RenderAttribute[_attrList.Length * 2];\r
-               System.Array.Copy(_attrList, rAttrArr, (int) _attrList.Length);\r
-               _attrList = rAttrArr;\r
-       }\r
-       RenderAttribute rAttr;\r
-       rAttr.name = name;\r
-       rAttr.value = value;\r
-       rAttr.key = key;\r
-       rAttr.encode = encode;\r
-       _attrList [_attrCount++] = rAttr;\r
-}\r
-\r
-public virtual void AddStyleAttribute(HtmlTextWriterStyle key, string value){\r
-       AddStyleAttribute(GetStyleName(key), value, key);\r
-}\r
-\r
-public virtual void AddStyleAttribute(string name, string value){\r
-       AddStyleAttribute(name, value, GetStyleKey(name));\r
-}\r
-\r
-protected virtual void AddStyleAttribute(string name, string value, HtmlTextWriterStyle key){\r
-       if (_styleCount >= (int) _styleList.Length) {\r
-               RenderStyle[] rAttrArr = new RenderStyle[_styleList.Length * 2];\r
-               System.Array.Copy(_styleList, rAttrArr, (int) _styleList.Length);\r
-               _styleList = rAttrArr;\r
-       }\r
-       RenderStyle rAttr;\r
-       rAttr.name = name;\r
-       rAttr.value = value;\r
-       rAttr.key = key;\r
-       _styleList [_styleCount++] = rAttr;\r
-}\r
-\r
-public override void Close(){\r
-       writer.Close();\r
-}\r
-\r
-protected virtual string EncodeAttributeValue(HtmlTextWriterAttribute attrKey, string value){\r
-       bool valid = true;\r
-       if (0 <= (int) attrKey && (int) attrKey < HtmlTextWriter._attrNameLookupArray.Length)\r
-               valid = HtmlTextWriter._attrNameLookupArray[(int) attrKey].encode;\r
-       return EncodeAttributeValue(value, valid);\r
-}\r
-\r
-protected string EncodeAttributeValue(string value, bool fEncode){\r
-       if (value == null)\r
-               return null;\r
-       if (!(fEncode))\r
-               return value;\r
-       return System.Web.HttpUtility.HtmlAttributeEncode(value);\r
-}\r
-\r
-protected string EncodeUrl(string url){\r
-       if (url.IndexOf(SpaceChar) < 0)\r
-               return url;\r
-       System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
-       for(int i=0; i <= url.Length; i++){\r
-               char temp = url[i];\r
-               if (temp != 32)\r
-                       sb.Append(temp);\r
-               else\r
-                       sb.Append("%20");\r
-       }\r
-       return sb.ToString();\r
-}\r
-\r
-protected virtual void FilterAttributes(){\r
-       int count = 0;\r
-       for(int i=0; i < _styleCount; i++){\r
-               RenderStyle rStyle = _styleList[i];\r
-               if (OnStyleAttributeRender(rStyle.name, rStyle.value, rStyle.key)) {\r
-                       count++;\r
-               }\r
-       }\r
-       _styleCount = count;\r
-       count = 0;\r
-       for(int i=0; i <= _attrCount; i++){\r
-               RenderAttribute rAttr = _attrList[i];\r
-               if (OnAttributeRender(rAttr.name, rAttr.value, rAttr.key)) {\r
-                       count++;\r
-               }\r
-       }\r
-       _attrCount = count;\r
-}\r
-\r
-public override void Flush(){\r
-       writer.Flush();\r
-}\r
-\r
-protected HtmlTextWriterAttribute GetAttributeKey(string attrName){\r
-       if (attrName != null && attrName.Length > 0) {\r
-               object attr = HtmlTextWriter._attrKeyLookupTable[attrName.ToLower()];\r
-               if (attr != null)\r
-                       return (HtmlTextWriterAttribute) attr;\r
-       }\r
-       return (HtmlTextWriterAttribute) (-1);\r
-}\r
-\r
-protected string GetAttributeName(HtmlTextWriterAttribute attrKey){\r
-       if ((int) attrKey >= 0 && (int) attrKey < HtmlTextWriter._attrNameLookupArray.Length)\r
-               return HtmlTextWriter._attrNameLookupArray[(int) attrKey].name;\r
-       return System.String.Empty;\r
-}\r
-\r
-protected HtmlTextWriterStyle GetStyleKey(string styleName){\r
-       if (styleName != null && styleName.Length > 0) {\r
-               object style = HtmlTextWriter._styleKeyLookupTable[styleName.ToLower()];\r
-               if (style != null)\r
-                       return (HtmlTextWriterStyle) style;\r
-       }\r
-       return (HtmlTextWriterStyle) (-1);\r
-}\r
-\r
-protected string GetStyleName(HtmlTextWriterStyle styleKey){\r
-       if ((int) styleKey >= 0 && (int) styleKey < HtmlTextWriter._styleNameLookupArray.Length)\r
-               return HtmlTextWriter._styleNameLookupArray[(int) styleKey];\r
-       return System.String.Empty;\r
-}\r
-\r
-protected virtual HtmlTextWriterTag GetTagKey(string tagName){\r
-       if (tagName != null && tagName.Length > 0) {\r
-               object tag = HtmlTextWriter._tagKeyLookupTable[tagName.ToLower()];\r
-               if (tag != null)\r
-                       return (HtmlTextWriterTag) tag;\r
-       }\r
-       return 0;\r
-}\r
-\r
-protected virtual string GetTagName(HtmlTextWriterTag tagKey){\r
-       if ((int) tagKey >= 0 && (int) tagKey < HtmlTextWriter._tagNameLookupArray.Length)\r
-               return HtmlTextWriter._tagNameLookupArray[(int) tagKey].name;\r
-       return System.String.Empty;\r
-}\r
-\r
-protected bool IsAttributeDefined(HtmlTextWriterAttribute key){\r
-       for (int i=0; i < _attrCount; i++) {\r
-               if (_attrList[i].key == key)\r
-                       return true;\r
-       }\r
-       return false;\r
-}\r
-\r
-protected bool IsAttributeDefined(HtmlTextWriterAttribute key, ref string value){\r
-       value = null;\r
-       for (int i=0; i < _attrCount; i++) {\r
-               if (_attrList[i].key == key) {\r
-                       value = _attrList[i].value;\r
-                       return true;\r
-               }\r
-       }\r
-       return false;\r
-}\r
-\r
-protected bool IsStyleAttributeDefined(HtmlTextWriterStyle key){\r
-       for (int i= 0; i < _styleCount; i++) {\r
-               if (_styleList[i].key == key)\r
-                       return true;\r
-       }\r
-       return false;\r
-}\r
-\r
-protected bool IsStyleAttributeDefined(HtmlTextWriterStyle key, ref string value){\r
-       value = null;\r
-       for( int i=0; i < _styleCount; i++) {\r
-               if (_styleList[i].key == key) {\r
-                       value = _styleList[i].value;\r
-                       return true;\r
-               }\r
-       }\r
-       return false;\r
-}\r
-\r
-protected virtual bool OnAttributeRender(string name, string value, HtmlTextWriterAttribute key){\r
-       return true;\r
-}\r
-\r
-protected virtual bool OnStyleAttributeRender(string name, string value, HtmlTextWriterStyle key){\r
-       return true;\r
-}\r
-\r
-protected virtual bool OnTagRender(string name, HtmlTextWriterTag key){\r
-       return true;\r
-}\r
-\r
-protected virtual void OutputTabs(){\r
-       if (tabsPending) {\r
-               for(int i=0; i < indentLevel; i++) {\r
-                       writer.Write(tabString);\r
-               }\r
-               tabsPending = false;\r
-       }\r
-}\r
-\r
-protected string PopEndTag(){\r
-       if (_endTagCount <= 0)\r
-               throw new InvalidOperationException("A PopEndTag was called without a corresponding PushEndTag");\r
-       _endTagCount--;\r
-       TagKey = _endTags[_endTagCount].tagKey;\r
-       return _endTags[_endTagCount].endTagText;\r
-}\r
-\r
-protected void PushEndTag(string endTag){\r
-       if (_endTagCount >= (int) _endTags.Length) {\r
-               TagStackEntry[] temp = new TagStackEntry[(int) _endTags.Length * 2];\r
-               System.Array.Copy(_endTags, temp, (int) _endTags.Length);\r
-               _endTags = temp;\r
-       }\r
-       _endTags[_endTagCount].tagKey = _tagKey;\r
-       _endTags[_endTagCount].endTagText = endTag;\r
-       _endTagCount++;\r
-}\r
-\r
-protected static void RegisterAttribute(string name, HtmlTextWriterAttribute key){\r
-       HtmlTextWriter.RegisterAttribute(name, key, false);\r
-}\r
-\r
-private static void RegisterAttribute(string name, HtmlTextWriterAttribute key, bool fEncode){\r
-       name = name.ToLower();\r
-       HtmlTextWriter._attrKeyLookupTable.Add(name, key);\r
-       if ((int) key < (int) HtmlTextWriter._attrNameLookupArray.Length)\r
-               HtmlTextWriter._attrNameLookupArray[(int) key] = new AttributeInformation(name, fEncode);\r
-}\r
-\r
-protected static void RegisterStyle(string name, HtmlTextWriterStyle key){\r
-       name = name.ToLower();\r
-       HtmlTextWriter._styleKeyLookupTable.Add(name, key);\r
-       if ((int) key < (int) HtmlTextWriter._styleNameLookupArray.Length)\r
-               HtmlTextWriter._styleNameLookupArray[(int) key] = name;\r
-}\r
-\r
-protected static void RegisterTag(string name, HtmlTextWriterTag key){\r
-       HtmlTextWriter.RegisterTag(name, key, TagType.Other);\r
-}\r
-\r
-private static void RegisterTag(string name, HtmlTextWriterTag key, TagType type){\r
-       name = name.ToLower();\r
-       HtmlTextWriter._tagKeyLookupTable.Add(name, key);\r
-       string fullTag = null;\r
-       if ((int) type != 1 && (int) key != 0) {\r
-               fullTag = EndTagLeftChars + name + TagRightChar;\r
-       }\r
-       if ((int) key < HtmlTextWriter._tagNameLookupArray.Length)\r
-               HtmlTextWriter._tagNameLookupArray[(int) key] = new TagInformation(name, type, fullTag);\r
-}\r
-\r
-protected virtual string RenderAfterContent(){\r
-       return null;\r
-}\r
-\r
-protected virtual string RenderAfterTag(){\r
-       return null;\r
-}\r
-\r
-protected virtual string RenderBeforeContent(){\r
-       return null;\r
-}\r
-\r
-protected virtual string RenderBeforeTag(){\r
-       return null;\r
-}\r
-\r
-public virtual void RenderBeginTag(HtmlTextWriterTag tagKey){\r
-       TagKey = tagKey;\r
-       bool tagRendered = true;\r
-       bool tagRender = true;\r
-       if (_isDescendant) {\r
-               tagRender = OnTagRender(_tagName, _tagKey);\r
-               FilterAttributes();\r
-               string beforeTag = RenderBeforeTag();\r
-               if (beforeTag != null) {\r
-                       if (tabsPending)\r
-                               OutputTabs();\r
-                       writer.Write(beforeTag);\r
-               }\r
-       }\r
-       TagInformation currentTag = HtmlTextWriter._tagNameLookupArray[_tagIndex];\r
-       if (currentTag.closingTag == null)\r
-               currentTag.closingTag = EndTagLeftChars + _tagName + TagRightChar;\r
-       if (tagRender) {\r
-               tagRendered = false;\r
-               if (tabsPending)\r
-                       OutputTabs();\r
-               writer.Write(TagLeftChar);\r
-               writer.Write(_tagName);\r
-               RenderAttribute rAttr;\r
-               string rAttrValue = null;\r
-               for (int i=0; i < _attrCount; i++) {\r
-                       rAttr = _attrList[i];\r
-                       if (rAttr.key == HtmlTextWriterAttribute.Style)\r
-                               rAttrValue = rAttr.value;\r
-                       else {\r
-                               writer.Write(SpaceChar);\r
-                               writer.Write(rAttr.name);\r
-                               if (rAttr.value != null) {\r
-                                       writer.Write(EqualsChar);\r
-                                       writer.Write(DoubleQuoteChar);\r
-                                       if (rAttr.encode) {\r
-                                               if (_httpWriter == null) {\r
-                                                       System.Web.HttpUtility.HtmlAttributeEncode(rAttr.value, writer);\r
-                                               }\r
-                                               else {\r
-                                                       System.Web.HttpUtility.HtmlAttributeEncode(rAttr.value, (TextWriter) _httpWriter);\r
-                                               }\r
-                                       }\r
-                                       else {\r
-                                               writer.Write(rAttr.value);\r
-                                       }\r
-                                       writer.Write(DoubleQuoteChar);\r
-                               }\r
-                       }\r
-               }\r
-               if (_styleCount > 0 || rAttrValue != null) {\r
-                       writer.Write(SpaceChar);\r
-                       writer.Write("style");\r
-                       writer.Write(EqualsChar);\r
-                       writer.Write(DoubleQuoteChar);\r
-                       RenderStyle rStyle;\r
-                       for (int i=0; i < _styleCount; i++) {\r
-                               rStyle = _styleList[i];\r
-                               writer.Write(rStyle.name);\r
-                               writer.Write(StyleEqualsChar);\r
-                               writer.Write(rStyle.value);\r
-                               writer.Write(SemicolonChar);\r
-                       }\r
-                       if (rAttrValue != null)\r
-                               writer.Write(rAttrValue);\r
-                       writer.Write(DoubleQuoteChar);\r
-               }\r
-               if (currentTag.tagType == TagType.NonClosing) {\r
-                       writer.Write(SpaceChar);\r
-                       writer.Write(SlashChar);\r
-                       writer.Write(TagRightChar);\r
-               }\r
-               else\r
-                       writer.Write(TagRightChar);\r
-       }\r
-       string beforeContent = RenderBeforeContent();\r
-       if (beforeContent != null) {\r
-               if (tabsPending)\r
-                       OutputTabs();\r
-               writer.Write(beforeContent);\r
-       }\r
-       if (tagRendered) {\r
-               if (currentTag.tagType == TagType.Inline)\r
-                       _inlineCount++;\r
-               else {\r
-                       WriteLine();\r
-                       Indent++;\r
-               }\r
-               if (currentTag.closingTag == null) {\r
-                       currentTag.closingTag = EndTagLeftChars + _tagName + TagRightChar;\r
-               }\r
-       }\r
-       if (_isDescendant) {\r
-               string afterContent = RenderAfterContent();\r
-               if (afterContent != null) {\r
-                       if (currentTag.closingTag != null)\r
-                               currentTag.closingTag = afterContent;\r
-               }\r
-               string afterTag = RenderAfterTag();\r
-               if (afterTag != null) {\r
-                       if (currentTag.closingTag != null)\r
-                               currentTag.closingTag = afterTag;\r
-               }\r
-       }\r
-       PushEndTag(currentTag.closingTag);\r
-       _attrCount = 0;\r
-       _styleCount = 0;\r
-}\r
-\r
-public virtual void RenderBeginTag(string tagName){\r
-       TagName = tagName;\r
-       RenderBeginTag(_tagKey);\r
-}\r
-\r
-public virtual void RenderEndTag(){\r
-       string endTagText = PopEndTag();\r
-       if (endTagText != null) {\r
-               if (HtmlTextWriter._tagNameLookupArray[_tagIndex].tagType == 0) {\r
-                       _inlineCount--;\r
-                       Write(endTagText);\r
-               }\r
-               else{\r
-                       WriteLine();\r
-                       Indent--;\r
-                       Write(endTagText);\r
-               }\r
-       }\r
-}\r
-\r
-public override void Write(bool value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(value);\r
-}\r
-\r
-public override void Write(char value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(value);\r
-}\r
-\r
-public override void Write(char[] buffer){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(buffer);\r
-}\r
-\r
-public override void Write(char[] buffer, int index, int count){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(buffer, index, count);\r
-}\r
-\r
-public override void Write(double value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(value);\r
-}\r
-\r
-public override void Write(int value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(value);\r
-}\r
-\r
-public override void Write(long value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(value);\r
-}\r
-\r
-public override void Write(object value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(value);\r
-}\r
-\r
-public override void Write(float value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(value);\r
-}\r
-\r
-public override void Write(string s){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(s);\r
-}\r
-\r
-public override void Write(string format, object arg0){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(format, arg0);\r
-}\r
-\r
-public override void Write(string format, object arg0, object arg1){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(format, arg0, arg1);\r
-}\r
-\r
-public override void Write(string format, params object[] arg){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(format, arg);\r
-}\r
-\r
-public virtual void WriteAttribute(string name, string value){\r
-       WriteAttribute(name, value, false);\r
-}\r
-\r
-public virtual void WriteAttribute(string name, string value, bool fEncode){\r
-       writer.Write(SpaceChar);\r
-       writer.Write(name);\r
-       if (value != null) {\r
-               writer.Write(EqualsChar);\r
-               writer.Write(DoubleQuoteChar);\r
-               if (fEncode) {\r
-                       if (_httpWriter == null) {\r
-                               System.Web.HttpUtility.HtmlAttributeEncode(value, writer);\r
-                       }\r
-                       else{\r
-                               System.Web.HttpUtility.HtmlAttributeEncode(value, (TextWriter) _httpWriter);\r
-                       }\r
-               }\r
-               else{\r
-                       writer.Write(value);\r
-               }\r
-               writer.Write(DoubleQuoteChar);\r
-       }\r
-}\r
-\r
-public virtual void WriteBeginTag(string tagName){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(TagLeftChar);\r
-       writer.Write(tagName);\r
-}\r
-\r
-public virtual void WriteEndTag(string tagName){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(TagLeftChar);\r
-       writer.Write(SlashChar);\r
-       writer.Write(tagName);\r
-       writer.Write(TagRightChar);\r
-}\r
-\r
-public virtual void WriteFullBeginTag(string tagName){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.Write(TagLeftChar);\r
-       writer.Write(tagName);\r
-       writer.Write(TagRightChar);\r
-}\r
-\r
-public override void WriteLine(){\r
-       writer.WriteLine();\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(bool value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(char value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(char[] buffer){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(buffer);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(char[] buffer, int index, int count){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(buffer, index, count);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(double value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(int value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(long value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(object value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(float value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(string s){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(s);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(string format, object arg0){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(format, arg0);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(string format, object arg0, object arg1){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(format, arg0, arg1);\r
-       tabsPending = true;\r
-}\r
-\r
-public override void WriteLine(string format, params object[] arg){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(format, arg);\r
-       tabsPending = true;\r
-}\r
-\r
-[CLSCompliant(false)]\r
-public override void WriteLine(uint value){\r
-       if (tabsPending)\r
-               OutputTabs();\r
-       writer.WriteLine(value);\r
-       tabsPending = true;\r
-}\r
-\r
-public void WriteLineNoTabs(string s){\r
-       writer.WriteLine(s);\r
-}\r
-\r
-public virtual void WriteStyleAttribute(string name, string value){\r
-       WriteStyleAttribute(name, value, false);\r
-}\r
-\r
-public virtual void WriteStyleAttribute(string name, string value, bool fEncode){\r
-       writer.Write(name);\r
-       writer.Write(StyleEqualsChar);\r
-       if (fEncode) {\r
-               if (_httpWriter == null) {\r
-                       System.Web.HttpUtility.HtmlAttributeEncode(value, writer);\r
-               }\r
-               else{\r
-                       System.Web.HttpUtility.HtmlAttributeEncode(value, (TextWriter) _httpWriter);\r
-               }\r
-       }\r
-       else {\r
-               writer.Write(value);\r
-       }\r
-       writer.Write(SemicolonChar);\r
-}\r
-\r
-public override System.Text.Encoding Encoding { \r
-       get{\r
-               return writer.Encoding;\r
-       }\r
-}\r
-\r
-public int Indent { \r
-       get{\r
-               return indentLevel;\r
-       }\r
-       set{\r
-               if (value < 0)\r
-                       value = 0;\r
-               indentLevel = value;\r
-       }\r
-}\r
-\r
-public TextWriter InnerWriter { \r
-       get{\r
-               return writer;\r
-       }\r
-       set{\r
-               writer = value;\r
-               _httpWriter = value as HttpWriter;\r
-       }\r
-}\r
-\r
-public override string NewLine { \r
-       get{\r
-               return writer.NewLine;\r
-       }\r
-       set{\r
-               writer.NewLine = value;\r
-       }\r
-}\r
-\r
-protected HtmlTextWriterTag TagKey { \r
-       get{\r
-               return _tagKey;\r
-       }\r
-       set{\r
-               _tagIndex = (int) value;\r
-               if (_tagIndex < 0 || _tagIndex >= (int) HtmlTextWriter._tagNameLookupArray.Length)\r
-                       throw new ArgumentOutOfRangeException("value");\r
-               _tagKey = value;\r
-               if (value != 0)\r
-                       _tagName = HtmlTextWriter._tagNameLookupArray[_tagIndex].name;\r
-       }\r
-}\r
-\r
-protected string TagName { \r
-       get{\r
-               return _tagName;\r
-       }\r
-       set{\r
-               _tagName = value;\r
-               _tagKey = GetTagKey(_tagName);\r
-               _tagIndex = (int) _tagKey;\r
-       }\r
-}\r
-\r
-public const string DefaultTabString = "\t";\r
-public const char DoubleQuoteChar = '"';\r
-public const string EndTagLeftChars = "</";\r
-public const char EqualsChar = '=';\r
-public const string EqualsDoubleQuoteString = "=\"";\r
-public const string SelfClosingChars = " /";\r
-public const string SelfClosingTagEnd = " />";\r
-public const char SemicolonChar = ';';\r
-public const char SingleQuoteChar = '\'';\r
-public const char SlashChar = '/';\r
-public const char SpaceChar = ' ';\r
-public const char StyleEqualsChar = ':';\r
-public const char TagLeftChar = '<';\r
-public const char TagRightChar = '>';\r
-\r
-private int _attrCount;\r
-private int _endTagCount;\r
-private int _styleCount;\r
-private int indentLevel;\r
-private int _inlineCount;\r
-private int _tagIndex;\r
-\r
-private bool _isDescendant;\r
-private bool tabsPending;\r
-\r
-private HtmlTextWriterTag _tagKey;\r
-private TextWriter writer;\r
-private HttpWriter _httpWriter;\r
-\r
-private static Hashtable _attrKeyLookupTable;\r
-private static Hashtable _styleKeyLookupTable;\r
-private static Hashtable _tagKeyLookupTable;\r
-\r
-private string _tagName;\r
-private string tabString;\r
-private static string[] _styleNameLookupArray;\r
-\r
-private RenderAttribute[] _attrList;\r
-private static AttributeInformation[] _attrNameLookupArray;\r
-private static TagInformation[] _tagNameLookupArray;\r
-private TagStackEntry[] _endTags;\r
-private RenderStyle[] _styleList;\r
-\r
-} //HtmlTextWriter\r
-\r
-struct AttributeInformation {\r
-       public bool encode;\r
-       public string name;\r
-\r
-       public AttributeInformation(string name, bool encode){\r
-               this.encode = encode;\r
-               this.name = name;\r
-       }\r
-} \r
\r
-struct RenderAttribute {\r
-       public bool encode;\r
-       public HtmlTextWriterAttribute key;\r
-       public string name;\r
-       public string value;\r
-} \r
\r
-struct RenderStyle {\r
-       public HtmlTextWriterStyle key;\r
-       public string name;\r
-       public string value;\r
-} \r
\r
-struct TagInformation {\r
-       public string closingTag;\r
-       public string name;\r
-       public TagType tagType;\r
-\r
-       public TagInformation(string name, TagType tagType, string closingTag){\r
-               this.name = name;\r
-               this.tagType = tagType;\r
-               this.closingTag = closingTag;   \r
-       }\r
-} \r
\r
-struct TagStackEntry {\r
-       public string endTagText;\r
-       public HtmlTextWriterTag tagKey;\r
-} \r
\r
-enum TagType {\r
-       Inline,\r
-       NonClosing,\r
-       Other\r
-} \r
-\r
-\r
-} // namespace System.Web.UI.HtmlControls\r
-\r
+// 
+// System.Web.UI.HtmlTextWriter
+//
+// Author:
+//        Ben Maurer <bmaurer@novell.com>
+//
+// (c) 2005 Novell
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.IO;
+using System.Globalization;
+using System.Collections;
+using System.Security.Permissions;
+using System.Text;
+
+namespace System.Web.UI {
+       
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       public class HtmlTextWriter : TextWriter {
+
+
+               public HtmlTextWriter (TextWriter writer) : this (writer, DefaultTabString)
+               {
+               }
+       
+               public HtmlTextWriter (TextWriter writer, string tabString)
+               {
+                       if (writer == null)
+                               throw new ArgumentNullException ();
+
+                       b = writer;
+                       tab_string = tabString;
+               }
+
+               internal static string StaticGetStyleName (System.Web.UI.HtmlTextWriterStyle styleKey) 
+               {
+                       if ((int) styleKey < htmlstyles.Length)
+                               return htmlstyles [(int) styleKey].name;
+
+                       return null;
+               }
+               
+               [MonoTODO]
+               protected static void RegisterAttribute (string name, HtmlTextWriterAttribute key)
+               {
+               }
+               
+               [MonoTODO]
+               protected static void RegisterStyle (string name, HtmlTextWriterStyle key)
+               {
+               }
+               
+               [MonoTODO]
+               protected static void RegisterTag (string name, HtmlTextWriterTag key)
+               {
+               }
+               
+       
+               public virtual void AddAttribute (HtmlTextWriterAttribute key, string value, bool fEncode)
+               {
+                       if (fEncode)
+                               value = EncodeAttributeValue (key, value);
+                       AddAttribute (GetAttributeName (key), value, key);
+               }
+               
+               
+               public virtual void AddAttribute (HtmlTextWriterAttribute key, string value)
+               {
+                       AddAttribute (key, value, true);
+               }
+       
+       
+               public virtual void AddAttribute (string name, string value, bool fEncode)
+               {
+                       if (fEncode)
+                               value = HttpUtility.HtmlAttributeEncode (value);
+
+                       AddAttribute (name, value, GetAttributeKey (name));
+               }
+               
+               public virtual void AddAttribute (string name, string value)
+               {
+                       AddAttribute (name, value, true);
+               }
+       
+               protected virtual void AddAttribute (string name, string value, HtmlTextWriterAttribute key)
+               {
+                       NextAttrStack ();
+                       attrs [attrs_pos].name = name;
+                       attrs [attrs_pos].value = value;
+                       attrs [attrs_pos].key = key;
+               }
+               
+               
+               protected virtual void AddStyleAttribute (string name, string value, HtmlTextWriterStyle key)
+               {
+                       NextStyleStack ();
+                       styles [styles_pos].name = name;
+                       styles [styles_pos].value = value;
+                       styles [styles_pos].key = key;
+               }
+               
+
+               public virtual void AddStyleAttribute (string name, string value)
+               {
+                       AddStyleAttribute (name, value, GetStyleKey (name));
+               }
+               
+               public virtual void AddStyleAttribute (HtmlTextWriterStyle key, string value)
+               {
+                       AddStyleAttribute (GetStyleName (key), value, key);
+               }
+       
+               public override void Close ()
+               {
+                       b.Close ();     
+               }
+
+               protected virtual string EncodeAttributeValue (HtmlTextWriterAttribute attrKey, string value)
+               {
+                       return HttpUtility.HtmlEncode (value);
+               }
+               
+               protected string EncodeAttributeValue (string value, bool fEncode)
+               {
+                       if (fEncode)
+                               return HttpUtility.HtmlEncode (value);
+                       return value;
+               }
+               
+               protected string EncodeUrl (string url)
+               {
+                       return HttpUtility.UrlPathEncode (url);
+               }
+               
+
+               protected virtual void FilterAttributes ()
+               {
+                       AddedAttr style_attr = new AddedAttr ();
+                       
+                       for (int i = 0; i <= attrs_pos; i ++) {
+                               AddedAttr a = attrs [i];
+                               if (OnAttributeRender (a.name, a.value, a.key)) {
+                                       if (a.key == HtmlTextWriterAttribute.Style) {
+                                               style_attr = a;
+                                               continue;
+                                       }
+                                       
+                                       WriteAttribute (a.name, a.value, false);
+                               }
+                       }
+
+                       if (styles_pos != -1 || style_attr.value != null) {
+                               Write (SpaceChar);
+                               Write ("style");
+                               Write (EqualsDoubleQuoteString);
+                               
+                               
+                               for (int i = 0; i <= styles_pos; i ++) {
+                                       AddedStyle a = styles [i];
+                                       if (OnStyleAttributeRender (a.name, a.value, a.key))
+                                               WriteStyleAttribute (a.name, a.value, false);
+                               }
+
+                               Write (style_attr.value);                               
+                               Write (DoubleQuoteChar);
+                       }
+
+                       styles_pos = attrs_pos = -1;
+               }
+       
+               public override void Flush ()
+               {
+                       b.Flush ();
+               }
+
+               [MonoTODO]
+               protected HtmlTextWriterAttribute GetAttributeKey (string attrName)
+               {
+                       // I don't think we want to binary search
+                       // because there might be something added to
+                       // the enum later. Do we really need anything
+                       // faster than a linear search?
+                       
+                       foreach (HtmlAttribute t in htmlattrs) {
+                               if (String.Compare(t.name, attrName, true, CultureInfo.InvariantCulture) == 0)
+                                       return t.key;
+                       }
+
+                       return (HtmlTextWriterAttribute)(-1);           
+               }
+
+               [MonoTODO]
+               protected string GetAttributeName (HtmlTextWriterAttribute attrKey)
+               {
+                       if ((int) attrKey < htmlattrs.Length)
+                               return htmlattrs [(int) attrKey].name;
+
+                       return null;
+               }
+               
+               [MonoTODO]
+               protected HtmlTextWriterStyle GetStyleKey (string styleName)
+               {
+                       // I don't think we want to binary search
+                       // because there might be something added to
+                       // the enum later. Do we really need anything
+                       // faster than a linear search?
+                       
+                       foreach (HtmlStyle t in htmlstyles) {
+                               if (String.Compare(t.name, styleName, true, CultureInfo.InvariantCulture) == 0)
+                                       return t.key;
+                       }
+
+                       return (HtmlTextWriterStyle)(-1);                       
+               }
+               
+               [MonoTODO]
+               protected string GetStyleName (HtmlTextWriterStyle styleKey)
+               {
+                       return StaticGetStyleName (styleKey);
+               }
+               
+               [MonoTODO]
+               protected virtual HtmlTextWriterTag GetTagKey (string tagName) 
+               {
+                       // I don't think we want to binary search
+                       // because there might be something added to
+                       // the enum later. Do we really need anything
+                       // faster than a linear search?
+                       
+                       foreach (HtmlTag t in tags) {
+                               if (String.Compare(t.name, tagName, true, CultureInfo.InvariantCulture) == 0)
+                                       return t.key;
+                       }
+
+                       return HtmlTextWriterTag.Unknown;
+               }
+
+               internal static string StaticGetTagName (HtmlTextWriterTag tagKey)
+               {
+                       if ((int) tagKey < tags.Length)
+                               return tags [(int) tagKey].name;
+
+                       return null;    
+               }
+               
+               
+               [MonoTODO]
+               protected virtual string GetTagName (HtmlTextWriterTag tagKey)
+               {
+                       if ((int) tagKey < tags.Length)
+                               return tags [(int) tagKey].name;
+
+                       return null;
+               }
+               
+               protected bool IsAttributeDefined (HtmlTextWriterAttribute key)
+               {
+                       string value;
+                       return IsAttributeDefined (key, out value);
+               }
+       
+               protected bool IsAttributeDefined (HtmlTextWriterAttribute key, out string value)
+               {
+                       for (int i = 0; i <= attrs_pos; i ++)
+                               if (attrs [i].key == key){
+                                       value = attrs [i].value;
+                                       return true;
+                               }
+
+                       value = null;
+                       return false;
+               }
+               
+               protected bool IsStyleAttributeDefined (HtmlTextWriterStyle key)
+               {
+                       string value;
+                       return IsStyleAttributeDefined (key, out value);
+               }
+       
+               protected bool IsStyleAttributeDefined (HtmlTextWriterStyle key, out string value)
+               {
+                       for (int i = 0; i <= styles_pos; i ++)
+                               if (styles [i].key == key){
+                                       value = styles [i].value;
+                                       return true;
+                               }
+
+                       value = null;
+                       return false;
+               }
+               
+               protected virtual bool OnAttributeRender (string name, string value, HtmlTextWriterAttribute key)
+               {
+                       return true;
+               }
+               
+               protected virtual bool OnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key)
+               {
+                       return true;
+               }
+               
+               protected virtual bool OnTagRender (string name, HtmlTextWriterTag key)
+               {
+                       return true;
+               }
+               
+       
+               protected virtual void OutputTabs ()
+               {
+                       if (! newline)
+                               return;
+                       newline = false;
+
+                       for (int i = 0; i < Indent; i ++)
+                               b.Write (tab_string);
+               }
+       
+
+                       
+               protected string PopEndTag ()
+               {
+                       if (tagstack_pos == -1)
+                               throw new InvalidOperationException ();
+                       
+                       string s = TagName;
+                       tagstack_pos --;
+                       return s;
+               }
+               
+               protected void PushEndTag (string endTag)
+               {
+                       NextTagStack ();
+                       TagName = endTag;
+               }
+
+               void PushEndTag (HtmlTextWriterTag t)
+               {
+                       NextTagStack ();
+                       TagKey = t;
+               }
+               
+
+               protected virtual string RenderAfterContent ()
+               {
+                       return null;
+               }
+               
+               protected virtual string RenderAfterTag ()
+               {
+                       return null;
+               }
+               
+               protected virtual string RenderBeforeContent ()
+               {
+                       return null;
+               }
+                       
+               protected virtual string RenderBeforeTag ()
+               {
+                       return null;
+               }
+
+               public virtual void RenderBeginTag (string tagName)
+               {
+                       if (! OnTagRender (tagName, GetTagKey (tagName)))
+                               return;
+
+                       PushEndTag (tagName);
+                       
+                       DoBeginTag ();
+               }
+               
+               public virtual void RenderBeginTag (HtmlTextWriterTag tagKey)
+               {
+                       if (! OnTagRender (GetTagName (tagKey), tagKey))
+                               return;
+
+                       PushEndTag (tagKey);
+
+                       DoBeginTag ();
+               }
+
+               void WriteIfNotNull (string s)
+               {
+                       if (s != null)
+                               Write (s);
+               }
+               
+
+               void DoBeginTag ()
+               {
+                       WriteIfNotNull (RenderBeforeTag ());
+                       WriteBeginTag (TagName);
+                       FilterAttributes ();
+
+                       HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
+
+                       switch (tags [(int) key].tag_type) {
+                       case TagType.Inline:
+                               Write (TagRightChar);
+                               break;
+                       case TagType.Block:
+                               Write (TagRightChar);
+                               WriteLine ();
+                               Indent ++;
+                               break;
+                       case TagType.SelfClosing:
+                               Write (SelfClosingTagEnd);
+                               break;
+                       }
+                       
+                       // FIXME what do i do for self close here?
+                       WriteIfNotNull (RenderBeforeContent ());
+               }
+               
+
+               public virtual void RenderEndTag ()
+               {
+                       // FIXME what do i do for self close here?
+                       WriteIfNotNull (RenderAfterContent ());
+                       
+                       HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
+
+                       switch (tags [(int) key].tag_type) {
+                       case TagType.Inline:
+                               WriteEndTag (TagName);
+                               break;
+                       case TagType.Block:
+                               Indent --;
+                               WriteLineNoTabs ("");
+                               WriteEndTag (TagName);
+                               
+                               break;
+                       case TagType.SelfClosing:
+                               // NADA
+                               break;
+                       }
+                       WriteIfNotNull (RenderAfterTag ());
+
+                       PopEndTag ();
+               }
+               
+
+               public virtual void WriteAttribute (string name, string value, bool fEncode)
+               {
+                       Write (SpaceChar);
+                       Write (name);
+                       if (value != null) {
+                               Write (EqualsDoubleQuoteString);
+                               value = EncodeAttributeValue (value, fEncode);
+                               Write (value);
+                               Write (DoubleQuoteChar);
+                       }
+               }
+               
+       
+               public virtual void WriteBeginTag (string tagName)
+               {
+                       Write (TagLeftChar);
+                       Write (tagName);
+               }
+               
+               public virtual void WriteEndTag (string tagName)
+               {
+                       Write (EndTagLeftChars);
+                       Write (tagName);
+                       Write (TagRightChar);   
+               }
+               
+               public virtual void WriteFullBeginTag (string tagName)
+               {
+                       Write (TagLeftChar);
+                       Write (tagName);
+                       Write (TagRightChar);
+               }
+                       
+               public virtual void WriteStyleAttribute (string name, string value)
+               {
+                       WriteStyleAttribute (name, value, true);
+               }
+
+               public virtual void WriteStyleAttribute (string name, string value, bool fEncode)
+               {
+#if NET_2_0
+                       if (name == "background-image") {
+                               value = String.Concat ("url(", value, ")");
+                       }
+#endif
+                       Write (name);
+                       Write (StyleEqualsChar);
+                       Write (EncodeAttributeValue (value, fEncode));
+                       Write (SemicolonChar);
+               }
+               
+               public override void Write (char [] buffer, int index, int count)
+               {
+                       OutputTabs ();
+                       b.Write (buffer, index, count);
+               }
+       
+               public override void Write (double value)
+               {
+                       OutputTabs ();
+                       b.Write (value);
+               }
+       
+               public override void Write (char value)
+               {
+                       OutputTabs ();
+                       b.Write (value);
+               }
+       
+               public override void Write (char [] buffer)
+               {
+                       OutputTabs ();
+                       b.Write (buffer);
+               }
+       
+               public override void Write (int value)
+               {
+                       OutputTabs ();
+                       b.Write (value);
+               }
+       
+               public override void Write (string format, object arg0)
+               {
+                       OutputTabs ();
+                       b.Write (format, arg0);
+               }
+       
+               public override void Write (string format, object arg0, object arg1)
+               {
+                       OutputTabs ();
+                       b.Write (format, arg0, arg1);
+               }
+       
+               public override void Write (string format, params object [] args)
+               {
+                       OutputTabs ();
+                       b.Write (format, args);
+               }
+
+               public override void Write (string s)
+               {
+                       OutputTabs ();
+                       b.Write (s);
+               }
+               
+               public override void Write (long value)
+               {
+                       OutputTabs ();
+                       b.Write (value);
+               }
+       
+               public override void Write (object value)
+               {
+                       OutputTabs ();
+                       b.Write (value);
+               }
+               
+               public override void Write (float value)
+               {
+                       OutputTabs ();
+                       b.Write (value);
+               }
+       
+               public override void Write (bool value)
+               {
+                       OutputTabs ();
+                       b.Write (value);
+               }
+       
+               public virtual void WriteAttribute (string name, string value)
+               {
+                       WriteAttribute (name, value, true);
+               }
+
+               public override void WriteLine (char value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true;
+               }
+       
+               public override void WriteLine (long value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true;
+               }
+       
+               public override void WriteLine (object value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true; 
+               }
+       
+               public override void WriteLine (double value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true;
+               }
+       
+               public override void WriteLine (char [] buffer, int index, int count)
+               {
+                       OutputTabs ();
+                       b.WriteLine (buffer, index, count);
+                       newline = true;
+               }
+       
+               public override void WriteLine (char [] buffer)
+               {
+                       OutputTabs ();
+                       b.WriteLine (buffer);
+                       newline = true;
+               }
+               
+               public override void WriteLine (bool value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true;
+               }
+       
+               public override void WriteLine ()
+               {
+                       OutputTabs ();
+                       b.WriteLine ();
+                       newline = true;
+               }
+       
+               public override void WriteLine (int value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true;
+               }
+       
+               public override void WriteLine (string format, object arg0, object arg1)
+               {
+                       OutputTabs ();
+                       b.WriteLine (format, arg0, arg1);
+                       newline = true;
+               }
+       
+               public override void WriteLine (string format, object arg0)
+               {
+                       OutputTabs ();
+                       b.WriteLine (format, arg0);
+                       newline = true;
+               }
+       
+               public override void WriteLine (string format, params object [] args)
+               {
+                       OutputTabs ();
+                       b.WriteLine (format, args);
+                       newline = true;
+               }
+               
+               [CLSCompliant (false)]
+               public override void WriteLine (uint value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true;
+               }
+       
+               public override void WriteLine (string s)
+               {
+                       OutputTabs ();
+                       b.WriteLine (s);
+                       newline = true;
+               }
+       
+               public override void WriteLine (float value)
+               {
+                       OutputTabs ();
+                       b.WriteLine (value);
+                       newline = true;
+               }
+       
+               public void WriteLineNoTabs (string s)
+               {
+                       b.WriteLine (s);
+                       newline = true;
+               }
+
+               public override Encoding Encoding {
+                       get {
+                               return b.Encoding;      
+                       }
+               }
+
+               int indent;
+               public int Indent {
+                       get {
+                               return indent;
+                       }
+                       set {
+                               indent = value;
+                       }
+               }
+       
+               public System.IO.TextWriter InnerWriter {
+                       get {
+                               return b;
+                       }
+                       set {
+                               b = value;
+                       }       
+               }
+       
+               public override string NewLine {
+                       get {
+                               return b.NewLine;
+                       }
+                       set {
+                               b.NewLine = value;
+                       }
+               }
+       
+               protected HtmlTextWriterTag TagKey {
+                       get {
+                               if (tagstack_pos == -1)
+                                       throw new InvalidOperationException ();
+
+                               return tagstack [tagstack_pos].key;
+                       }
+                       set {
+                               tagstack [tagstack_pos].key = value;
+                               tagstack [tagstack_pos].name = GetTagName (value);
+                       }
+               }
+       
+               protected string TagName {
+                       get {
+                               if (tagstack_pos == -1)
+                                       throw new InvalidOperationException ();
+                               
+                               return tagstack [tagstack_pos].name;
+                       }
+                       set {
+                               tagstack [tagstack_pos].name = value;
+                               tagstack [tagstack_pos].key = GetTagKey (value);
+                               if (tagstack [tagstack_pos].key != HtmlTextWriterTag.Unknown)
+                                       tagstack [tagstack_pos].name = GetTagName (tagstack [tagstack_pos].key);
+                       }
+               }
+               
+
+               TextWriter b;
+               string tab_string;
+               bool newline;
+               
+               //
+               // These emulate generic Stack <T>, since we can't use that ;-(. _pos is the current
+               // element.IE, you edit blah [blah_pos]. I *really* want generics, sigh.
+               //
+               AddedStyle [] styles;
+               AddedAttr [] attrs;
+               AddedTag [] tagstack;
+
+               int styles_pos = -1, attrs_pos = -1, tagstack_pos = -1;
+               
+               struct AddedTag {
+                       public string name;
+                       public HtmlTextWriterTag key;
+               }
+               
+               struct AddedStyle {
+                       public string name;
+                       public HtmlTextWriterStyle key;
+                       public string value;
+               }
+               
+               struct AddedAttr {
+                       public string name;
+                       public HtmlTextWriterAttribute key;
+                       public string value;
+               }
+
+               void NextStyleStack ()
+               {
+                       if (styles == null)
+                               styles = new AddedStyle [16];
+                               
+                       if (++styles_pos < styles.Length)
+                               return;
+                       
+                       int nsize = styles.Length * 2;
+                       AddedStyle [] ncontents = new AddedStyle [nsize];
+
+                       Array.Copy (styles, ncontents, styles.Length);
+                       styles = ncontents;
+               }
+
+               void NextAttrStack ()
+               {
+                       if (attrs == null)
+                               attrs = new AddedAttr [16];
+                               
+                       if (++attrs_pos < attrs.Length)
+                               return;
+                       
+                       int nsize = attrs.Length * 2;
+                       AddedAttr [] ncontents = new AddedAttr [nsize];
+
+                       Array.Copy (attrs, ncontents, attrs.Length);
+                       attrs = ncontents;
+               }
+
+               void NextTagStack ()
+               {
+                       if (tagstack == null)
+                               tagstack = new AddedTag [16];
+                               
+                       if (++tagstack_pos < tagstack.Length)
+                               return;
+                                               
+                       int nsize = tagstack.Length * 2;
+                       AddedTag [] ncontents = new AddedTag [nsize];
+
+                       Array.Copy (tagstack, ncontents, tagstack.Length);
+                       tagstack = ncontents;
+               }
+       
+               public const string DefaultTabString = "\t";
+               public const char DoubleQuoteChar = '"';
+               public const string EndTagLeftChars = "</";
+               public const char EqualsChar = '=';
+               public const string EqualsDoubleQuoteString = "=\"";
+               public const string SelfClosingChars = " /";
+               public const string SelfClosingTagEnd = " />";
+               public const char SemicolonChar = ';';
+               public const char SingleQuoteChar = '\'';
+               public const char SlashChar = '/';
+               public const char SpaceChar = ' ' ;
+               public const char StyleEqualsChar = ':';
+               public const char TagLeftChar = '<';
+               public const char TagRightChar = '>';
+
+               enum TagType {
+                       Block,
+                       Inline,
+                       SelfClosing,
+               }
+               
+               
+               struct HtmlTag {
+                       public HtmlTextWriterTag key;
+                       public string name;
+                       public TagType tag_type;
+
+                       public HtmlTag (HtmlTextWriterTag k, string n, TagType tt)
+                       {
+                               key = k;
+                               name = n;
+                               tag_type = tt;
+                       }
+               }
+
+               struct HtmlStyle {
+                       public HtmlTextWriterStyle key;
+                       public string name;
+                       
+                       public HtmlStyle (HtmlTextWriterStyle k, string n)
+                       {
+                               key = k;
+                               name = n;
+                       }
+               }
+
+               
+               struct HtmlAttribute {
+                       public HtmlTextWriterAttribute key;
+                       public string name;
+
+                       public HtmlAttribute (HtmlTextWriterAttribute k, string n)
+                       {
+                               key = k;
+                               name = n;
+                       }
+               }
+               
+               static HtmlTag [] tags = {
+                       new HtmlTag (HtmlTextWriterTag.Unknown,    "",                  TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.A,          "a",                 TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Acronym,    "acronym",           TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Address,    "address",           TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Area,       "area",              TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.B,          "b",                 TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Base,       "base",              TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Basefont,   "basefont",          TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Bdo,        "bdo",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Bgsound,    "bgsound",           TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Big,        "big",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Blockquote, "blockquote",        TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Body,       "body",              TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Br,         "br",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Button,     "button",            TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Caption,    "caption",           TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Center,     "center",            TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Cite,       "cite",              TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Code,       "code",              TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Col,        "col",               TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Colgroup,   "colgroup",          TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Dd,         "dd",                TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Del,        "del",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Dfn,        "dfn",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Dir,        "dir",               TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Div,        "div",               TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Dl,         "dl",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Dt,         "dt",                TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Em,         "em",                TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Embed,      "embed",             TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Fieldset,   "fieldset",          TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Font,       "font",              TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Form,       "form",              TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Frame,      "frame",             TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Frameset,   "frameset",          TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.H1,         "h1",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.H2,         "h2",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.H3,         "h3",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.H4,         "h4",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.H5,         "h5",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.H6,         "h6",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Head,       "head",              TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Hr,         "hr",                TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Html,       "html",              TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.I,          "i",                 TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Iframe,     "iframe",            TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Img,        "img",               TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Input,      "input",             TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Ins,        "ins",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Isindex,    "isindex",           TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Kbd,        "kbd",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Label,      "label",             TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Legend,     "legend",            TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Li,         "li",                TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Link,       "link",              TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Map,        "map",               TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Marquee,    "marquee",           TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Menu,       "menu",              TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Meta,       "meta",              TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Nobr,       "nobr",              TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Noframes,   "noframes",          TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Noscript,   "noscript",          TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Object,     "object",            TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Ol,         "ol",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Option,     "option",            TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.P,          "p",                 TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Param,      "param",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Pre,        "pre",               TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Q,          "q",                 TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Rt,         "rt",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Ruby,       "ruby",              TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.S,          "s",                 TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Samp,       "samp",              TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Script,     "script",            TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Select,     "select",            TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Small,      "small",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Span,       "span",              TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Strike,     "strike",            TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Strong,     "strong",            TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Style,      "style",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Sub,        "sub",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Sup,        "sup",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Table,      "table",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Tbody,      "tbody",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Td,         "td",                TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Textarea,   "textarea",          TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Tfoot,      "tfoot",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Th,         "th",                TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Thead,      "thead",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Title,      "title",             TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Tr,         "tr",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Tt,         "tt",                TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.U,          "u",                 TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Ul,         "ul",                TagType.Block),
+                       new HtmlTag (HtmlTextWriterTag.Var,        "var",               TagType.Inline),
+                       new HtmlTag (HtmlTextWriterTag.Wbr,        "wbr",               TagType.SelfClosing),
+                       new HtmlTag (HtmlTextWriterTag.Xml,        "xml",               TagType.Block),
+               };
+
+               static HtmlAttribute [] htmlattrs = {
+                       new HtmlAttribute (HtmlTextWriterAttribute.Accesskey,         "accesskey"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Align,             "align"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Alt,               "alt"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Background,        "background"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Bgcolor,           "bgcolor"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Border,            "border"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Bordercolor,       "bordercolor"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Cellpadding,       "cellpadding"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Cellspacing,       "cellspacing"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Checked,           "checked"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Class,             "class"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Cols,              "cols"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Colspan,           "colspan"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Disabled,          "disabled"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.For,               "for"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Height,            "height"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Href,              "href"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Id,                "id"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Maxlength,         "maxlength"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Multiple,          "multiple"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Name,              "name"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Nowrap,            "nowrap"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Onchange,          "onchange"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Onclick,           "onclick"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.ReadOnly,          "readonly"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Rows,              "rows"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Rowspan,           "rowspan"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Rules,             "rules"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Selected,          "selected"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Size,              "size"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Src,               "src"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Style,             "style"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Tabindex,          "tabindex"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Target,            "target"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Title,             "title"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Type,              "type"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Valign,            "valign"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Value,             "value"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Width,             "width"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Wrap,              "wrap"),
+#if NET_2_0
+                       new HtmlAttribute (HtmlTextWriterAttribute.Abbr,              "abbr"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.AutoComplete,      "autocomplete"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Axis,              "axis"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Content,           "content"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Coords,            "coords"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.DesignerRegion,    "_designerregion"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Dir,               "dir"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Headers,           "headers"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Longdesc,          "longdesc"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Rel,               "rel"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Scope,             "scope"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Shape,             "shape"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.Usemap,            "usemap"),
+                       new HtmlAttribute (HtmlTextWriterAttribute.VCardName,         "vcard_name"),
+#endif
+               };
+
+               static HtmlStyle [] htmlstyles = {
+                       new HtmlStyle (HtmlTextWriterStyle.BackgroundColor,    "background-color"),
+                       new HtmlStyle (HtmlTextWriterStyle.BackgroundImage,    "background-image"),
+                       new HtmlStyle (HtmlTextWriterStyle.BorderCollapse,     "border-collapse"),
+                       new HtmlStyle (HtmlTextWriterStyle.BorderColor,        "border-color"),
+                       new HtmlStyle (HtmlTextWriterStyle.BorderStyle,        "border-style"),
+                       new HtmlStyle (HtmlTextWriterStyle.BorderWidth,        "border-width"),
+                       new HtmlStyle (HtmlTextWriterStyle.Color,              "color"),
+                       new HtmlStyle (HtmlTextWriterStyle.FontFamily,         "font-family"),
+                       new HtmlStyle (HtmlTextWriterStyle.FontSize,           "font-size"),
+                       new HtmlStyle (HtmlTextWriterStyle.FontStyle,          "font-style"),
+                       new HtmlStyle (HtmlTextWriterStyle.FontWeight,         "font-weight"),
+                       new HtmlStyle (HtmlTextWriterStyle.Height,             "height"),
+                       new HtmlStyle (HtmlTextWriterStyle.TextDecoration,     "text-decoration"),
+                       new HtmlStyle (HtmlTextWriterStyle.Width,              "width"),
+#if NET_2_0
+                       new HtmlStyle (HtmlTextWriterStyle.ListStyleImage,     "list-style-image"),
+                       new HtmlStyle (HtmlTextWriterStyle.ListStyleType,      "list-style-type"),
+                       new HtmlStyle (HtmlTextWriterStyle.Cursor,             "cursor"),
+                       new HtmlStyle (HtmlTextWriterStyle.Direction,          "direction"),
+                       new HtmlStyle (HtmlTextWriterStyle.Display,            "display"),
+                       new HtmlStyle (HtmlTextWriterStyle.Filter,             "filter"),
+                       new HtmlStyle (HtmlTextWriterStyle.FontVariant,        "font-variant"),
+                       new HtmlStyle (HtmlTextWriterStyle.Left,               "left"),
+                       new HtmlStyle (HtmlTextWriterStyle.Margin,             "margin"),
+                       new HtmlStyle (HtmlTextWriterStyle.MarginBottom,       "margin-bottom"),
+                       new HtmlStyle (HtmlTextWriterStyle.MarginLeft,         "margin-left"),
+                       new HtmlStyle (HtmlTextWriterStyle.MarginRight,        "margin-right"),
+                       new HtmlStyle (HtmlTextWriterStyle.MarginTop,          "margin-top"),
+                       new HtmlStyle (HtmlTextWriterStyle.Overflow,           "overflow"),
+                       new HtmlStyle (HtmlTextWriterStyle.OverflowX,          "overflow-x"),
+                       new HtmlStyle (HtmlTextWriterStyle.OverflowY,          "overflow-y"),
+                       new HtmlStyle (HtmlTextWriterStyle.Padding,            "padding"),
+                       new HtmlStyle (HtmlTextWriterStyle.PaddingBottom,      "padding-bottom"),
+                       new HtmlStyle (HtmlTextWriterStyle.PaddingLeft,        "padding-left"),
+                       new HtmlStyle (HtmlTextWriterStyle.PaddingRight,       "padding-right"),
+                       new HtmlStyle (HtmlTextWriterStyle.PaddingTop,         "padding-top"),
+                       new HtmlStyle (HtmlTextWriterStyle.Position,           "position"),
+                       new HtmlStyle (HtmlTextWriterStyle.TextAlign,          "text-align"),
+                       new HtmlStyle (HtmlTextWriterStyle.VerticalAlign,      "vertical-align"),
+                       new HtmlStyle (HtmlTextWriterStyle.TextOverflow,       "text-overflow"),
+                       new HtmlStyle (HtmlTextWriterStyle.Top,                "top"),
+                       new HtmlStyle (HtmlTextWriterStyle.Visibility,         "visibility"),
+                       new HtmlStyle (HtmlTextWriterStyle.WhiteSpace,         "white-space"),
+                       new HtmlStyle (HtmlTextWriterStyle.ZIndex,             "z-index"),
+#endif
+               };
+
+#if NET_2_0
+               public virtual bool IsValidFormAttribute (string attribute)
+               {
+                       return true;
+               }
+
+               // writes <br />
+               public virtual void WriteBreak ()
+               {
+                       string br = GetTagName (HtmlTextWriterTag.Br);
+                       WriteBeginTag (br);
+                       Write (SelfClosingTagEnd);
+               }
+#endif
+       }
+}