imported everything from my branch (which is slightly harmless).
[mono.git] / mcs / class / System.Web / System.Web.UI / HtmlTextWriter.cs
1
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 // 
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 // 
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 /*      System.Web.UI\r
23 *       Authors\r
24 *               Leen Toelen (toelen@hotmail.com)\r
25 */\r
26 \r
27 using System;\r
28 using System.IO;\r
29 using System.Collections;\r
30 using System.Web;\r
31 using System.Web.UI;\r
32 \r
33 namespace System.Web.UI{\r
34 \r
35 public class HtmlTextWriter : System.IO.TextWriter {\r
36 \r
37 static HtmlTextWriter(){\r
38         HtmlTextWriter._tagKeyLookupTable = new Hashtable(97,CaseInsensitiveHashCodeProvider.DefaultInvariant,
39                                                           CaseInsensitiveComparer.DefaultInvariant);
40         HtmlTextWriter._tagNameLookupArray = new TagInformation[97];\r
41         HtmlTextWriter.RegisterTag("", HtmlTextWriterTag.Unknown, TagType.Other);\r
42         HtmlTextWriter.RegisterTag("a", HtmlTextWriterTag.A, TagType.Inline);\r
43         HtmlTextWriter.RegisterTag("acronym", HtmlTextWriterTag.Acronym, TagType.Inline);\r
44         HtmlTextWriter.RegisterTag("address", HtmlTextWriterTag.Address, TagType.Other);\r
45         HtmlTextWriter.RegisterTag("area", HtmlTextWriterTag.Area, TagType.Other);\r
46         HtmlTextWriter.RegisterTag("b", HtmlTextWriterTag.B, TagType.Inline);\r
47         HtmlTextWriter.RegisterTag("base", HtmlTextWriterTag.Base, TagType.NonClosing);\r
48         HtmlTextWriter.RegisterTag("basefont", HtmlTextWriterTag.Basefont, TagType.NonClosing);\r
49         HtmlTextWriter.RegisterTag("bdo", HtmlTextWriterTag.Bdo, TagType.Inline);\r
50         HtmlTextWriter.RegisterTag("bgsound", HtmlTextWriterTag.Bgsound, TagType.NonClosing);\r
51         HtmlTextWriter.RegisterTag("big", HtmlTextWriterTag.Big, TagType.Inline);\r
52         HtmlTextWriter.RegisterTag("blockquote", HtmlTextWriterTag.Blockquote, TagType.Other);\r
53         HtmlTextWriter.RegisterTag("body", HtmlTextWriterTag.Body, TagType.Other);\r
54         HtmlTextWriter.RegisterTag("br", HtmlTextWriterTag.Br, TagType.Other);\r
55         HtmlTextWriter.RegisterTag("button", HtmlTextWriterTag.Button, TagType.Inline);\r
56         HtmlTextWriter.RegisterTag("caption", HtmlTextWriterTag.Caption, TagType.Other);\r
57         HtmlTextWriter.RegisterTag("center", HtmlTextWriterTag.Center, TagType.Other);\r
58         HtmlTextWriter.RegisterTag("cite", HtmlTextWriterTag.Cite, TagType.Inline);\r
59         HtmlTextWriter.RegisterTag("code", HtmlTextWriterTag.Code, TagType.Inline);\r
60         HtmlTextWriter.RegisterTag("col", HtmlTextWriterTag.Col, TagType.NonClosing);\r
61         HtmlTextWriter.RegisterTag("colgroup", HtmlTextWriterTag.Colgroup, TagType.Other);\r
62         HtmlTextWriter.RegisterTag("del", HtmlTextWriterTag.Del, TagType.Inline);\r
63         HtmlTextWriter.RegisterTag("dd", HtmlTextWriterTag.Dd, TagType.Inline);\r
64         HtmlTextWriter.RegisterTag("dfn", HtmlTextWriterTag.Dfn, TagType.Inline);\r
65         HtmlTextWriter.RegisterTag("dir", HtmlTextWriterTag.Dir, TagType.Other);\r
66         HtmlTextWriter.RegisterTag("div", HtmlTextWriterTag.Div, TagType.Other);\r
67         HtmlTextWriter.RegisterTag("dl", HtmlTextWriterTag.Dl, TagType.Other);\r
68         HtmlTextWriter.RegisterTag("dt", HtmlTextWriterTag.Dt, TagType.Inline);\r
69         HtmlTextWriter.RegisterTag("em", HtmlTextWriterTag.Em, TagType.Inline);\r
70         HtmlTextWriter.RegisterTag("embed", HtmlTextWriterTag.Embed, TagType.NonClosing);\r
71         HtmlTextWriter.RegisterTag("fieldset", HtmlTextWriterTag.Fieldset, TagType.Other);\r
72         HtmlTextWriter.RegisterTag("font", HtmlTextWriterTag.Font, TagType.Inline);\r
73         HtmlTextWriter.RegisterTag("form", HtmlTextWriterTag.Form, TagType.Other);\r
74         HtmlTextWriter.RegisterTag("frame", HtmlTextWriterTag.Frame, TagType.NonClosing);\r
75         HtmlTextWriter.RegisterTag("frameset", HtmlTextWriterTag.Frameset, TagType.Other);\r
76         HtmlTextWriter.RegisterTag("h1", HtmlTextWriterTag.H1, TagType.Other);\r
77         HtmlTextWriter.RegisterTag("h2", HtmlTextWriterTag.H2, TagType.Other);\r
78         HtmlTextWriter.RegisterTag("h3", HtmlTextWriterTag.H3, TagType.Other);\r
79         HtmlTextWriter.RegisterTag("h4", HtmlTextWriterTag.H4, TagType.Other);\r
80         HtmlTextWriter.RegisterTag("h5", HtmlTextWriterTag.H5, TagType.Other);\r
81         HtmlTextWriter.RegisterTag("h6", HtmlTextWriterTag.H6, TagType.Other);\r
82         HtmlTextWriter.RegisterTag("head", HtmlTextWriterTag.Head, TagType.Other);\r
83         HtmlTextWriter.RegisterTag("hr", HtmlTextWriterTag.Hr, TagType.NonClosing);\r
84         HtmlTextWriter.RegisterTag("html", HtmlTextWriterTag.Html, TagType.Other);\r
85         HtmlTextWriter.RegisterTag("i", HtmlTextWriterTag.I, TagType.Inline);\r
86         HtmlTextWriter.RegisterTag("iframe", HtmlTextWriterTag.Iframe, TagType.Other);\r
87         HtmlTextWriter.RegisterTag("img", HtmlTextWriterTag.Img, TagType.NonClosing);\r
88         HtmlTextWriter.RegisterTag("input", HtmlTextWriterTag.Input, TagType.NonClosing);\r
89         HtmlTextWriter.RegisterTag("ins", HtmlTextWriterTag.Ins, TagType.Inline);\r
90         HtmlTextWriter.RegisterTag("isindex", HtmlTextWriterTag.Isindex, TagType.NonClosing);\r
91         HtmlTextWriter.RegisterTag("kbd", HtmlTextWriterTag.Kbd, TagType.Inline);\r
92         HtmlTextWriter.RegisterTag("label", HtmlTextWriterTag.Label, TagType.Inline);\r
93         HtmlTextWriter.RegisterTag("legend", HtmlTextWriterTag.Legend, TagType.Other);\r
94         HtmlTextWriter.RegisterTag("li", HtmlTextWriterTag.Li, TagType.Inline);\r
95         HtmlTextWriter.RegisterTag("link", HtmlTextWriterTag.Link, TagType.NonClosing);\r
96         HtmlTextWriter.RegisterTag("map", HtmlTextWriterTag.Map, TagType.Other);\r
97         HtmlTextWriter.RegisterTag("marquee", HtmlTextWriterTag.Marquee, TagType.Other);\r
98         HtmlTextWriter.RegisterTag("menu", HtmlTextWriterTag.Menu, TagType.Other);\r
99         HtmlTextWriter.RegisterTag("meta", HtmlTextWriterTag.Meta, TagType.NonClosing);\r
100         HtmlTextWriter.RegisterTag("nobr", HtmlTextWriterTag.Nobr, TagType.Inline);\r
101         HtmlTextWriter.RegisterTag("noframes", HtmlTextWriterTag.Noframes, TagType.Other);\r
102         HtmlTextWriter.RegisterTag("noscript", HtmlTextWriterTag.Noscript, TagType.Other);\r
103         HtmlTextWriter.RegisterTag("object", HtmlTextWriterTag.Object, TagType.Other);\r
104         HtmlTextWriter.RegisterTag("ol", HtmlTextWriterTag.Ol, TagType.Other);\r
105         HtmlTextWriter.RegisterTag("option", HtmlTextWriterTag.Option, TagType.Other);\r
106         HtmlTextWriter.RegisterTag("p", HtmlTextWriterTag.P, TagType.Inline);\r
107         HtmlTextWriter.RegisterTag("param", HtmlTextWriterTag.Param, TagType.Other);\r
108         HtmlTextWriter.RegisterTag("pre", HtmlTextWriterTag.Pre, TagType.Other);\r
109         HtmlTextWriter.RegisterTag("q", HtmlTextWriterTag.Q, TagType.Inline);\r
110         HtmlTextWriter.RegisterTag("rt", HtmlTextWriterTag.Rt, TagType.Other);\r
111         HtmlTextWriter.RegisterTag("ruby", HtmlTextWriterTag.Ruby, TagType.Other);\r
112         HtmlTextWriter.RegisterTag("s", HtmlTextWriterTag.S, TagType.Inline);\r
113         HtmlTextWriter.RegisterTag("samp", HtmlTextWriterTag.Samp, TagType.Inline);\r
114         HtmlTextWriter.RegisterTag("script", HtmlTextWriterTag.Script, TagType.Other);\r
115         HtmlTextWriter.RegisterTag("select", HtmlTextWriterTag.Select, TagType.Other);\r
116         HtmlTextWriter.RegisterTag("small", HtmlTextWriterTag.Small, TagType.Other);\r
117         HtmlTextWriter.RegisterTag("span", HtmlTextWriterTag.Span, TagType.Inline);\r
118         HtmlTextWriter.RegisterTag("strike", HtmlTextWriterTag.Strike, TagType.Inline);\r
119         HtmlTextWriter.RegisterTag("strong", HtmlTextWriterTag.Strong, TagType.Inline);\r
120         HtmlTextWriter.RegisterTag("style", HtmlTextWriterTag.Style, TagType.Other);\r
121         HtmlTextWriter.RegisterTag("sub", HtmlTextWriterTag.Sub, TagType.Inline);\r
122         HtmlTextWriter.RegisterTag("sup", HtmlTextWriterTag.Sup, TagType.Inline);\r
123         HtmlTextWriter.RegisterTag("table", HtmlTextWriterTag.Table, TagType.Other);\r
124         HtmlTextWriter.RegisterTag("tbody", HtmlTextWriterTag.Tbody, TagType.Other);\r
125         HtmlTextWriter.RegisterTag("td", HtmlTextWriterTag.Td, TagType.Inline);\r
126         HtmlTextWriter.RegisterTag("textarea", HtmlTextWriterTag.Textarea, TagType.Inline);\r
127         HtmlTextWriter.RegisterTag("tfoot", HtmlTextWriterTag.Tfoot, TagType.Other);\r
128         HtmlTextWriter.RegisterTag("th", HtmlTextWriterTag.Th, TagType.Inline);\r
129         HtmlTextWriter.RegisterTag("thead", HtmlTextWriterTag.Thead, TagType.Other);\r
130         HtmlTextWriter.RegisterTag("title", HtmlTextWriterTag.Title, TagType.Other);\r
131         HtmlTextWriter.RegisterTag("tr", HtmlTextWriterTag.Tr, TagType.Other);\r
132         HtmlTextWriter.RegisterTag("tt", HtmlTextWriterTag.Tt, TagType.Inline);\r
133         HtmlTextWriter.RegisterTag("u", HtmlTextWriterTag.U, TagType.Inline);\r
134         HtmlTextWriter.RegisterTag("ul", HtmlTextWriterTag.Ul, TagType.Other);\r
135         HtmlTextWriter.RegisterTag("var", HtmlTextWriterTag.Var, TagType.Inline);\r
136         HtmlTextWriter.RegisterTag("wbr", HtmlTextWriterTag.Wbr, TagType.NonClosing);\r
137         HtmlTextWriter.RegisterTag("xml", HtmlTextWriterTag.Xml, TagType.Other);\r
138 \r
139 #if NET_2_0\r
140         HtmlTextWriter._attrNameLookupArray = new AttributeInformation[54];\r
141 #else\r
142         HtmlTextWriter._attrNameLookupArray = new AttributeInformation[40];\r
143 #endif\r
144         HtmlTextWriter._attrKeyLookupTable = new Hashtable (HtmlTextWriter._attrNameLookupArray.Length,
145                                         CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant);
146         HtmlTextWriter.RegisterAttribute("accesskey", HtmlTextWriterAttribute.Accesskey, true);\r
147         HtmlTextWriter.RegisterAttribute("align", HtmlTextWriterAttribute.Align, false);\r
148         HtmlTextWriter.RegisterAttribute("alt", HtmlTextWriterAttribute.Alt, true);\r
149         HtmlTextWriter.RegisterAttribute("background", HtmlTextWriterAttribute.Background, true);\r
150         HtmlTextWriter.RegisterAttribute("bgcolor", HtmlTextWriterAttribute.Bgcolor, false);\r
151         HtmlTextWriter.RegisterAttribute("border", HtmlTextWriterAttribute.Border, false);\r
152         HtmlTextWriter.RegisterAttribute("bordercolor", HtmlTextWriterAttribute.Bordercolor, false);\r
153         HtmlTextWriter.RegisterAttribute("cellpadding", HtmlTextWriterAttribute.Cellpadding, false);\r
154         HtmlTextWriter.RegisterAttribute("cellspacing", HtmlTextWriterAttribute.Cellspacing, false);\r
155         HtmlTextWriter.RegisterAttribute("checked", HtmlTextWriterAttribute.Checked, false);\r
156         HtmlTextWriter.RegisterAttribute("class", HtmlTextWriterAttribute.Class, true);\r
157         HtmlTextWriter.RegisterAttribute("cols", HtmlTextWriterAttribute.Cols, false);\r
158         HtmlTextWriter.RegisterAttribute("colspan", HtmlTextWriterAttribute.Colspan, false);\r
159         HtmlTextWriter.RegisterAttribute("disabled", HtmlTextWriterAttribute.Disabled, false);\r
160         HtmlTextWriter.RegisterAttribute("for", HtmlTextWriterAttribute.For, false);\r
161         HtmlTextWriter.RegisterAttribute("height", HtmlTextWriterAttribute.Height, false);\r
162         HtmlTextWriter.RegisterAttribute("href", HtmlTextWriterAttribute.Href, true);\r
163         HtmlTextWriter.RegisterAttribute("id", HtmlTextWriterAttribute.Id, false);\r
164         HtmlTextWriter.RegisterAttribute("maxlength", HtmlTextWriterAttribute.Maxlength, false);\r
165         HtmlTextWriter.RegisterAttribute("multiple", HtmlTextWriterAttribute.Multiple, false);\r
166         HtmlTextWriter.RegisterAttribute("name", HtmlTextWriterAttribute.Name, false);\r
167         HtmlTextWriter.RegisterAttribute("nowrap", HtmlTextWriterAttribute.Nowrap, false);\r
168         HtmlTextWriter.RegisterAttribute("onchange", HtmlTextWriterAttribute.Onchange, true);\r
169         HtmlTextWriter.RegisterAttribute("onclick", HtmlTextWriterAttribute.Onclick, true);\r
170         HtmlTextWriter.RegisterAttribute("readonly", HtmlTextWriterAttribute.ReadOnly, false);\r
171         HtmlTextWriter.RegisterAttribute("rows", HtmlTextWriterAttribute.Rows, false);\r
172         HtmlTextWriter.RegisterAttribute("rowspan", HtmlTextWriterAttribute.Rowspan, false);\r
173         HtmlTextWriter.RegisterAttribute("rules", HtmlTextWriterAttribute.Rules, false);\r
174         HtmlTextWriter.RegisterAttribute("selected", HtmlTextWriterAttribute.Selected, false);\r
175         HtmlTextWriter.RegisterAttribute("size", HtmlTextWriterAttribute.Size, false);\r
176         HtmlTextWriter.RegisterAttribute("src", HtmlTextWriterAttribute.Src, true);\r
177         HtmlTextWriter.RegisterAttribute("style", HtmlTextWriterAttribute.Style, false);\r
178         HtmlTextWriter.RegisterAttribute("tabindex", HtmlTextWriterAttribute.Tabindex, false);\r
179         HtmlTextWriter.RegisterAttribute("target", HtmlTextWriterAttribute.Target, false);\r
180         HtmlTextWriter.RegisterAttribute("title", HtmlTextWriterAttribute.Title, true);\r
181         HtmlTextWriter.RegisterAttribute("type", HtmlTextWriterAttribute.Type, false);\r
182         HtmlTextWriter.RegisterAttribute("valign", HtmlTextWriterAttribute.Valign, false);\r
183         HtmlTextWriter.RegisterAttribute("value", HtmlTextWriterAttribute.Value, true);\r
184         HtmlTextWriter.RegisterAttribute("width", HtmlTextWriterAttribute.Width, false);\r
185         HtmlTextWriter.RegisterAttribute("wrap", HtmlTextWriterAttribute.Wrap, false);\r
186 #if NET_2_0\r
187         HtmlTextWriter.RegisterAttribute("abbr", HtmlTextWriterAttribute.Abbr, false);\r
188         HtmlTextWriter.RegisterAttribute("autocomplete", HtmlTextWriterAttribute.AutoComplete, false);\r
189         HtmlTextWriter.RegisterAttribute("axis", HtmlTextWriterAttribute.Axis, false);\r
190         HtmlTextWriter.RegisterAttribute("content", HtmlTextWriterAttribute.Content, false);\r
191         HtmlTextWriter.RegisterAttribute("coords", HtmlTextWriterAttribute.Coords, false);\r
192         HtmlTextWriter.RegisterAttribute("_designerRegion", HtmlTextWriterAttribute.DesignerRegion, false);\r
193         HtmlTextWriter.RegisterAttribute("dir", HtmlTextWriterAttribute.Dir, false);\r
194         HtmlTextWriter.RegisterAttribute("headers", HtmlTextWriterAttribute.Headers, false);\r
195         HtmlTextWriter.RegisterAttribute("longdesc", HtmlTextWriterAttribute.Longdesc, false);\r
196         HtmlTextWriter.RegisterAttribute("rel", HtmlTextWriterAttribute.Rel, false);\r
197         HtmlTextWriter.RegisterAttribute("scope", HtmlTextWriterAttribute.Scope, false);\r
198         HtmlTextWriter.RegisterAttribute("shape", HtmlTextWriterAttribute.Shape, false);\r
199         HtmlTextWriter.RegisterAttribute("usemap", HtmlTextWriterAttribute.Usemap, false);\r
200         HtmlTextWriter.RegisterAttribute("vcard_name", HtmlTextWriterAttribute.VCardName, false);\r
201 #endif\r
202 \r
203 #if NET_2_0\r
204         HtmlTextWriter._styleNameLookupArray = new String[42];\r
205 #else\r
206         HtmlTextWriter._styleNameLookupArray = new String[14];\r
207 #endif\r
208         HtmlTextWriter._styleKeyLookupTable = new Hashtable (HtmlTextWriter._styleNameLookupArray.Length,
209                                 CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant);
210         HtmlTextWriter.RegisterStyle("background-color", HtmlTextWriterStyle.BackgroundColor);\r
211         HtmlTextWriter.RegisterStyle("background-image", HtmlTextWriterStyle.BackgroundImage);\r
212         HtmlTextWriter.RegisterStyle("border-collapse", HtmlTextWriterStyle.BorderCollapse);\r
213         HtmlTextWriter.RegisterStyle("border-color", HtmlTextWriterStyle.BorderColor);\r
214         HtmlTextWriter.RegisterStyle("border-style", HtmlTextWriterStyle.BorderStyle);\r
215         HtmlTextWriter.RegisterStyle("border-width", HtmlTextWriterStyle.BorderWidth);\r
216         HtmlTextWriter.RegisterStyle("color", HtmlTextWriterStyle.Color);\r
217         HtmlTextWriter.RegisterStyle("font-family", HtmlTextWriterStyle.FontFamily);\r
218         HtmlTextWriter.RegisterStyle("font-size", HtmlTextWriterStyle.FontSize);\r
219         HtmlTextWriter.RegisterStyle("font-style", HtmlTextWriterStyle.FontStyle);\r
220         HtmlTextWriter.RegisterStyle("font-weight", HtmlTextWriterStyle.FontWeight);\r
221         HtmlTextWriter.RegisterStyle("height", HtmlTextWriterStyle.Height);\r
222         HtmlTextWriter.RegisterStyle("text-decoration", HtmlTextWriterStyle.TextDecoration);\r
223         HtmlTextWriter.RegisterStyle("width", HtmlTextWriterStyle.Width);\r
224 #if NET_2_0\r
225         HtmlTextWriter.RegisterStyle("list-style-image", HtmlTextWriterStyle.ListStyleImage);\r
226         HtmlTextWriter.RegisterStyle("list-style-type", HtmlTextWriterStyle.ListStyleType);\r
227         HtmlTextWriter.RegisterStyle("cursor", HtmlTextWriterStyle.Cursor);\r
228         HtmlTextWriter.RegisterStyle("direction", HtmlTextWriterStyle.Direction);\r
229         HtmlTextWriter.RegisterStyle("display", HtmlTextWriterStyle.Display);\r
230         HtmlTextWriter.RegisterStyle("filter", HtmlTextWriterStyle.Filter);\r
231         HtmlTextWriter.RegisterStyle("font-variant", HtmlTextWriterStyle.FontVariant);\r
232         HtmlTextWriter.RegisterStyle("left", HtmlTextWriterStyle.Left);\r
233         HtmlTextWriter.RegisterStyle("margin", HtmlTextWriterStyle.Margin);\r
234         HtmlTextWriter.RegisterStyle("margin-bottom", HtmlTextWriterStyle.MarginBottom);\r
235         HtmlTextWriter.RegisterStyle("margin-left", HtmlTextWriterStyle.MarginLeft);\r
236         HtmlTextWriter.RegisterStyle("margin-right", HtmlTextWriterStyle.MarginRight);\r
237         HtmlTextWriter.RegisterStyle("margin-top", HtmlTextWriterStyle.MarginTop);\r
238         HtmlTextWriter.RegisterStyle("overflow", HtmlTextWriterStyle.Overflow);\r
239         HtmlTextWriter.RegisterStyle("overflow-x", HtmlTextWriterStyle.OverflowX);\r
240         HtmlTextWriter.RegisterStyle("overflow-y", HtmlTextWriterStyle.OverflowY);\r
241         HtmlTextWriter.RegisterStyle("padding", HtmlTextWriterStyle.Padding);\r
242         HtmlTextWriter.RegisterStyle("padding-bottom", HtmlTextWriterStyle.PaddingBottom);\r
243         HtmlTextWriter.RegisterStyle("padding-left", HtmlTextWriterStyle.PaddingLeft);\r
244         HtmlTextWriter.RegisterStyle("padding-right", HtmlTextWriterStyle.PaddingRight);\r
245         HtmlTextWriter.RegisterStyle("padding-top", HtmlTextWriterStyle.PaddingTop);\r
246         HtmlTextWriter.RegisterStyle("position", HtmlTextWriterStyle.Position);\r
247         HtmlTextWriter.RegisterStyle("text-align", HtmlTextWriterStyle.TextAlign);\r
248         HtmlTextWriter.RegisterStyle("text-overflow", HtmlTextWriterStyle.TextOverflow);\r
249         HtmlTextWriter.RegisterStyle("top", HtmlTextWriterStyle.Top);\r
250         HtmlTextWriter.RegisterStyle("visibility", HtmlTextWriterStyle.Visibility);\r
251         HtmlTextWriter.RegisterStyle("white-space", HtmlTextWriterStyle.WhiteSpace);\r
252         HtmlTextWriter.RegisterStyle("z-index", HtmlTextWriterStyle.ZIndex);\r
253 #endif\r
254 }\r
255 \r
256 public HtmlTextWriter(TextWriter writer):this(writer, " "){}\r
257 \r
258 public HtmlTextWriter(TextWriter writer, string tabString) : base() {\r
259         this.writer = writer;\r
260         this.tabString = tabString;\r
261         indentLevel = 0;\r
262         tabsPending = false;\r
263         _httpWriter = writer as HttpWriter;\r
264         _isDescendant = GetType() == typeof(HtmlTextWriter) == false;\r
265         _attrList = new RenderAttribute[20];\r
266         _attrCount = 0;\r
267         _styleList = new RenderStyle[20];\r
268         _styleCount = 0;\r
269         _endTags = new TagStackEntry[16];\r
270         _endTagCount = 0;\r
271         _inlineCount = 0;\r
272 }\r
273 \r
274 public virtual void AddAttribute(HtmlTextWriterAttribute key, string value){\r
275         if ((int) key >= 0 && (int) key < HtmlTextWriter._attrNameLookupArray.Length) {\r
276                 AttributeInformation attrInfo = HtmlTextWriter._attrNameLookupArray[(int) key];\r
277                 AddAttribute(attrInfo.name, value, key, attrInfo.encode);\r
278         }\r
279 }\r
280 \r
281 public virtual void AddAttribute(HtmlTextWriterAttribute key, string value, bool fEncode){\r
282         if ((int) key >= 0 && (int) key < HtmlTextWriter._attrNameLookupArray.Length) {\r
283                 AddAttribute(HtmlTextWriter._attrNameLookupArray[(int) key].name, value, key, fEncode);\r
284         }\r
285 }\r
286 \r
287 public virtual void AddAttribute(string name, string value){\r
288         HtmlTextWriterAttribute attr = GetAttributeKey(name);\r
289         value = EncodeAttributeValue(GetAttributeKey(name), value);\r
290         AddAttribute(name, value, attr);\r
291 }\r
292 \r
293 public virtual void AddAttribute(string name, string value, bool fEndode){\r
294         value = EncodeAttributeValue(value, fEndode);\r
295         AddAttribute(name, value, GetAttributeKey(name));\r
296 }\r
297 \r
298 protected virtual void AddAttribute(string name, string value, HtmlTextWriterAttribute key){\r
299         AddAttribute(name, value, key, false);\r
300 }\r
301 \r
302 private void AddAttribute(string name, string value, HtmlTextWriterAttribute key, bool encode){\r
303         if (_attrCount >= (int) _attrList.Length) {\r
304                 RenderAttribute[] rAttrArr = new RenderAttribute[_attrList.Length * 2];\r
305                 System.Array.Copy(_attrList, rAttrArr, (int) _attrList.Length);\r
306                 _attrList = rAttrArr;\r
307         }\r
308         RenderAttribute rAttr;\r
309         rAttr.name = name;\r
310         rAttr.value = value;\r
311         rAttr.key = key;\r
312         rAttr.encode = encode;\r
313         _attrList [_attrCount++] = rAttr;\r
314 }\r
315 \r
316 public virtual void AddStyleAttribute(HtmlTextWriterStyle key, string value){\r
317         AddStyleAttribute(GetStyleName(key), value, key);\r
318 }\r
319 \r
320 public virtual void AddStyleAttribute(string name, string value){\r
321         AddStyleAttribute(name, value, GetStyleKey(name));\r
322 }\r
323 \r
324 protected virtual void AddStyleAttribute(string name, string value, HtmlTextWriterStyle key){\r
325         if (_styleCount >= (int) _styleList.Length) {\r
326                 RenderStyle[] rAttrArr = new RenderStyle[_styleList.Length * 2];\r
327                 System.Array.Copy(_styleList, rAttrArr, (int) _styleList.Length);\r
328                 _styleList = rAttrArr;\r
329         }\r
330         RenderStyle rAttr;\r
331         rAttr.name = name;\r
332         rAttr.value = value;\r
333         rAttr.key = key;\r
334         _styleList [_styleCount++] = rAttr;\r
335 }\r
336 \r
337 public override void Close(){\r
338         writer.Close();\r
339 }\r
340 \r
341 protected virtual string EncodeAttributeValue(HtmlTextWriterAttribute attrKey, string value){\r
342         bool valid = true;\r
343         if (0 <= (int) attrKey && (int) attrKey < HtmlTextWriter._attrNameLookupArray.Length)\r
344                 valid = HtmlTextWriter._attrNameLookupArray[(int) attrKey].encode;\r
345         return EncodeAttributeValue(value, valid);\r
346 }\r
347 \r
348 protected string EncodeAttributeValue(string value, bool fEncode){\r
349         if (value == null)\r
350                 return null;\r
351         if (!(fEncode))\r
352                 return value;\r
353         return System.Web.HttpUtility.HtmlAttributeEncode(value);\r
354 }\r
355 \r
356 protected string EncodeUrl(string url){\r
357         if (url.IndexOf(SpaceChar) < 0)\r
358                 return url;\r
359         System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
360         for(int i=0; i <= url.Length; i++){\r
361                 char temp = url[i];\r
362                 if (temp != 32)\r
363                         sb.Append(temp);\r
364                 else\r
365                         sb.Append("%20");\r
366         }\r
367         return sb.ToString();\r
368 }\r
369 \r
370 protected virtual void FilterAttributes(){\r
371         int count = 0;\r
372         for(int i=0; i < _styleCount; i++){\r
373                 RenderStyle rStyle = _styleList[i];\r
374                 if (OnStyleAttributeRender(rStyle.name, rStyle.value, rStyle.key)) {\r
375                         count++;\r
376                 }\r
377         }\r
378         _styleCount = count;\r
379         count = 0;\r
380         for(int i=0; i <= _attrCount; i++){\r
381                 RenderAttribute rAttr = _attrList[i];\r
382                 if (OnAttributeRender(rAttr.name, rAttr.value, rAttr.key)) {\r
383                         count++;\r
384                 }\r
385         }\r
386         _attrCount = count;\r
387 }\r
388 \r
389 public override void Flush(){\r
390         writer.Flush();\r
391 }\r
392 \r
393 protected HtmlTextWriterAttribute GetAttributeKey(string attrName){\r
394         if (attrName != null && attrName.Length > 0) {\r
395                 object attr = HtmlTextWriter._attrKeyLookupTable[attrName];\r
396                 if (attr != null)\r
397                         return (HtmlTextWriterAttribute) attr;\r
398         }\r
399         return (HtmlTextWriterAttribute) (-1);\r
400 }\r
401 \r
402 protected string GetAttributeName(HtmlTextWriterAttribute attrKey){\r
403         if ((int) attrKey >= 0 && (int) attrKey < HtmlTextWriter._attrNameLookupArray.Length)\r
404                 return HtmlTextWriter._attrNameLookupArray[(int) attrKey].name;\r
405         return System.String.Empty;\r
406 }\r
407 \r
408 protected HtmlTextWriterStyle GetStyleKey(string styleName){\r
409         if (styleName != null && styleName.Length > 0) {\r
410                 object style = HtmlTextWriter._styleKeyLookupTable[styleName];\r
411                 if (style != null)\r
412                         return (HtmlTextWriterStyle) style;\r
413         }\r
414         return (HtmlTextWriterStyle) (-1);\r
415 }\r
416 \r
417 protected string GetStyleName(HtmlTextWriterStyle styleKey){\r
418         return StaticGetStyleName (styleKey);\r
419 }\r
420 \r
421 internal static string StaticGetStyleName (HtmlTextWriterStyle styleKey){\r
422         if ((int) styleKey >= 0 && (int) styleKey < HtmlTextWriter._styleNameLookupArray.Length)\r
423                 return HtmlTextWriter._styleNameLookupArray[(int) styleKey];\r
424         return System.String.Empty;\r
425 }\r
426 \r
427 protected virtual HtmlTextWriterTag GetTagKey(string tagName){\r
428         if (tagName != null && tagName.Length > 0) {\r
429                 object tag = HtmlTextWriter._tagKeyLookupTable[tagName];\r
430                 if (tag != null)\r
431                         return (HtmlTextWriterTag) tag;\r
432         }\r
433         return 0;\r
434 }\r
435 \r
436 protected virtual string GetTagName(HtmlTextWriterTag tagKey){\r
437         if ((int) tagKey >= 0 && (int) tagKey < HtmlTextWriter._tagNameLookupArray.Length)\r
438                 return HtmlTextWriter._tagNameLookupArray[(int) tagKey].name;\r
439         return System.String.Empty;\r
440 }\r
441 \r
442 protected bool IsAttributeDefined(HtmlTextWriterAttribute key){\r
443         for (int i=0; i < _attrCount; i++) {\r
444                 if (_attrList[i].key == key)\r
445                         return true;\r
446         }\r
447         return false;\r
448 }\r
449 \r
450 protected bool IsAttributeDefined(HtmlTextWriterAttribute key, out string value){\r
451         value = null;\r
452         for (int i=0; i < _attrCount; i++) {\r
453                 if (_attrList[i].key == key) {\r
454                         value = _attrList[i].value;\r
455                         return true;\r
456                 }\r
457         }\r
458         return false;\r
459 }\r
460 \r
461 protected bool IsStyleAttributeDefined(HtmlTextWriterStyle key){\r
462         for (int i= 0; i < _styleCount; i++) {\r
463                 if (_styleList[i].key == key)\r
464                         return true;\r
465         }\r
466         return false;\r
467 }\r
468 \r
469 protected bool IsStyleAttributeDefined(HtmlTextWriterStyle key, out string value){\r
470         value = null;\r
471         for( int i=0; i < _styleCount; i++) {\r
472                 if (_styleList[i].key == key) {\r
473                         value = _styleList[i].value;\r
474                         return true;\r
475                 }\r
476         }\r
477         return false;\r
478 }\r
479 \r
480 protected virtual bool OnAttributeRender(string name, string value, HtmlTextWriterAttribute key){\r
481         return true;\r
482 }\r
483 \r
484 protected virtual bool OnStyleAttributeRender(string name, string value, HtmlTextWriterStyle key){\r
485         return true;\r
486 }\r
487 \r
488 protected virtual bool OnTagRender(string name, HtmlTextWriterTag key){\r
489         return true;\r
490 }\r
491 \r
492 protected virtual void OutputTabs(){\r
493         if (tabsPending) {\r
494                 for(int i=0; i < indentLevel; i++) {\r
495                         writer.Write(tabString);\r
496                 }\r
497                 tabsPending = false;\r
498         }\r
499 }\r
500 \r
501 protected string PopEndTag(){\r
502         if (_endTagCount <= 0)\r
503                 throw new InvalidOperationException("A PopEndTag was called without a corresponding PushEndTag");\r
504         _endTagCount--;\r
505         TagKey = _endTags[_endTagCount].tagKey;\r
506         return _endTags[_endTagCount].endTagText;\r
507 }\r
508 \r
509 protected void PushEndTag(string endTag){\r
510         if (_endTagCount >= (int) _endTags.Length) {\r
511                 TagStackEntry[] temp = new TagStackEntry[(int) _endTags.Length * 2];\r
512                 System.Array.Copy(_endTags, temp, (int) _endTags.Length);\r
513                 _endTags = temp;\r
514         }\r
515         _endTags[_endTagCount].tagKey = _tagKey;\r
516         _endTags[_endTagCount].endTagText = endTag;\r
517         _endTagCount++;\r
518 }\r
519 \r
520 protected static void RegisterAttribute(string name, HtmlTextWriterAttribute key){\r
521         HtmlTextWriter.RegisterAttribute(name, key, false);\r
522 }\r
523 \r
524 private static void RegisterAttribute(string name, HtmlTextWriterAttribute key, bool fEncode){\r
525         name = name.ToLower();\r
526         HtmlTextWriter._attrKeyLookupTable.Add(name, key);\r
527         if ((int) key < (int) HtmlTextWriter._attrNameLookupArray.Length)\r
528                 HtmlTextWriter._attrNameLookupArray[(int) key] = new AttributeInformation(name, fEncode);\r
529 }\r
530 \r
531 protected static void RegisterStyle(string name, HtmlTextWriterStyle key){\r
532         name = name.ToLower();\r
533         HtmlTextWriter._styleKeyLookupTable.Add(name, key);\r
534         if ((int) key < (int) HtmlTextWriter._styleNameLookupArray.Length)\r
535                 HtmlTextWriter._styleNameLookupArray[(int) key] = name;\r
536 }\r
537 \r
538 protected static void RegisterTag(string name, HtmlTextWriterTag key){\r
539         HtmlTextWriter.RegisterTag(name, key, TagType.Other);\r
540 }\r
541 \r
542 private static void RegisterTag(string name, HtmlTextWriterTag key, TagType type){\r
543         name = name.ToLower();\r
544         HtmlTextWriter._tagKeyLookupTable.Add(name, key);\r
545         string fullTag = null;\r
546         if ((int) type != 1 && (int) key != 0) {\r
547                 fullTag = EndTagLeftChars + name + TagRightChar;\r
548         }\r
549         if ((int) key < HtmlTextWriter._tagNameLookupArray.Length)\r
550                 HtmlTextWriter._tagNameLookupArray[(int) key] = new TagInformation(name, type, fullTag);\r
551 }\r
552 \r
553 protected virtual string RenderAfterContent(){\r
554         return null;\r
555 }\r
556 \r
557 protected virtual string RenderAfterTag(){\r
558         return null;\r
559 }\r
560 \r
561 protected virtual string RenderBeforeContent(){\r
562         return null;\r
563 }\r
564 \r
565 protected virtual string RenderBeforeTag(){\r
566         return null;\r
567 }\r
568 \r
569 public virtual void RenderBeginTag(HtmlTextWriterTag tagKey){\r
570         TagKey = tagKey;\r
571         bool tagRendered = true;\r
572         bool tagRender = true;\r
573         if (_isDescendant) {\r
574                 tagRender = OnTagRender(_tagName, _tagKey);\r
575                 FilterAttributes();\r
576                 string beforeTag = RenderBeforeTag();\r
577                 if (beforeTag != null) {\r
578                         if (tabsPending)\r
579                                 OutputTabs();\r
580                         writer.Write(beforeTag);\r
581                 }\r
582         }\r
583         TagInformation currentTag = HtmlTextWriter._tagNameLookupArray[_tagIndex];\r
584         if (currentTag.closingTag == null && currentTag.tagType == TagType.Other) {\r
585                 currentTag.closingTag = EndTagLeftChars + _tagName + TagRightChar;\r
586         }\r
587 \r
588         if (tagRender) {\r
589                 tagRendered = false;\r
590                 if (tabsPending)\r
591                         OutputTabs();\r
592                 writer.Write(TagLeftChar);\r
593                 writer.Write(_tagName);\r
594                 RenderAttribute rAttr;\r
595                 string rAttrValue = null;\r
596                 for (int i=0; i < _attrCount; i++) {\r
597                         rAttr = _attrList[i];\r
598                         if (rAttr.key == HtmlTextWriterAttribute.Style)\r
599                                 rAttrValue = rAttr.value;\r
600                         else {\r
601                                 writer.Write(SpaceChar);\r
602                                 writer.Write(rAttr.name);\r
603                                 if (rAttr.value != null) {\r
604                                         writer.Write(EqualsChar);\r
605                                         writer.Write(DoubleQuoteChar);\r
606                                         if (rAttr.encode) {\r
607                                                 if (_httpWriter == null) {\r
608                                                         System.Web.HttpUtility.HtmlAttributeEncode(rAttr.value, writer);\r
609                                                 }\r
610                                                 else {\r
611                                                         System.Web.HttpUtility.HtmlAttributeEncode(rAttr.value, (TextWriter) _httpWriter);\r
612                                                 }\r
613                                         }\r
614                                         else {\r
615                                                 writer.Write(rAttr.value);\r
616                                         }\r
617                                         writer.Write(DoubleQuoteChar);\r
618                                 }\r
619                         }\r
620                 }\r
621                 if (_styleCount > 0 || rAttrValue != null) {\r
622                         writer.Write(SpaceChar);\r
623                         writer.Write("style");\r
624                         writer.Write(EqualsChar);\r
625                         writer.Write(DoubleQuoteChar);\r
626                         RenderStyle rStyle;\r
627                         for (int i=0; i < _styleCount; i++) {\r
628                                 rStyle = _styleList[i];\r
629                                 writer.Write(rStyle.name);\r
630                                 writer.Write(StyleEqualsChar);\r
631                                 writer.Write(rStyle.value);\r
632                                 writer.Write(SemicolonChar);\r
633                         }\r
634                         if (rAttrValue != null)\r
635                                 writer.Write(rAttrValue);\r
636                         writer.Write(DoubleQuoteChar);\r
637                 }\r
638                 if (currentTag.tagType == TagType.NonClosing) {\r
639                         writer.Write(SpaceChar);\r
640                         writer.Write(SlashChar);\r
641                         writer.Write(TagRightChar);\r
642                 }\r
643                 else\r
644                         writer.Write(TagRightChar);\r
645         }\r
646         string beforeContent = RenderBeforeContent();\r
647         if (beforeContent != null) {\r
648                 if (tabsPending)\r
649                         OutputTabs();\r
650                 writer.Write(beforeContent);\r
651         }\r
652         if (tagRendered) {\r
653                 if (currentTag.tagType == TagType.Inline)\r
654                         _inlineCount++;\r
655                 else {\r
656                         WriteLine();\r
657                         Indent++;\r
658                 }\r
659                 if (currentTag.closingTag == null) {\r
660                         currentTag.closingTag = EndTagLeftChars + _tagName + TagRightChar;\r
661                 }\r
662         }\r
663         if (_isDescendant) {\r
664                 string afterContent = RenderAfterContent();\r
665                 if (afterContent != null) {\r
666                         if (currentTag.closingTag != null)\r
667                                 currentTag.closingTag = afterContent;\r
668                 }\r
669                 string afterTag = RenderAfterTag();\r
670                 if (afterTag != null) {\r
671                         if (currentTag.closingTag != null)\r
672                                 currentTag.closingTag = afterTag;\r
673                 }\r
674         }\r
675         PushEndTag(currentTag.closingTag);\r
676         _attrCount = 0;\r
677         _styleCount = 0;\r
678 }\r
679 \r
680 public virtual void RenderBeginTag(string tagName){\r
681         TagName = tagName;\r
682         RenderBeginTag(_tagKey);\r
683 }\r
684 \r
685 public virtual void RenderEndTag(){\r
686         string endTagText = PopEndTag();\r
687         if (endTagText != null) {\r
688                 if (HtmlTextWriter._tagNameLookupArray[_tagIndex].tagType == 0) {\r
689                         _inlineCount--;\r
690                         Write(endTagText);\r
691                 }\r
692                 else{\r
693                         WriteLine();\r
694                         Indent--;\r
695                         Write(endTagText);\r
696                 }\r
697         }\r
698 }\r
699 \r
700 public override void Write(bool value){\r
701         if (tabsPending)\r
702                 OutputTabs();\r
703         writer.Write(value);\r
704 }\r
705 \r
706 public override void Write(char value){\r
707         if (tabsPending)\r
708                 OutputTabs();\r
709         writer.Write(value);\r
710 }\r
711 \r
712 public override void Write(char[] buffer){\r
713         if (tabsPending)\r
714                 OutputTabs();\r
715         writer.Write(buffer);\r
716 }\r
717 \r
718 public override void Write(char[] buffer, int index, int count){\r
719         if (tabsPending)\r
720                 OutputTabs();\r
721         writer.Write(buffer, index, count);\r
722 }\r
723 \r
724 public override void Write(double value){\r
725         if (tabsPending)\r
726                 OutputTabs();\r
727         writer.Write(value);\r
728 }\r
729 \r
730 public override void Write(int value){\r
731         if (tabsPending)\r
732                 OutputTabs();\r
733         writer.Write(value);\r
734 }\r
735 \r
736 public override void Write(long value){\r
737         if (tabsPending)\r
738                 OutputTabs();\r
739         writer.Write(value);\r
740 }\r
741 \r
742 public override void Write(object value){\r
743         if (tabsPending)\r
744                 OutputTabs();\r
745         writer.Write(value);\r
746 }\r
747 \r
748 public override void Write(float value){\r
749         if (tabsPending)\r
750                 OutputTabs();\r
751         writer.Write(value);\r
752 }\r
753 \r
754 public override void Write(string s){\r
755         if (tabsPending)\r
756                 OutputTabs();\r
757         writer.Write(s);\r
758 }\r
759 \r
760 public override void Write(string format, object arg0){\r
761         if (tabsPending)\r
762                 OutputTabs();\r
763         writer.Write(format, arg0);\r
764 }\r
765 \r
766 public override void Write(string format, object arg0, object arg1){\r
767         if (tabsPending)\r
768                 OutputTabs();\r
769         writer.Write(format, arg0, arg1);\r
770 }\r
771 \r
772 public override void Write(string format, params object[] arg){\r
773         if (tabsPending)\r
774                 OutputTabs();\r
775         writer.Write(format, arg);\r
776 }\r
777 \r
778 public virtual void WriteAttribute(string name, string value){\r
779         WriteAttribute(name, value, false);\r
780 }\r
781 \r
782 public virtual void WriteAttribute(string name, string value, bool fEncode){\r
783         writer.Write(SpaceChar);\r
784         writer.Write(name);\r
785         if (value != null) {\r
786                 writer.Write(EqualsChar);\r
787                 writer.Write(DoubleQuoteChar);\r
788                 if (fEncode) {\r
789                         if (_httpWriter == null) {\r
790                                 System.Web.HttpUtility.HtmlAttributeEncode(value, writer);\r
791                         }\r
792                         else{\r
793                                 System.Web.HttpUtility.HtmlAttributeEncode(value, (TextWriter) _httpWriter);\r
794                         }\r
795                 }\r
796                 else{\r
797                         writer.Write(value);\r
798                 }\r
799                 writer.Write(DoubleQuoteChar);\r
800         }\r
801 }\r
802 \r
803 public virtual void WriteBeginTag(string tagName){\r
804         if (tabsPending)\r
805                 OutputTabs();\r
806         writer.Write(TagLeftChar);\r
807         writer.Write(tagName);\r
808 }\r
809 \r
810 public virtual void WriteEndTag(string tagName){\r
811         if (tabsPending)\r
812                 OutputTabs();\r
813         writer.Write(TagLeftChar);\r
814         writer.Write(SlashChar);\r
815         writer.Write(tagName);\r
816         writer.Write(TagRightChar);\r
817 }\r
818 \r
819 public virtual void WriteFullBeginTag(string tagName){\r
820         if (tabsPending)\r
821                 OutputTabs();\r
822         writer.Write(TagLeftChar);\r
823         writer.Write(tagName);\r
824         writer.Write(TagRightChar);\r
825 }\r
826 \r
827 public override void WriteLine(){\r
828         writer.WriteLine();\r
829         tabsPending = true;\r
830 }\r
831 \r
832 public override void WriteLine(bool value){\r
833         if (tabsPending)\r
834                 OutputTabs();\r
835         writer.WriteLine(value);\r
836         tabsPending = true;\r
837 }\r
838 \r
839 public override void WriteLine(char value){\r
840         if (tabsPending)\r
841                 OutputTabs();\r
842         writer.WriteLine(value);\r
843         tabsPending = true;\r
844 }\r
845 \r
846 public override void WriteLine(char[] buffer){\r
847         if (tabsPending)\r
848                 OutputTabs();\r
849         writer.WriteLine(buffer);\r
850         tabsPending = true;\r
851 }\r
852 \r
853 public override void WriteLine(char[] buffer, int index, int count){\r
854         if (tabsPending)\r
855                 OutputTabs();\r
856         writer.WriteLine(buffer, index, count);\r
857         tabsPending = true;\r
858 }\r
859 \r
860 public override void WriteLine(double value){\r
861         if (tabsPending)\r
862                 OutputTabs();\r
863         writer.WriteLine(value);\r
864         tabsPending = true;\r
865 }\r
866 \r
867 public override void WriteLine(int value){\r
868         if (tabsPending)\r
869                 OutputTabs();\r
870         writer.WriteLine(value);\r
871         tabsPending = true;\r
872 }\r
873 \r
874 public override void WriteLine(long value){\r
875         if (tabsPending)\r
876                 OutputTabs();\r
877         writer.WriteLine(value);\r
878         tabsPending = true;\r
879 }\r
880 \r
881 public override void WriteLine(object value){\r
882         if (tabsPending)\r
883                 OutputTabs();\r
884         writer.WriteLine(value);\r
885         tabsPending = true;\r
886 }\r
887 \r
888 public override void WriteLine(float value){\r
889         if (tabsPending)\r
890                 OutputTabs();\r
891         writer.WriteLine(value);\r
892         tabsPending = true;\r
893 }\r
894 \r
895 public override void WriteLine(string s){\r
896         if (tabsPending)\r
897                 OutputTabs();\r
898         writer.WriteLine(s);\r
899         tabsPending = true;\r
900 }\r
901 \r
902 public override void WriteLine(string format, object arg0){\r
903         if (tabsPending)\r
904                 OutputTabs();\r
905         writer.WriteLine(format, arg0);\r
906         tabsPending = true;\r
907 }\r
908 \r
909 public override void WriteLine(string format, object arg0, object arg1){\r
910         if (tabsPending)\r
911                 OutputTabs();\r
912         writer.WriteLine(format, arg0, arg1);\r
913         tabsPending = true;\r
914 }\r
915 \r
916 public override void WriteLine(string format, params object[] arg){\r
917         if (tabsPending)\r
918                 OutputTabs();\r
919         writer.WriteLine(format, arg);\r
920         tabsPending = true;\r
921 }\r
922 \r
923 [CLSCompliant(false)]\r
924 public override void WriteLine(uint value){\r
925         if (tabsPending)\r
926                 OutputTabs();\r
927         writer.WriteLine(value);\r
928         tabsPending = true;\r
929 }\r
930 \r
931 public void WriteLineNoTabs(string s){\r
932         writer.WriteLine(s);\r
933 }\r
934 \r
935 public virtual void WriteStyleAttribute(string name, string value){\r
936         WriteStyleAttribute(name, value, false);\r
937 }\r
938 \r
939 public virtual void WriteStyleAttribute(string name, string value, bool fEncode){\r
940         writer.Write(name);\r
941         writer.Write(StyleEqualsChar);\r
942         if (fEncode) {\r
943                 if (_httpWriter == null) {\r
944                         System.Web.HttpUtility.HtmlAttributeEncode(value, writer);\r
945                 }\r
946                 else{\r
947                         System.Web.HttpUtility.HtmlAttributeEncode(value, (TextWriter) _httpWriter);\r
948                 }\r
949         }\r
950         else {\r
951                 writer.Write(value);\r
952         }\r
953         writer.Write(SemicolonChar);\r
954 }\r
955 \r
956 public override System.Text.Encoding Encoding { \r
957         get{\r
958                 return writer.Encoding;\r
959         }\r
960 }\r
961 \r
962 public int Indent { \r
963         get{\r
964                 return indentLevel;\r
965         }\r
966         set{\r
967                 if (value < 0)\r
968                         value = 0;\r
969                 indentLevel = value;\r
970         }\r
971 }\r
972 \r
973 public TextWriter InnerWriter { \r
974         get{\r
975                 return writer;\r
976         }\r
977         set{\r
978                 writer = value;\r
979                 _httpWriter = value as HttpWriter;\r
980         }\r
981 }\r
982 \r
983 public override string NewLine { \r
984         get{\r
985                 return writer.NewLine;\r
986         }\r
987         set{\r
988                 writer.NewLine = value;\r
989         }\r
990 }\r
991 \r
992 protected HtmlTextWriterTag TagKey { \r
993         get{\r
994                 return _tagKey;\r
995         }\r
996         set{\r
997                 _tagIndex = (int) value;\r
998                 if (_tagIndex < 0 || _tagIndex >= (int) HtmlTextWriter._tagNameLookupArray.Length)\r
999                         throw new ArgumentOutOfRangeException("value");\r
1000                 _tagKey = value;\r
1001                 if (value != 0)\r
1002                         _tagName = HtmlTextWriter._tagNameLookupArray[_tagIndex].name;\r
1003         }\r
1004 }\r
1005 \r
1006 protected string TagName { \r
1007         get{\r
1008                 return _tagName;\r
1009         }\r
1010         set{\r
1011                 _tagName = value;\r
1012                 _tagKey = GetTagKey(_tagName);\r
1013                 _tagIndex = (int) _tagKey;\r
1014         }\r
1015 }\r
1016 \r
1017 public const string DefaultTabString = "\t";\r
1018 public const char DoubleQuoteChar = '"';\r
1019 public const string EndTagLeftChars = "</";\r
1020 public const char EqualsChar = '=';\r
1021 public const string EqualsDoubleQuoteString = "=\"";\r
1022 public const string SelfClosingChars = " /";\r
1023 public const string SelfClosingTagEnd = " />";\r
1024 public const char SemicolonChar = ';';\r
1025 public const char SingleQuoteChar = '\'';\r
1026 public const char SlashChar = '/';\r
1027 public const char SpaceChar = ' ';\r
1028 public const char StyleEqualsChar = ':';\r
1029 public const char TagLeftChar = '<';\r
1030 public const char TagRightChar = '>';\r
1031 \r
1032 private int _attrCount;\r
1033 private int _endTagCount;\r
1034 private int _styleCount;\r
1035 private int indentLevel;\r
1036 private int _inlineCount;\r
1037 private int _tagIndex;\r
1038 \r
1039 private bool _isDescendant;\r
1040 private bool tabsPending;\r
1041 \r
1042 private HtmlTextWriterTag _tagKey;\r
1043 private TextWriter writer;\r
1044 private HttpWriter _httpWriter;\r
1045 \r
1046 private static Hashtable _attrKeyLookupTable;\r
1047 private static Hashtable _styleKeyLookupTable;\r
1048 private static Hashtable _tagKeyLookupTable;\r
1049 \r
1050 private string _tagName;\r
1051 private string tabString;\r
1052 private static string[] _styleNameLookupArray;\r
1053 \r
1054 private RenderAttribute[] _attrList;\r
1055 private static AttributeInformation[] _attrNameLookupArray;\r
1056 private static TagInformation[] _tagNameLookupArray;\r
1057 private TagStackEntry[] _endTags;\r
1058 private RenderStyle[] _styleList;\r
1059 \r
1060 } //HtmlTextWriter\r
1061 \r
1062 struct AttributeInformation {\r
1063         public bool encode;\r
1064         public string name;\r
1065 \r
1066         public AttributeInformation(string name, bool encode){\r
1067                 this.encode = encode;\r
1068                 this.name = name;\r
1069         }\r
1070\r
1071  \r
1072 struct RenderAttribute {\r
1073         public bool encode;\r
1074         public HtmlTextWriterAttribute key;\r
1075         public string name;\r
1076         public string value;\r
1077\r
1078  \r
1079 struct RenderStyle {\r
1080         public HtmlTextWriterStyle key;\r
1081         public string name;\r
1082         public string value;\r
1083\r
1084  \r
1085 struct TagInformation {\r
1086         public string closingTag;\r
1087         public string name;\r
1088         public TagType tagType;\r
1089 \r
1090         public TagInformation(string name, TagType tagType, string closingTag){\r
1091                 this.name = name;\r
1092                 this.tagType = tagType;\r
1093                 this.closingTag = closingTag;   \r
1094         }\r
1095\r
1096  \r
1097 struct TagStackEntry {\r
1098         public string endTagText;\r
1099         public HtmlTextWriterTag tagKey;\r
1100\r
1101  \r
1102 enum TagType {\r
1103         Inline,\r
1104         NonClosing,\r
1105         Other\r
1106\r
1107 \r
1108 \r
1109 } // namespace System.Web.UI.HtmlControls\r
1110 \r